diff --git a/cldr.js/cldr.js-event-tests.ts b/cldr.js/cldr.js-event-tests.ts new file mode 100644 index 000000000..1d397e4df --- /dev/null +++ b/cldr.js/cldr.js-event-tests.ts @@ -0,0 +1,34 @@ +/// +/// + +Cldr.on("get", (path, value) => { + console.log(path); + console.log(value); +}); + +Cldr.once("get", (path, value) => { + console.log(path); + console.log(value); +}); + +Cldr.off("get", (path, value) => { + console.log(path); + console.log(value); +}); + +const cldr = new Cldr("en"); + +cldr.on("get", (path, value) => { + console.log(path); + console.log(value); +}); + +cldr.once("get", (path, value) => { + console.log(path); + console.log(value); +}); + +cldr.off("get", (path, value) => { + console.log(path); + console.log(value); +}); diff --git a/cldr.js/cldr.js-event.d.ts b/cldr.js/cldr.js-event.d.ts new file mode 100644 index 000000000..5e520127c --- /dev/null +++ b/cldr.js/cldr.js-event.d.ts @@ -0,0 +1,24 @@ +// Type definitions for Cldr.js 0.4.4 +// Project: https://github.com/rxaviers/cldrjs +// Definitions by: Raman But-Husaim +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// The definition file for event module. + +declare module cldr { + interface CldrStatic { + on(event:string, listener:(path:string, value:any) => void): void; + once(event:string, listener:(path:string, value:any) => void): void; + off(event:string, listener:(path:string, value:any) => void): void; + } + + interface CldrFactory { + on(event:string, listener:(path:string, value:any) => void): void; + once(event:string, listener:(path:string, value:any) => void): void; + off(event:string, listener:(path:string, value:any) => void): void; + } +} + +declare module "cldr/event" { + export = cldr; +} diff --git a/cldr.js/cldr.js-supplemental-tests.ts b/cldr.js/cldr.js-supplemental-tests.ts new file mode 100644 index 000000000..582733797 --- /dev/null +++ b/cldr.js/cldr.js-supplemental-tests.ts @@ -0,0 +1,19 @@ +/// +/// + +const cldr = new Cldr("en"); + +const supplemental = cldr.supplemental; + +const supplementalPath = supplemental("plurals-type-cardinal/{languageId}/pluralRule-count-one"); +const supplementalPathByArray = supplemental(["plurals-type-cardinal", "{languageId}/pluralRule-count-one"]); + +const timeData = supplemental.timeData; +const allowed = timeData.allowed(); +const preferred = timeData.preferred(); + +const weekData = supplemental.weekData; +const firstDay = weekData.firstDay(); +const minDays = weekData.minDays(); + + diff --git a/cldr.js/cldr.js-supplemental.d.ts b/cldr.js/cldr.js-supplemental.d.ts new file mode 100644 index 000000000..d1486f082 --- /dev/null +++ b/cldr.js/cldr.js-supplemental.d.ts @@ -0,0 +1,33 @@ +// Type definitions for Cldr.js 0.4.4 +// Project: https://github.com/rxaviers/cldrjs +// Definitions by: Raman But-Husaim +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// The definition file for supplemental module. + +declare module cldr { + interface TimeDataStatic { + allowed(): string; + preferred(): string; + } + + interface WeekDataStatic { + firstDay(): string; + minDays(): number; + } + + interface SupplementalStatic { + timeData: TimeDataStatic; + weekData: WeekDataStatic; + (path:string): any; + (paths:string[]): any; + } + + interface CldrStatic { + supplemental: SupplementalStatic; + } +} + +declare module "cldr/supplemental" { + export = cldr; +} diff --git a/cldr.js/cldr.js-tests.ts b/cldr.js/cldr.js-tests.ts new file mode 100644 index 000000000..c86d48774 --- /dev/null +++ b/cldr.js/cldr.js-tests.ts @@ -0,0 +1,164 @@ +/// + +Cldr.load({ + "main": { + "en": { + "identity": { + "version": { + "_cldrVersion": "25", + "_number": "$Revision: 91 $" + }, + "generation": { + "_date": "$Date: 2014-03-13 22:27:12 -0500 (Thu, 13 Mar 2014) $" + }, + "language": "en" + }, + "dates": { + "calendars": { + "gregorian": { + "months": { + "format": { + "abbreviated": { + "1": "Jan", + "2": "Feb", + "3": "Mar", + "4": "Apr", + "5": "May", + "6": "Jun", + "7": "Jul", + "8": "Aug", + "9": "Sep", + "10": "Oct", + "11": "Nov", + "12": "Dec" + } + } + }, + "dayPeriods": { + "format": { + "wide": { + "am": "AM", + "am-alt-variant": "am", + "noon": "noon", + "pm": "PM", + "pm-alt-variant": "pm" + } + } + }, + "dateFormats": { + "medium": "MMM d, y" + }, + "timeFormats": { + "medium": "h:mm:ss a", + }, + "dateTimeFormats": { + "medium": "{1}, {0}" + } + } + }, + "fields": { + "second": { + "displayName": "Second", + "relative-type-0": "now", + "relativeTime-type-future": { + "relativeTimePattern-count-one": "in {0} second", + "relativeTimePattern-count-other": "in {0} seconds" + }, + "relativeTime-type-past": { + "relativeTimePattern-count-one": "{0} second ago", + "relativeTimePattern-count-other": "{0} seconds ago" + } + } + } + }, + "numbers": { + "currencies": { + "USD": { + "symbol": "$" + } + }, + "defaultNumberingSystem": "latn", + "symbols-numberSystem-latn": { + "decimal": ".", + "exponential": "E", + "group": ",", + "infinity": "∞", + "minusSign": "-", + "nan": "NaN", + "percentSign": "%", + "perMille": "‰", + "plusSign": "+", + "timeSeparator": ":" + }, + "decimalFormats-numberSystem-latn": { + "standard": "#,##0.###" + }, + "currencyFormats-numberSystem-latn": { + "currencySpacing": { + "beforeCurrency": { + "currencyMatch": "[:^S:]", + "surroundingMatch": "[:digit:]", + "insertBetween": " " + }, + "afterCurrency": { + "currencyMatch": "[:^S:]", + "surroundingMatch": "[:digit:]", + "insertBetween": " " + } + }, + "standard": "¤#,##0.00" + } + }, + "units": { + "short": { + "per": { + "compoundUnitPattern": "{0}/{1}" + }, + "speed-mile-per-hour": { + "displayName": "miles/hour", + "unitPattern-count-one": "{0} mph", + "unitPattern-count-other": "{0} mph" + } + } + } + } + }, + "supplemental": { + "version": { + "_cldrVersion": "25", + "_number": "$Revision: 91 $" + }, + "currencyData": { + "fractions": { + "DEFAULT": { + "_rounding": "0", + "_digits": "2" + } + } + }, + "likelySubtags": { + "en": "en-Latn-US", + }, + "plurals-type-cardinal": { + "en": { + "pluralRule-count-one": "i = 1 and v = 0 @integer 1", + "pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …" + } + } + } +}); + +const cldr = new Cldr("en"); +const getDecimalSeparator = cldr.get("/cldr/main/{languageId}/numbers/symbols-numberSystem-latn/decimal"); +const getDecimalSeparatorByArray = cldr.get(["/cldr/main", "{languageId}/numbers/symbols-numberSystem-latn", "decimal"]); +const mainDecimalSeparator = cldr.main("/{languageId}/numbers/symbols-numberSystem-latn/decimal"); +const mainDecimalSeparatorByArray = cldr.main(["/{languageId}/numbers", "/symbols-numberSystem-latn/decimal"]); +const locale = cldr.locale; + +const attributes = cldr.attributes; +const language = attributes.language; +const script = attributes.script; +const region = attributes.region; +const territory = attributes.territory; +const languageId = attributes.languageId; +const maxLanguageId = attributes.maxLanguageId; diff --git a/cldr.js/cldr.js.d.ts b/cldr.js/cldr.js.d.ts new file mode 100644 index 000000000..8466e54aa --- /dev/null +++ b/cldr.js/cldr.js.d.ts @@ -0,0 +1,239 @@ +// Type definitions for Cldr.js 0.4.4 +// Project: https://github.com/rxaviers/cldrjs +// Definitions by: Raman But-Husaim +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module cldr { + /** + * @name Attributes + * @memberof cldr + * @kind interface + * + * @description + * The object created during instance initialization and used internally by .get() + * to replace dynamic parts of an item path. + */ + interface Attributes { + /** + * @name language + * @memberof cldr.Attributes + * @kind property + * @access public + * + * @type {any} + * + * @description + * Language subtag {@link http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions} + */ + language: any; + + /** + * @name script + * @memberof cldr.Attributes + * @kind property + * @access public + * + * @type {any} + * + * @description + * Script subtag {@link http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions} + */ + script: any; + + /** + * @name region + * @memberof cldr.Attributes + * @kind property + * @access public + * + * @type {any} + * + * @description + * Region subtag {@link http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions} + */ + region: any; + + /** + * @name territory + * @memberof cldr.Attributes + * @kind property + * @access public + * + * @type {any} + * + * @description + * Region subtag (territory variant) {@link http://www.unicode.org/reports/tr35/#Language_Locale_Field_Definitions} + */ + territory: any; + + /** + * @name languageId + * @memberof cldr.Attributes + * @kind property + * @access public + * + * @type {any} + * + * @description + * Language Id {@link http://www.unicode.org/reports/tr35/#Unicode_language_identifier} + */ + languageId: any; + + /** + * @name maxLanguageId + * @memberof cldr.Attributes + * @kind property + * @access public + * + * @type {any} + * + * @description + * Maximized Language Id {@link http://www.unicode.org/reports/tr35/#Likely_Subtags} + */ + maxLanguageId: any; + } + + /** + * @name CldrStatic + * @memberof cldr + * @kind interface + * + * @description + * The cldr class definition. + */ + interface CldrStatic { + /** + * @name get + * @memberof cldr.CldrStatic + * @kind function + * @access public + * + * @description + * Get the item data given its path, or 'undefined' if missing. + * + * @param {string} path The path to the cldr member. + * + * @returns {any} The cldr member. + */ + get(path: string) : any; + + /** + * @name get + * @memberof cldr.CldrStatic + * @kind function + * @access public + * + * @description + * Get the item data given its path, or 'undefined' if missing. + * + * @param {Array} paths The array with path parts to the cldr member. + * + * @returns {any} The cldr member. + */ + get(paths: string[]): any; + + /** + * @name main + * @memberof cldr.CldrStatic + * @kind function + * @access public + * + * @description + * It's an alias for .get(["main/{languageId}, ...])" + * + * @param {string} path The path to the cldr member. + * + * @returns {any} The cldr member. + */ + main(path: string): any; + + /** + * @name main + * @memberof cldr.CldrStatic + * @kind function + * @access public + * + * @declaration + * It's an alias for .get(["main/{languageId}, ...])" + * + * @param {Array} paths The array with path parts to the cldr member. + * + * @returns {any} The cldr member. + */ + main(paths: string[]): any; + + /** + * @name locale + * @memberof cldr.CldrStatic + * @kind property + * @access public + * + * @type {string} + * + * @declaration + * The locale string. + */ + locale: string; + + /** + * @name attributes + * @memberof cldr.CldrStatic + * @kind property + * @access public + * + * @type {cldr.Attributes} + * + * @declaration + * The object created during instance initialization and used internally by .get() + * to replace dynamic parts of an item path. + */ + attributes: Attributes; + } + + /** + * @name CldrFactory + * @memberof cldr + * @kind inteface + * + * @description + * The factory for {@link cldr.CldrStatic} class. + */ + interface CldrFactory { + /** + * @name load + * @memberof cldr.CldrFactory + * @kind function + * @access public + * + * @description + * Load the CLDR content in the form of JSON. + * + * @param {any} json The json content. + * @param {Array} otherJson Optional. The parts of the JSON. + * + * @returns {void} + */ + load(json: any, ...otherJson: any[]): void; + + /** + * @name constructor + * @memberof cldr.CldrFactory + * @kind function + * @access public + * + * @description + * The constructor function for {@link cldr.CldrStatic} class. + * + * @param {string} locale The locale name that was previously loaded. + * + * @returns {cldr.CldrStatic} The instance of {@link cldr.CldrStatic} class. + */ + new (locale: string): CldrStatic; + } +} + +declare module "cldr" { + export = cldr; +} + +declare var Cldr: cldr.CldrFactory;