@webiny/i18n 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/I18n.d.ts +2 -2
  2. package/I18n.js +158 -425
  3. package/I18n.js.map +1 -1
  4. package/README.md +7 -13
  5. package/extractor/extract.js +24 -57
  6. package/extractor/extract.js.map +1 -1
  7. package/extractor/index.js +32 -60
  8. package/extractor/index.js.map +1 -1
  9. package/index.d.ts +3 -3
  10. package/index.js +12 -34
  11. package/index.js.map +1 -1
  12. package/modifiers/countModifier.d.ts +1 -1
  13. package/modifiers/countModifier.js +17 -41
  14. package/modifiers/countModifier.js.map +1 -1
  15. package/modifiers/dateModifier.d.ts +1 -1
  16. package/modifiers/dateModifier.js +9 -19
  17. package/modifiers/dateModifier.js.map +1 -1
  18. package/modifiers/dateTimeModifier.d.ts +1 -1
  19. package/modifiers/dateTimeModifier.js +9 -19
  20. package/modifiers/dateTimeModifier.js.map +1 -1
  21. package/modifiers/genderModifier.d.ts +1 -1
  22. package/modifiers/genderModifier.js +9 -19
  23. package/modifiers/genderModifier.js.map +1 -1
  24. package/modifiers/ifModifier.d.ts +1 -1
  25. package/modifiers/ifModifier.js +9 -19
  26. package/modifiers/ifModifier.js.map +1 -1
  27. package/modifiers/index.d.ts +1 -1
  28. package/modifiers/index.js +23 -31
  29. package/modifiers/index.js.map +1 -1
  30. package/modifiers/numberModifier.d.ts +1 -1
  31. package/modifiers/numberModifier.js +9 -19
  32. package/modifiers/numberModifier.js.map +1 -1
  33. package/modifiers/pluralModifier.d.ts +1 -1
  34. package/modifiers/pluralModifier.js +17 -40
  35. package/modifiers/pluralModifier.js.map +1 -1
  36. package/modifiers/priceModifier.d.ts +1 -1
  37. package/modifiers/priceModifier.js +9 -19
  38. package/modifiers/priceModifier.js.map +1 -1
  39. package/modifiers/timeModifier.d.ts +1 -1
  40. package/modifiers/timeModifier.js +9 -19
  41. package/modifiers/timeModifier.js.map +1 -1
  42. package/package.json +23 -29
  43. package/processors/default.d.ts +1 -1
  44. package/processors/default.js +34 -64
  45. package/processors/default.js.map +1 -1
  46. package/types.d.ts +3 -3
  47. package/types.js +0 -5
  48. package/types.js.map +0 -1
package/I18n.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["I18N","constructor","defaultFormats","getDefaultFormats","translations","modifiers","processors","translate","base","namespace","Error","lodashGet","translation","getTranslation","hash","hasVariables","includes","$this","i18n","values","data","key","processor","canExecute","execute","ns","date","value","outputFormat","inputFormat","getDateFormat","parsedValue","fecha","parse","format","time","getTimeFormat","dateTime","getDateTimeFormat","price","getPriceFormat","lodashAssign","replace","accounting","formatMoney","symbol","precision","thousand","decimal","number","getNumberFormat","formatNumber","getTranslations","hasTranslation","setTranslation","setTranslations","clearTranslations","mergeTranslations","getLocale","locale","setLocale","registerModifier","modifier","name","registerModifiers","forEach","unregisterModifier","registerProcessor","registerProcessors","unregisterProcessor","datetime"],"sources":["I18n.ts"],"sourcesContent":["import accounting from \"accounting\";\nimport * as fecha from \"fecha\";\n/**\n * Package short-hash has no types.\n */\n// @ts-ignore\nimport hash from \"short-hash\";\nimport lodashAssign from \"lodash/assign\";\nimport lodashGet from \"lodash/get\";\n\nimport {\n Formats,\n I18NData,\n I18NDataValues,\n Modifier,\n NumberFormat,\n PriceFormat,\n Processor,\n ProcessorResult,\n Translations,\n Translator\n} from \"./types\";\n\nexport type Translated =\n | ((values: I18NDataValues) => ProcessorResult | null)\n | ProcessorResult\n | null;\n/**\n * Main class used for all I18n needs.\n */\nexport default class I18N {\n public locale: string | null = null;\n public defaultFormats: Formats;\n public translations: Translations;\n public modifiers: {\n [name: string]: Modifier;\n };\n public processors: {\n [name: string]: Processor;\n };\n\n public constructor() {\n /**\n * If we fail to fetch formats for currently selected locale, these default formats will be used.\n * @type {{date: string, time: string, datetime: string, number: string}}\n */\n this.defaultFormats = this.getDefaultFormats();\n\n /**\n * All currently-loaded translations, for easier (synchronous) access.\n * @type {{}}\n */\n this.translations = {};\n\n /**\n * All registered modifiers.\n * @type {{}}\n */\n this.modifiers = {};\n\n /**\n * All registered processors.\n * Default built-in processors are registered immediately below.\n * @type {{}}\n */\n this.processors = {};\n }\n\n public translate(base: string, namespace?: string): Translated {\n // Returns full translation for given base text in given namespace (optional).\n // If translation isn't found, base text will be returned.\n // We create a key out of given namespace and base text.\n\n if (!namespace) {\n throw Error(\"I18N text namespace not defined.\");\n }\n\n base = lodashGet(base, \"raw.0\", base);\n\n let translation: string | null = this.getTranslation(namespace + \".\" + hash(base));\n\n if (!translation) {\n translation = base;\n }\n\n const hasVariables = base.includes(\"{\") && base.includes(\"}\");\n if (hasVariables) {\n // eslint-disable-next-line @typescript-eslint/no-this-alias\n const $this = this;\n return function i18n(values: I18NDataValues) {\n const data: I18NData = {\n translation: translation as string,\n base,\n namespace,\n values,\n i18n: $this\n };\n for (const key in $this.processors) {\n const processor = $this.processors[key];\n if (processor.canExecute(data)) {\n return processor.execute(data);\n }\n }\n return null;\n };\n }\n\n const data: I18NData = { translation, base, namespace, values: {}, i18n: this };\n for (const key in this.processors) {\n if (this.processors[key].canExecute(data)) {\n return this.processors[key].execute(data);\n }\n }\n return null;\n }\n\n public namespace(namespace: string): Translator {\n return base => {\n return this.translate(base as string, namespace);\n };\n }\n\n public ns(namespace: string): Translator {\n return this.namespace(namespace);\n }\n\n /**\n * Formats and outputs date.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n public date(\n value: Date | string | number,\n outputFormat?: string,\n inputFormat?: string\n ): string {\n if (!outputFormat) {\n outputFormat = this.getDateFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: number | Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value;\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Formats and outputs time.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n public time(\n value: Date | string | number,\n outputFormat?: string,\n inputFormat?: string\n ): string {\n if (!outputFormat) {\n outputFormat = this.getTimeFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: number | Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value;\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Formats and outputs date/time.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n dateTime(value: Date | string | number, outputFormat?: string, inputFormat?: string): string {\n if (!outputFormat) {\n outputFormat = this.getDateTimeFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: number | Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value;\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Outputs formatted number as amount of price.\n */\n public price(value: string | number, outputFormat?: any): string {\n if (!outputFormat) {\n outputFormat = this.getPriceFormat();\n } else {\n outputFormat = lodashAssign({}, this.defaultFormats.price, outputFormat);\n }\n\n // Convert placeholders to accounting's placeholders.\n let format = outputFormat.format;\n format = format.replace(\"{symbol}\", \"%s\");\n format = format.replace(\"{amount}\", \"%v\");\n\n return accounting.formatMoney(\n value,\n outputFormat.symbol,\n outputFormat.precision,\n outputFormat.thousand,\n outputFormat.decimal,\n format\n );\n }\n\n /**\n * Outputs formatted number.\n */\n public number(value: string | number, outputFormat?: NumberFormat): string {\n if (!outputFormat) {\n outputFormat = this.getNumberFormat();\n } else {\n outputFormat = lodashAssign({}, this.defaultFormats.number, outputFormat);\n }\n return accounting.formatNumber(\n /**\n * Cast as number because method transforms it internally.\n */\n value as number,\n outputFormat.precision,\n outputFormat.thousand,\n outputFormat.decimal\n );\n }\n\n /**\n * Returns translation for given text key.\n */\n public getTranslation(key?: string): string | null {\n if (!key) {\n return null;\n }\n return this.translations[key];\n }\n\n /**\n * Returns all translations for current locale.\n */\n public getTranslations(): Translations {\n return this.translations;\n }\n\n /**\n * Returns true if given key has a translation for currently set locale.\n */\n public hasTranslation(key: string): boolean {\n return key in this.translations;\n }\n\n /**\n * Sets translation for given text key.\n */\n public setTranslation(key: string, translation: string): I18N {\n this.translations[key] = translation;\n return this;\n }\n\n /**\n * Sets translations that will be used.\n */\n public setTranslations(translations: Translations): I18N {\n this.translations = translations;\n return this;\n }\n\n /**\n * Clears all translations.\n */\n public clearTranslations(): I18N {\n this.setTranslations({});\n return this;\n }\n\n /**\n * Merges given translations object with already existing.\n */\n\n public mergeTranslations(translations: Translations): Translations {\n return lodashAssign(this.translations, translations);\n }\n\n /**\n * Returns currently selected locale (locale's key).\n */\n public getLocale(): null | string {\n return this.locale;\n }\n\n /**\n * Sets current locale.\n */\n public setLocale(locale: string): I18N {\n this.locale = locale;\n return this;\n }\n\n /**\n * Registers single modifier.\n */\n public registerModifier(modifier: Modifier): I18N {\n this.modifiers[modifier.name] = modifier;\n return this;\n }\n\n /**\n * Registers all modifiers in given array.\n */\n public registerModifiers(modifiers: Array<Modifier>): I18N {\n modifiers.forEach(modifier => this.registerModifier(modifier));\n return this;\n }\n\n /**\n * Unregisters given modifier.\n */\n public unregisterModifier(name: string): I18N {\n delete this.modifiers[name];\n return this;\n }\n\n /**\n * Registers single processor.\n */\n public registerProcessor(processor: Processor): I18N {\n this.processors[processor.name] = processor;\n return this;\n }\n\n /**\n * Registers all processors in given array.\n */\n public registerProcessors(processors: Array<Processor>): I18N {\n processors.forEach(processor => this.registerProcessor(processor));\n return this;\n }\n\n /**\n * Unregisters given processor.\n */\n public unregisterProcessor(name: string): I18N {\n delete this.processors[name];\n return this;\n }\n\n /**\n * Returns default formats\n */\n public getDefaultFormats(): Formats {\n return {\n date: \"DD/MM/YYYY\",\n time: \"HH:mm\",\n datetime: \"DD/MM/YYYY HH:mm\",\n price: {\n symbol: \"\",\n format: \"{symbol}{amount}\",\n decimal: \".\",\n thousand: \",\",\n precision: 2\n },\n number: {\n decimal: \".\",\n thousand: \",\",\n precision: 2\n }\n };\n }\n\n /**\n * Returns current format to be used when outputting dates.\n */\n public getDateFormat(): string {\n return lodashGet(this.locale, \"formats.date\", this.defaultFormats.date);\n }\n\n /**\n * Returns current format to be used when outputting time.\n */\n public getTimeFormat(): string {\n return lodashGet(this.locale, \"formats.time\", this.defaultFormats.time);\n }\n\n /**\n * Returns current format to be used when outputting date/time.\n */\n public getDateTimeFormat(): string {\n return lodashGet(this.locale, \"formats.datetime\", this.defaultFormats.datetime);\n }\n\n /**\n * Returns current format to be used when outputting prices.\n */\n public getPriceFormat(): PriceFormat {\n return lodashAssign(\n {},\n this.defaultFormats.price,\n lodashGet(this.locale, \"formats.price\", {})\n );\n }\n\n /**\n * Returns current format to be used when outputting numbers.\n */\n public getNumberFormat(): NumberFormat {\n return lodashAssign(\n {},\n this.defaultFormats.number,\n lodashGet(this.locale, \"formats.number\", {})\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AAKA;;AACA;;AACA;;AANA;AACA;AACA;AACA;;AAsBA;AACA;AACA;AACe,MAAMA,IAAN,CAAW;EAWfC,WAAW,GAAG;IAAA,8CAVU,IAUV;IAAA;IAAA;IAAA;IAAA;;IACjB;AACR;AACA;AACA;IACQ,KAAKC,cAAL,GAAsB,KAAKC,iBAAL,EAAtB;IAEA;AACR;AACA;AACA;;IACQ,KAAKC,YAAL,GAAoB,EAApB;IAEA;AACR;AACA;AACA;;IACQ,KAAKC,SAAL,GAAiB,EAAjB;IAEA;AACR;AACA;AACA;AACA;;IACQ,KAAKC,UAAL,GAAkB,EAAlB;EACH;;EAEMC,SAAS,CAACC,IAAD,EAAeC,SAAf,EAA+C;IAC3D;IACA;IACA;IAEA,IAAI,CAACA,SAAL,EAAgB;MACZ,MAAMC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JD,OAAO,EAAE,GADL;QAEJD,QAAQ,EAAE,GAFN;QAGJD,SAAS,EAAE;MAHP;IAXL,CAAP;EAiBH;EAED;AACJ;AACA;;;EACWhB,aAAa,GAAW;IAC3B,OAAO,IAAAnB,YAAA,EAAU,KAAKgD,MAAf,EAAuB,cAAvB,EAAuC,KAAKzD,cAAL,CAAoBwB,IAA3D,CAAP;EACH;EAED;AACJ;AACA;;;EACWU,aAAa,GAAW;IAC3B,OAAO,IAAAzB,YAAA,EAAU,KAAKgD,MAAf,EAAuB,cAAvB,EAAuC,KAAKzD,cAAL,CAAoBiC,IAA3D,CAAP;EACH;EAED;AACJ;AACA;;;EACWG,iBAAiB,GAAW;IAC/B,OAAO,IAAA3B,YAAA,EAAU,KAAKgD,MAAf,EAAuB,kBAAvB,EAA2C,KAAKzD,cAAL,CAAoBoE,QAA/D,CAAP;EACH;EAED;AACJ;AACA;;;EACW9B,cAAc,GAAgB;IACjC,OAAO,IAAAC,eAAA,EACH,EADG,EAEH,KAAKvC,cAAL,CAAoBqC,KAFjB,EAGH,IAAA5B,YAAA,EAAU,KAAKgD,MAAf,EAAuB,eAAvB,EAAwC,EAAxC,CAHG,CAAP;EAKH;EAED;AACJ;AACA;;;EACWT,eAAe,GAAiB;IACnC,OAAO,IAAAT,eAAA,EACH,EADG,EAEH,KAAKvC,cAAL,CAAoB+C,MAFjB,EAGH,IAAAtC,YAAA,EAAU,KAAKgD,MAAf,EAAuB,gBAAvB,EAAyC,EAAzC,CAHG,CAAP;EAKH;;AAjZqB"}
1
+ {"version":3,"file":"I18n.js","sources":["../src/I18n.ts"],"sourcesContent":["import accounting from \"accounting\";\nimport * as fecha from \"fecha\";\nimport lodashAssign from \"lodash/assign.js\";\nimport lodashGet from \"lodash/get.js\";\n\nimport type {\n Formats,\n I18NData,\n I18NDataValues,\n Modifier,\n NumberFormat,\n PriceFormat,\n Processor,\n ProcessorResult,\n Translations,\n Translator\n} from \"./types.js\";\nimport { hash } from \"ohash\";\n\nexport type Translated =\n | ((values: I18NDataValues) => ProcessorResult | null)\n | ProcessorResult\n | null;\n/**\n * Main class used for all I18n needs.\n */\nexport default class I18N {\n public locale: string | null = null;\n public defaultFormats: Formats;\n public translations: Translations;\n public modifiers: {\n [name: string]: Modifier;\n };\n public processors: {\n [name: string]: Processor;\n };\n\n public constructor() {\n /**\n * If we fail to fetch formats for currently selected locale, these default formats will be used.\n * @type {{date: string, time: string, datetime: string, number: string}}\n */\n this.defaultFormats = this.getDefaultFormats();\n\n /**\n * All currently-loaded translations, for easier (synchronous) access.\n * @type {{}}\n */\n this.translations = {};\n\n /**\n * All registered modifiers.\n * @type {{}}\n */\n this.modifiers = {};\n\n /**\n * All registered processors.\n * Default built-in processors are registered immediately below.\n * @type {{}}\n */\n this.processors = {};\n }\n\n public translate(base: string, namespace?: string): Translated {\n // Returns full translation for given base text in given namespace (optional).\n // If translation isn't found, base text will be returned.\n // We create a key out of given namespace and base text.\n\n if (!namespace) {\n throw Error(\"I18N text namespace not defined.\");\n }\n\n base = lodashGet(base, \"raw.0\", base);\n\n let translation: string | null = this.getTranslation(namespace + \".\" + hash(base));\n\n if (!translation) {\n translation = base;\n }\n\n const hasVariables = base.includes(\"{\") && base.includes(\"}\");\n if (hasVariables) {\n // oxlint-disable-next-line typescript/no-this-alias\n const $this = this;\n return function i18n(values: I18NDataValues) {\n const data: I18NData = {\n translation: translation as string,\n base,\n namespace,\n values,\n i18n: $this\n };\n for (const key in $this.processors) {\n const processor = $this.processors[key];\n if (processor.canExecute(data)) {\n return processor.execute(data);\n }\n }\n return null;\n };\n }\n\n const data: I18NData = { translation, base, namespace, values: {}, i18n: this };\n for (const key in this.processors) {\n if (this.processors[key].canExecute(data)) {\n return this.processors[key].execute(data);\n }\n }\n return null;\n }\n\n public namespace(namespace: string): Translator {\n return base => {\n return this.translate(base as string, namespace);\n };\n }\n\n public ns(namespace: string): Translator {\n return this.namespace(namespace);\n }\n\n /**\n * Formats and outputs date.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n public date(\n value: Date | string | number,\n outputFormat?: string,\n inputFormat?: string\n ): string {\n if (!outputFormat) {\n outputFormat = this.getDateFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value instanceof Date ? value : new Date(value);\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Formats and outputs time.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n public time(\n value: Date | string | number,\n outputFormat?: string,\n inputFormat?: string\n ): string {\n if (!outputFormat) {\n outputFormat = this.getTimeFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value instanceof Date ? value : new Date(value);\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Formats and outputs date/time.\n * It will try to load format from currently selected locale's settings. If not defined, default formats will be used.\n */\n dateTime(value: Date | string | number, outputFormat?: string, inputFormat?: string): string {\n if (!outputFormat) {\n outputFormat = this.getDateTimeFormat();\n }\n if (!inputFormat) {\n inputFormat = \"YYYY-MM-DDTHH:mm:ss.SSSZ\";\n }\n\n let parsedValue: Date;\n\n if (typeof value === \"string\") {\n parsedValue = fecha.parse(value, inputFormat) as Date;\n } else {\n parsedValue = value instanceof Date ? value : new Date(value);\n }\n\n return fecha.format(parsedValue, outputFormat);\n }\n\n /**\n * Outputs formatted number as amount of price.\n */\n public price(value: string | number, outputFormat?: any): string {\n if (!outputFormat) {\n outputFormat = this.getPriceFormat();\n } else {\n outputFormat = lodashAssign({}, this.defaultFormats.price, outputFormat);\n }\n\n // Convert placeholders to accounting's placeholders.\n let format = outputFormat.format;\n format = format.replace(\"{symbol}\", \"%s\");\n format = format.replace(\"{amount}\", \"%v\");\n\n return accounting.formatMoney(\n value,\n outputFormat.symbol,\n outputFormat.precision,\n outputFormat.thousand,\n outputFormat.decimal,\n format\n );\n }\n\n /**\n * Outputs formatted number.\n */\n public number(value: string | number, outputFormat?: NumberFormat): string {\n if (!outputFormat) {\n outputFormat = this.getNumberFormat();\n } else {\n outputFormat = lodashAssign({}, this.defaultFormats.number, outputFormat);\n }\n return accounting.formatNumber(\n /**\n * Cast as number because method transforms it internally.\n */\n value as number,\n outputFormat.precision,\n outputFormat.thousand,\n outputFormat.decimal\n );\n }\n\n /**\n * Returns translation for given text key.\n */\n public getTranslation(key?: string): string | null {\n if (!key) {\n return null;\n }\n return this.translations[key];\n }\n\n /**\n * Returns all translations for current locale.\n */\n public getTranslations(): Translations {\n return this.translations;\n }\n\n /**\n * Returns true if given key has a translation for currently set locale.\n */\n public hasTranslation(key: string): boolean {\n return key in this.translations;\n }\n\n /**\n * Sets translation for given text key.\n */\n public setTranslation(key: string, translation: string): I18N {\n this.translations[key] = translation;\n return this;\n }\n\n /**\n * Sets translations that will be used.\n */\n public setTranslations(translations: Translations): I18N {\n this.translations = translations;\n return this;\n }\n\n /**\n * Clears all translations.\n */\n public clearTranslations(): I18N {\n this.setTranslations({});\n return this;\n }\n\n /**\n * Merges given translations object with already existing.\n */\n\n public mergeTranslations(translations: Translations): Translations {\n return lodashAssign(this.translations, translations);\n }\n\n /**\n * Returns currently selected locale (locale's key).\n */\n public getLocale(): null | string {\n return this.locale;\n }\n\n /**\n * Sets current locale.\n */\n public setLocale(locale: string): I18N {\n this.locale = locale;\n return this;\n }\n\n /**\n * Registers single modifier.\n */\n public registerModifier(modifier: Modifier): I18N {\n this.modifiers[modifier.name] = modifier;\n return this;\n }\n\n /**\n * Registers all modifiers in given array.\n */\n public registerModifiers(modifiers: Array<Modifier>): I18N {\n modifiers.forEach(modifier => this.registerModifier(modifier));\n return this;\n }\n\n /**\n * Unregisters given modifier.\n */\n public unregisterModifier(name: string): I18N {\n delete this.modifiers[name];\n return this;\n }\n\n /**\n * Registers single processor.\n */\n public registerProcessor(processor: Processor): I18N {\n this.processors[processor.name] = processor;\n return this;\n }\n\n /**\n * Registers all processors in given array.\n */\n public registerProcessors(processors: Array<Processor>): I18N {\n processors.forEach(processor => this.registerProcessor(processor));\n return this;\n }\n\n /**\n * Unregisters given processor.\n */\n public unregisterProcessor(name: string): I18N {\n delete this.processors[name];\n return this;\n }\n\n /**\n * Returns default formats\n */\n public getDefaultFormats(): Formats {\n return {\n date: \"DD/MM/YYYY\",\n time: \"HH:mm\",\n datetime: \"DD/MM/YYYY HH:mm\",\n price: {\n symbol: \"\",\n format: \"{symbol}{amount}\",\n decimal: \".\",\n thousand: \",\",\n precision: 2\n },\n number: {\n decimal: \".\",\n thousand: \",\",\n precision: 2\n }\n };\n }\n\n /**\n * Returns current format to be used when outputting dates.\n */\n public getDateFormat(): string {\n return lodashGet(this.locale, \"formats.date\", this.defaultFormats.date);\n }\n\n /**\n * Returns current format to be used when outputting time.\n */\n public getTimeFormat(): string {\n return lodashGet(this.locale, \"formats.time\", this.defaultFormats.time);\n }\n\n /**\n * Returns current format to be used when outputting date/time.\n */\n public getDateTimeFormat(): string {\n return lodashGet(this.locale, \"formats.datetime\", this.defaultFormats.datetime);\n }\n\n /**\n * Returns current format to be used when outputting prices.\n */\n public getPriceFormat(): PriceFormat {\n return lodashAssign(\n {},\n this.defaultFormats.price,\n lodashGet(this.locale, \"formats.price\", {})\n );\n }\n\n /**\n * Returns current format to be used when outputting numbers.\n */\n public getNumberFormat(): NumberFormat {\n return lodashAssign(\n {},\n this.defaultFormats.number,\n lodashGet(this.locale, \"formats.number\", {})\n );\n }\n}\n"],"names":["I18N","base","namespace","Error","lodashGet","translation","hash","hasVariables","$this","values","data","key","processor","value","outputFormat","inputFormat","parsedValue","fecha","Date","lodashAssign","format","accounting","translations","locale","modifier","modifiers","name","processors"],"mappings":";;;;;AA0Be,MAAMA;IAWjB,aAAqB;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ACJ"}
package/README.md CHANGED
@@ -1,17 +1,11 @@
1
1
  # @webiny/i18n
2
- [![](https://img.shields.io/npm/dw/@webiny/i18n.svg)](https://www.npmjs.com/package/@webiny/i18n)
3
- [![](https://img.shields.io/npm/v/@webiny/i18n.svg)](https://www.npmjs.com/package/@webiny/i18n)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
6
2
 
7
- A simple I18N library, for frontend and backend apps.
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
8
6
 
9
- ## Install
10
- ```
11
- npm install --save @webiny/i18n
12
- ```
7
+ 📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
13
8
 
14
- Or if you prefer yarn:
15
- ```
16
- yarn add @webiny/i18n
17
- ```
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -1,62 +1,29 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _shortHash = _interopRequireDefault(require("short-hash"));
11
-
12
- /**
13
- * Package short-hash has no types.
14
- */
15
- // @ts-ignore
16
-
17
- /**
18
- * Searches for all declared namespaces.
19
- * Result contains an object with identifiers as keys, and namespaces they represent as values, for example:
20
- * {ns1: 'Webiny.Ns1', ns2: 'Webiny.Ns2', i18n: 'NewNamespace', t: 'Some.Other.Namespace'}
21
- * @param source
22
- */
23
- const getNamespaces = source => {
24
- const regex = /([a-zA-Z0-9]+)[ ]+=[ ]+i18n.namespace\(['"`]([a-zA-Z0-9.]+)['"`]\)/g;
25
- let m;
26
- const results = {};
27
-
28
- while ((m = regex.exec(source)) !== null) {
29
- if (m.index === regex.lastIndex) {
30
- regex.lastIndex++;
1
+ import { hash } from "ohash";
2
+ const getNamespaces = (source)=>{
3
+ const regex = /([a-zA-Z0-9]+)[ ]+=[ ]+i18n.namespace\(['"`]([a-zA-Z0-9.]+)['"`]\)/g;
4
+ let m;
5
+ const results = {};
6
+ while(null !== (m = regex.exec(source))){
7
+ if (m.index === regex.lastIndex) regex.lastIndex++;
8
+ results[m[1]] = m[2];
31
9
  }
32
-
33
- results[m[1]] = m[2];
34
- }
35
-
36
- return results;
10
+ return results;
37
11
  };
38
-
39
- var _default = source => {
40
- const results = {};
41
- const allDeclaredNamespaces = getNamespaces(source);
42
-
43
- for (const variable in allDeclaredNamespaces) {
44
- const regex = new RegExp(variable + "`(.*?)`", "g");
45
- let m;
46
-
47
- while ((m = regex.exec(source)) !== null) {
48
- if (m.index === regex.lastIndex) {
49
- regex.lastIndex++;
50
- } // This is the key - namespace + hash of matched label.
51
-
52
-
53
- const matchedText = m[1];
54
- const key = allDeclaredNamespaces[variable] + "." + (0, _shortHash.default)(matchedText);
55
- results[key] = matchedText;
12
+ const extract = (source)=>{
13
+ const results = {};
14
+ const allDeclaredNamespaces = getNamespaces(source);
15
+ for(const variable in allDeclaredNamespaces){
16
+ const regex = new RegExp(variable + "`(.*?)`", "g");
17
+ let m;
18
+ while(null !== (m = regex.exec(source))){
19
+ if (m.index === regex.lastIndex) regex.lastIndex++;
20
+ const matchedText = m[1];
21
+ const key = allDeclaredNamespaces[variable] + "." + hash(matchedText);
22
+ results[key] = matchedText;
23
+ }
56
24
  }
57
- }
58
-
59
- return results;
25
+ return results;
60
26
  };
27
+ export default extract;
61
28
 
62
- exports.default = _default;
29
+ //# sourceMappingURL=extract.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getNamespaces","source","regex","m","results","exec","index","lastIndex","allDeclaredNamespaces","variable","RegExp","matchedText","key","hash"],"sources":["extract.ts"],"sourcesContent":["/**\n * Package short-hash has no types.\n */\n// @ts-ignore\nimport hash from \"short-hash\";\n\n/**\n * Searches for all declared namespaces.\n * Result contains an object with identifiers as keys, and namespaces they represent as values, for example:\n * {ns1: 'Webiny.Ns1', ns2: 'Webiny.Ns2', i18n: 'NewNamespace', t: 'Some.Other.Namespace'}\n * @param source\n */\nconst getNamespaces = (source: string) => {\n const regex = /([a-zA-Z0-9]+)[ ]+=[ ]+i18n.namespace\\(['\"`]([a-zA-Z0-9.]+)['\"`]\\)/g;\n let m;\n\n const results: Record<string, string> = {};\n\n while ((m = regex.exec(source)) !== null) {\n if (m.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n results[m[1]] = m[2];\n }\n\n return results;\n};\n\nexport default (source: string) => {\n const results: Record<string, string> = {};\n const allDeclaredNamespaces = getNamespaces(source);\n\n for (const variable in allDeclaredNamespaces) {\n const regex = new RegExp(variable + \"`(.*?)`\", \"g\");\n\n let m;\n while ((m = regex.exec(source)) !== null) {\n if (m.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n // This is the key - namespace + hash of matched label.\n const matchedText = m[1];\n const key = allDeclaredNamespaces[variable] + \".\" + hash(matchedText);\n results[key] = matchedText;\n }\n }\n\n return results;\n};\n"],"mappings":";;;;;;;;;AAIA;;AAJA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAIC,MAAD,IAAoB;EACtC,MAAMC,KAAK,GAAG,qEAAd;EACA,IAAIC,CAAJ;EAEA,MAAMC,OAA+B,GAAG,EAAxC;;EAEA,OAAO,CAACD,CAAC,GAAGD,KAAK,CAACG,IAAN,CAAWJ,MAAX,CAAL,MAA6B,IAApC,EAA0C;IACtC,IAAIE,CAAC,CAACG,KAAF,KAAYJ,KAAK,CAACK,SAAtB,EAAiC;MAC7BL,KAAK,CAACK,SAAN;IACH;;IAEDH,OAAO,CAACD,CAAC,CAAC,CAAD,CAAF,CAAP,GAAgBA,CAAC,CAAC,CAAD,CAAjB;EACH;;EAED,OAAOC,OAAP;AACH,CAfD;;eAiBgBH,MAAD,IAAoB;EAC/B,MAAMG,OAA+B,GAAG,EAAxC;EACA,MAAMI,qBAAqB,GAAGR,aAAa,CAACC,MAAD,CAA3C;;EAEA,KAAK,MAAMQ,QAAX,IAAuBD,qBAAvB,EAA8C;IAC1C,MAAMN,KAAK,GAAG,IAAIQ,MAAJ,CAAWD,QAAQ,GAAG,SAAtB,EAAiC,GAAjC,CAAd;IAEA,IAAIN,CAAJ;;IACA,OAAO,CAACA,CAAC,GAAGD,KAAK,CAACG,IAAN,CAAWJ,MAAX,CAAL,MAA6B,IAApC,EAA0C;MACtC,IAAIE,CAAC,CAACG,KAAF,KAAYJ,KAAK,CAACK,SAAtB,EAAiC;QAC7BL,KAAK,CAACK,SAAN;MACH,CAHqC,CAKtC;;;MACA,MAAMI,WAAW,GAAGR,CAAC,CAAC,CAAD,CAArB;MACA,MAAMS,GAAG,GAAGJ,qBAAqB,CAACC,QAAD,CAArB,GAAkC,GAAlC,GAAwC,IAAAI,kBAAA,EAAKF,WAAL,CAApD;MACAP,OAAO,CAACQ,GAAD,CAAP,GAAeD,WAAf;IACH;EACJ;;EAED,OAAOP,OAAP;AACH,C"}
1
+ {"version":3,"file":"extractor/extract.js","sources":["../../src/extractor/extract.ts"],"sourcesContent":["import { hash } from \"ohash\";\n\n/**\n * Searches for all declared namespaces.\n * Result contains an object with identifiers as keys, and namespaces they represent as values, for example:\n * {ns1: 'Webiny.Ns1', ns2: 'Webiny.Ns2', i18n: 'NewNamespace', t: 'Some.Other.Namespace'}\n * @param source\n */\nconst getNamespaces = (source: string) => {\n const regex = /([a-zA-Z0-9]+)[ ]+=[ ]+i18n.namespace\\(['\"`]([a-zA-Z0-9.]+)['\"`]\\)/g;\n let m;\n\n const results: Record<string, string> = {};\n\n while ((m = regex.exec(source)) !== null) {\n if (m.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n results[m[1]] = m[2];\n }\n\n return results;\n};\n\nexport default (source: string) => {\n const results: Record<string, string> = {};\n const allDeclaredNamespaces = getNamespaces(source);\n\n for (const variable in allDeclaredNamespaces) {\n const regex = new RegExp(variable + \"`(.*?)`\", \"g\");\n\n let m;\n while ((m = regex.exec(source)) !== null) {\n if (m.index === regex.lastIndex) {\n regex.lastIndex++;\n }\n\n // This is the key - namespace + hash of matched label.\n const matchedText = m[1];\n const key = allDeclaredNamespaces[variable] + \".\" + hash(matchedText);\n results[key] = matchedText;\n }\n }\n\n return results;\n};\n"],"names":["getNamespaces","source","regex","m","results","allDeclaredNamespaces","variable","RegExp","matchedText","key","hash"],"mappings":";AAQA,MAAMA,gBAAgB,CAACC;IACnB,MAAMC,QAAQ;IACd,IAAIC;IAEJ,MAAMC,UAAkC,CAAC;IAEzC,MAAQD,AAA4B,SAA5BA,CAAAA,IAAID,MAAM,IAAI,CAACD,OAAM,EAAa;QACtC,IAAIE,EAAE,KAAK,KAAKD,MAAM,SAAS,EAC3BA,MAAM,SAAS;QAGnBE,OAAO,CAACD,CAAC,CAAC,EAAE,CAAC,GAAGA,CAAC,CAAC,EAAE;IACxB;IAEA,OAAOC;AACX;AAEA,gBAAgB,CAAAH;IACZ,MAAMG,UAAkC,CAAC;IACzC,MAAMC,wBAAwBL,cAAcC;IAE5C,IAAK,MAAMK,YAAYD,sBAAuB;QAC1C,MAAMH,QAAQ,IAAIK,OAAOD,WAAW,WAAW;QAE/C,IAAIH;QACJ,MAAQA,AAA4B,SAA5BA,CAAAA,IAAID,MAAM,IAAI,CAACD,OAAM,EAAa;YACtC,IAAIE,EAAE,KAAK,KAAKD,MAAM,SAAS,EAC3BA,MAAM,SAAS;YAInB,MAAMM,cAAcL,CAAC,CAAC,EAAE;YACxB,MAAMM,MAAMJ,qBAAqB,CAACC,SAAS,GAAG,MAAMI,KAAKF;YACzDJ,OAAO,CAACK,IAAI,GAAGD;QACnB;IACJ;IAEA,OAAOJ;AACX"}
@@ -1,64 +1,36 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
-
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
-
12
- var _extract = _interopRequireDefault(require("./extract"));
13
-
14
- var _glob = _interopRequireDefault(require("glob"));
15
-
16
- var _fs = _interopRequireDefault(require("fs"));
17
-
1
+ import extract from "./extract.js";
2
+ import fast_glob from "fast-glob";
3
+ import node_fs from "node:fs";
18
4
  class Extractor {
19
- constructor() {
20
- (0, _defineProperty2.default)(this, "glob", void 0);
21
- (0, _defineProperty2.default)(this, "content", "");
22
- (0, _defineProperty2.default)(this, "listOnly", false);
23
- }
24
-
25
- setGlob(value) {
26
- this.glob = value;
27
- return this;
28
- }
29
-
30
- setContent(content) {
31
- this.content = content;
32
- return this;
33
- }
34
-
35
- execute() {
36
- const results = {};
37
-
38
- if (!this.glob) {
39
- return results;
5
+ setGlob(value) {
6
+ this.glob = value;
7
+ return this;
8
+ }
9
+ setContent(content) {
10
+ this.content = content;
11
+ return this;
12
+ }
13
+ execute() {
14
+ const results = {};
15
+ if (!this.glob) return results;
16
+ const paths = fast_glob.sync(this.glob);
17
+ paths.forEach((path)=>{
18
+ const contents = node_fs.readFileSync(path, "utf8");
19
+ const parsed = extract(contents);
20
+ for(const key in parsed)results[key] = parsed[key];
21
+ });
22
+ return results;
23
+ }
24
+ setListOnly(flag = true) {
25
+ this.listOnly = flag;
26
+ return this;
27
+ }
28
+ constructor(){
29
+ this.content = "";
30
+ this.listOnly = false;
40
31
  }
41
-
42
- const paths = _glob.default.sync(this.glob);
43
-
44
- paths.forEach(path => {
45
- const contents = _fs.default.readFileSync(path, "utf8");
46
-
47
- const parsed = (0, _extract.default)(contents);
48
-
49
- for (const key in parsed) {
50
- results[key] = parsed[key];
51
- }
52
- });
53
- return results;
54
- }
55
-
56
- setListOnly(flag = true) {
57
- this.listOnly = flag;
58
- return this;
59
- }
60
-
61
32
  }
33
+ const extractor = Extractor;
34
+ export default extractor;
62
35
 
63
- var _default = Extractor;
64
- exports.default = _default;
36
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Extractor","setGlob","value","glob","setContent","content","execute","results","paths","sync","forEach","path","contents","fs","readFileSync","parsed","extract","key","setListOnly","flag","listOnly"],"sources":["index.ts"],"sourcesContent":["import extract from \"./extract\";\nimport glob from \"glob\";\nimport fs from \"fs\";\n\nexport interface ExtractorResults {\n [key: string]: string;\n}\nclass Extractor {\n private glob: string | undefined;\n public content = \"\";\n public listOnly = false;\n\n public setGlob(value: string): Extractor {\n this.glob = value;\n return this;\n }\n\n public setContent(content: string): Extractor {\n this.content = content;\n return this;\n }\n\n public execute(): ExtractorResults {\n const results: ExtractorResults = {};\n\n if (!this.glob) {\n return results;\n }\n const paths = glob.sync(this.glob);\n paths.forEach(path => {\n const contents = fs.readFileSync(path, \"utf8\");\n const parsed = extract(contents);\n for (const key in parsed) {\n results[key] = parsed[key];\n }\n });\n\n return results;\n }\n\n public setListOnly(flag = true): Extractor {\n this.listOnly = flag;\n return this;\n }\n}\n\nexport default Extractor;\n"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAN,CAAgB;EAAA;IAAA;IAAA,+CAEK,EAFL;IAAA,gDAGM,KAHN;EAAA;;EAKLC,OAAO,CAACC,KAAD,EAA2B;IACrC,KAAKC,IAAL,GAAYD,KAAZ;IACA,OAAO,IAAP;EACH;;EAEME,UAAU,CAACC,OAAD,EAA6B;IAC1C,KAAKA,OAAL,GAAeA,OAAf;IACA,OAAO,IAAP;EACH;;EAEMC,OAAO,GAAqB;IAC/B,MAAMC,OAAyB,GAAG,EAAlC;;IAEA,IAAI,CAAC,KAAKJ,IAAV,EAAgB;MACZ,OAAOI,OAAP;IACH;;IACD,MAAMC,KAAK,GAAGL,aAAA,CAAKM,IAAL,CAAU,KAAKN,IAAf,CAAd;;IACAK,KAAK,CAACE,OAAN,CAAcC,IAAI,IAAI;MAClB,MAAMC,QAAQ,GAAGC,WAAA,CAAGC,YAAH,CAAgBH,IAAhB,EAAsB,MAAtB,CAAjB;;MACA,MAAMI,MAAM,GAAG,IAAAC,gBAAA,EAAQJ,QAAR,CAAf;;MACA,KAAK,MAAMK,GAAX,IAAkBF,MAAlB,EAA0B;QACtBR,OAAO,CAACU,GAAD,CAAP,GAAeF,MAAM,CAACE,GAAD,CAArB;MACH;IACJ,CAND;IAQA,OAAOV,OAAP;EACH;;EAEMW,WAAW,CAACC,IAAI,GAAG,IAAR,EAAyB;IACvC,KAAKC,QAAL,GAAgBD,IAAhB;IACA,OAAO,IAAP;EACH;;AApCW;;eAuCDnB,S"}
1
+ {"version":3,"file":"extractor/index.js","sources":["../../src/extractor/index.ts"],"sourcesContent":["import extract from \"./extract.js\";\nimport fastGlob from \"fast-glob\";\nimport fs from \"node:fs\";\n\nexport interface ExtractorResults {\n [key: string]: string;\n}\nclass Extractor {\n private glob: string | undefined;\n public content = \"\";\n public listOnly = false;\n\n public setGlob(value: string): Extractor {\n this.glob = value;\n return this;\n }\n\n public setContent(content: string): Extractor {\n this.content = content;\n return this;\n }\n\n public execute(): ExtractorResults {\n const results: ExtractorResults = {};\n\n if (!this.glob) {\n return results;\n }\n const paths = fastGlob.sync(this.glob);\n paths.forEach(path => {\n const contents = fs.readFileSync(path, \"utf8\");\n const parsed = extract(contents);\n for (const key in parsed) {\n results[key] = parsed[key];\n }\n });\n\n return results;\n }\n\n public setListOnly(flag = true): Extractor {\n this.listOnly = flag;\n return this;\n }\n}\n\nexport default Extractor;\n"],"names":["Extractor","value","content","results","paths","fastGlob","path","contents","fs","parsed","extract","key","flag"],"mappings":";;;AAOA,MAAMA;IAKK,QAAQC,KAAa,EAAa;QACrC,IAAI,CAAC,IAAI,GAAGA;QACZ,OAAO,IAAI;IACf;IAEO,WAAWC,OAAe,EAAa;QAC1C,IAAI,CAAC,OAAO,GAAGA;QACf,OAAO,IAAI;IACf;IAEO,UAA4B;QAC/B,MAAMC,UAA4B,CAAC;QAEnC,IAAI,CAAC,IAAI,CAAC,IAAI,EACV,OAAOA;QAEX,MAAMC,QAAQC,UAAAA,IAAa,CAAC,IAAI,CAAC,IAAI;QACrCD,MAAM,OAAO,CAACE,CAAAA;YACV,MAAMC,WAAWC,QAAAA,YAAe,CAACF,MAAM;YACvC,MAAMG,SAASC,QAAQH;YACvB,IAAK,MAAMI,OAAOF,OACdN,OAAO,CAACQ,IAAI,GAAGF,MAAM,CAACE,IAAI;QAElC;QAEA,OAAOR;IACX;IAEO,YAAYS,OAAO,IAAI,EAAa;QACvC,IAAI,CAAC,QAAQ,GAAGA;QAChB,OAAO,IAAI;IACf;;aAlCO,OAAO,GAAG;aACV,QAAQ,GAAG;;AAkCtB;AAEA,kBAAeZ"}
package/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import I18n from "./I18n";
2
- import defaultProcessor from "./processors/default";
1
+ import I18n from "./I18n.js";
2
+ import defaultProcessor from "./processors/default.js";
3
3
  declare const i18n: I18n;
4
- declare const defaultModifiers: import("./types").Modifier[];
4
+ declare const defaultModifiers: import("./types.js").Modifier[];
5
5
  export default i18n;
6
6
  export { I18n, defaultModifiers, defaultProcessor };
package/index.js CHANGED
@@ -1,34 +1,12 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- Object.defineProperty(exports, "I18n", {
9
- enumerable: true,
10
- get: function () {
11
- return _I18n.default;
12
- }
13
- });
14
- exports.defaultModifiers = exports.default = void 0;
15
- Object.defineProperty(exports, "defaultProcessor", {
16
- enumerable: true,
17
- get: function () {
18
- return _default2.default;
19
- }
20
- });
21
-
22
- var _I18n = _interopRequireDefault(require("./I18n"));
23
-
24
- var _default2 = _interopRequireDefault(require("./processors/default"));
25
-
26
- var _modifiers = _interopRequireDefault(require("./modifiers"));
27
-
28
- const i18n = new _I18n.default();
29
- const defaultModifiers = (0, _modifiers.default)({
30
- i18n
31
- });
32
- exports.defaultModifiers = defaultModifiers;
33
- var _default = i18n;
34
- exports.default = _default;
1
+ import I18n from "./I18n.js";
2
+ import modifiers from "./modifiers/index.js";
3
+ const i18n = new I18n();
4
+ const defaultModifiers = modifiers({
5
+ i18n: i18n
6
+ });
7
+ const src = i18n;
8
+ export { default as defaultProcessor } from "./processors/default.js";
9
+ export default src;
10
+ export { I18n, defaultModifiers };
11
+
12
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["i18n","I18n","defaultModifiers","modifiersFactory"],"sources":["index.ts"],"sourcesContent":["import I18n from \"./I18n\";\nimport defaultProcessor from \"./processors/default\";\nimport modifiersFactory from \"./modifiers\";\n\nconst i18n = new I18n();\n\nconst defaultModifiers = modifiersFactory({ i18n });\n\nexport default i18n;\n\nexport { I18n, defaultModifiers, defaultProcessor };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA,MAAMA,IAAI,GAAG,IAAIC,aAAJ,EAAb;AAEA,MAAMC,gBAAgB,GAAG,IAAAC,kBAAA,EAAiB;EAAEH;AAAF,CAAjB,CAAzB;;eAEeA,I"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import I18n from \"./I18n.js\";\nimport defaultProcessor from \"./processors/default.js\";\nimport modifiersFactory from \"./modifiers/index.js\";\n\nconst i18n = new I18n();\n\nconst defaultModifiers = modifiersFactory({ i18n });\n\nexport default i18n;\n\nexport { I18n, defaultModifiers, defaultProcessor };\n"],"names":["i18n","I18n","defaultModifiers","modifiersFactory"],"mappings":";;AAIA,MAAMA,OAAO,IAAIC;AAEjB,MAAMC,mBAAmBC,UAAiB;IAAEH,MAAAA;AAAK;AAEjD,YAAeA"}
@@ -1,3 +1,3 @@
1
- import { Modifier } from "../types";
1
+ import type { Modifier } from "../types.js";
2
2
  declare const _default: () => Modifier;
3
3
  export default _default;
@@ -1,43 +1,19 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _default = () => {
9
- return {
10
- name: "count",
11
-
12
- execute(value, parameters) {
13
- // Numbers can be single number or ranges.
14
- for (let i = 0; i < parameters.length; i = i + 2) {
15
- const current = parameters[i];
16
-
17
- if (current === "default") {
18
- return value + " " + parameters[i + 1];
1
+ const countModifier = ()=>({
2
+ name: "count",
3
+ execute (value, parameters) {
4
+ for(let i = 0; i < parameters.length; i += 2){
5
+ const current = parameters[i];
6
+ if ("default" === current) return value + " " + parameters[i + 1];
7
+ const numbers = current.split("-");
8
+ if (2 === numbers.length) {
9
+ if (value >= numbers[0] && value <= numbers[1]) return value + " " + parameters[i + 1];
10
+ continue;
11
+ }
12
+ if (String(value) === numbers[0]) return value + " " + parameters[i + 1];
13
+ }
14
+ return value;
19
15
  }
16
+ });
17
+ export default countModifier;
20
18
 
21
- const numbers = current.split("-"); // If we are dealing with a numbers range, then let's check if we are in it.
22
-
23
- if (numbers.length === 2) {
24
- if (value >= numbers[0] && value <= numbers[1]) {
25
- return value + " " + parameters[i + 1];
26
- }
27
-
28
- continue;
29
- }
30
-
31
- if (String(value) === numbers[0]) {
32
- return value + " " + parameters[i + 1];
33
- }
34
- } // If we didn't match any condition, let's just remove the received value.
35
-
36
-
37
- return value;
38
- }
39
-
40
- };
41
- };
42
-
43
- exports.default = _default;
19
+ //# sourceMappingURL=countModifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["name","execute","value","parameters","i","length","current","numbers","split","String"],"sources":["countModifier.ts"],"sourcesContent":["import { Modifier } from \"~/types\";\n\nexport default (): Modifier => {\n return {\n name: \"count\",\n execute(value: string, parameters: Array<string>) {\n // Numbers can be single number or ranges.\n for (let i = 0; i < parameters.length; i = i + 2) {\n const current = parameters[i];\n if (current === \"default\") {\n return value + \" \" + parameters[i + 1];\n }\n\n const numbers = current.split(\"-\");\n\n // If we are dealing with a numbers range, then let's check if we are in it.\n if (numbers.length === 2) {\n if (value >= numbers[0] && value <= numbers[1]) {\n return value + \" \" + parameters[i + 1];\n }\n continue;\n }\n\n if (String(value) === numbers[0]) {\n return value + \" \" + parameters[i + 1];\n }\n }\n\n // If we didn't match any condition, let's just remove the received value.\n return value;\n }\n };\n};\n"],"mappings":";;;;;;;eAEe,MAAgB;EAC3B,OAAO;IACHA,IAAI,EAAE,OADH;;IAEHC,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;MAC9C;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,UAAU,CAACE,MAA/B,EAAuCD,CAAC,GAAGA,CAAC,GAAG,CAA/C,EAAkD;QAC9C,MAAME,OAAO,GAAGH,UAAU,CAACC,CAAD,CAA1B;;QACA,IAAIE,OAAO,KAAK,SAAhB,EAA2B;UACvB,OAAOJ,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;QACH;;QAED,MAAMG,OAAO,GAAGD,OAAO,CAACE,KAAR,CAAc,GAAd,CAAhB,CAN8C,CAQ9C;;QACA,IAAID,OAAO,CAACF,MAAR,KAAmB,CAAvB,EAA0B;UACtB,IAAIH,KAAK,IAAIK,OAAO,CAAC,CAAD,CAAhB,IAAuBL,KAAK,IAAIK,OAAO,CAAC,CAAD,CAA3C,EAAgD;YAC5C,OAAOL,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;UACH;;UACD;QACH;;QAED,IAAIK,MAAM,CAACP,KAAD,CAAN,KAAkBK,OAAO,CAAC,CAAD,CAA7B,EAAkC;UAC9B,OAAOL,KAAK,GAAG,GAAR,GAAcC,UAAU,CAACC,CAAC,GAAG,CAAL,CAA/B;QACH;MACJ,CArB6C,CAuB9C;;;MACA,OAAOF,KAAP;IACH;;EA3BE,CAAP;AA6BH,C"}
1
+ {"version":3,"file":"modifiers/countModifier.js","sources":["../../src/modifiers/countModifier.ts"],"sourcesContent":["import type { Modifier } from \"~/types.js\";\n\nexport default (): Modifier => {\n return {\n name: \"count\",\n execute(value: string, parameters: Array<string>) {\n // Numbers can be single number or ranges.\n for (let i = 0; i < parameters.length; i = i + 2) {\n const current = parameters[i];\n if (current === \"default\") {\n return value + \" \" + parameters[i + 1];\n }\n\n const numbers = current.split(\"-\");\n\n // If we are dealing with a numbers range, then let's check if we are in it.\n if (numbers.length === 2) {\n if (value >= numbers[0] && value <= numbers[1]) {\n return value + \" \" + parameters[i + 1];\n }\n continue;\n }\n\n if (String(value) === numbers[0]) {\n return value + \" \" + parameters[i + 1];\n }\n }\n\n // If we didn't match any condition, let's just remove the received value.\n return value;\n }\n };\n};\n"],"names":["value","parameters","i","current","numbers","String"],"mappings":"AAEA,sBAAgB,IACL;QACH,MAAM;QACN,SAAQA,KAAa,EAAEC,UAAyB;YAE5C,IAAK,IAAIC,IAAI,GAAGA,IAAID,WAAW,MAAM,EAAEC,KAAQ,EAAG;gBAC9C,MAAMC,UAAUF,UAAU,CAACC,EAAE;gBAC7B,IAAIC,AAAY,cAAZA,SACA,OAAOH,QAAQ,MAAMC,UAAU,CAACC,IAAI,EAAE;gBAG1C,MAAME,UAAUD,QAAQ,KAAK,CAAC;gBAG9B,IAAIC,AAAmB,MAAnBA,QAAQ,MAAM,EAAQ;oBACtB,IAAIJ,SAASI,OAAO,CAAC,EAAE,IAAIJ,SAASI,OAAO,CAAC,EAAE,EAC1C,OAAOJ,QAAQ,MAAMC,UAAU,CAACC,IAAI,EAAE;oBAE1C;gBACJ;gBAEA,IAAIG,OAAOL,WAAWI,OAAO,CAAC,EAAE,EAC5B,OAAOJ,QAAQ,MAAMC,UAAU,CAACC,IAAI,EAAE;YAE9C;YAGA,OAAOF;QACX;IACJ"}
@@ -1,3 +1,3 @@
1
- import { Modifier, ModifierOptions } from "../types";
1
+ import type { Modifier, ModifierOptions } from "../types.js";
2
2
  declare const _default: ({ i18n }: ModifierOptions) => Modifier;
3
3
  export default _default;
@@ -1,19 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _default = ({
9
- i18n
10
- }) => ({
11
- name: "date",
12
-
13
- execute(value) {
14
- return i18n.date(value);
15
- }
16
-
17
- });
18
-
19
- exports.default = _default;
1
+ const dateModifier = ({ i18n })=>({
2
+ name: "date",
3
+ execute (value) {
4
+ return i18n.date(value);
5
+ }
6
+ });
7
+ export default dateModifier;
8
+
9
+ //# sourceMappingURL=dateModifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["i18n","name","execute","value","date"],"sources":["dateModifier.ts"],"sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"date\",\n execute(value) {\n return i18n.date(value);\n }\n});\n"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,MAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAQ;IACX,OAAOH,IAAI,CAACI,IAAL,CAAUD,KAAV,CAAP;EACH;;AAJoD,CAA1C,C"}
1
+ {"version":3,"file":"modifiers/dateModifier.js","sources":["../../src/modifiers/dateModifier.ts"],"sourcesContent":["import type { Modifier, ModifierOptions } from \"~/types.js\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"date\",\n execute(value) {\n return i18n.date(value);\n }\n});\n"],"names":["i18n","value"],"mappings":"AAEA,qBAAgB,GAAEA,IAAI,EAAmB,GAAgB;QACrD,MAAM;QACN,SAAQC,KAAK;YACT,OAAOD,KAAK,IAAI,CAACC;QACrB;IACJ"}
@@ -1,3 +1,3 @@
1
- import { Modifier, ModifierOptions } from "../types";
1
+ import type { Modifier, ModifierOptions } from "../types.js";
2
2
  declare const _default: ({ i18n }: ModifierOptions) => Modifier;
3
3
  export default _default;
@@ -1,19 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _default = ({
9
- i18n
10
- }) => ({
11
- name: "dateTime",
12
-
13
- execute(value) {
14
- return i18n.dateTime(value);
15
- }
16
-
17
- });
18
-
19
- exports.default = _default;
1
+ const dateTimeModifier = ({ i18n })=>({
2
+ name: "dateTime",
3
+ execute (value) {
4
+ return i18n.dateTime(value);
5
+ }
6
+ });
7
+ export default dateTimeModifier;
8
+
9
+ //# sourceMappingURL=dateTimeModifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["i18n","name","execute","value","dateTime"],"sources":["dateTimeModifier.ts"],"sourcesContent":["import { Modifier, ModifierOptions } from \"~/types\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"dateTime\",\n execute(value: string) {\n return i18n.dateTime(value);\n }\n});\n"],"mappings":";;;;;;;eAEe,CAAC;EAAEA;AAAF,CAAD,MAA0C;EACrDC,IAAI,EAAE,UAD+C;;EAErDC,OAAO,CAACC,KAAD,EAAgB;IACnB,OAAOH,IAAI,CAACI,QAAL,CAAcD,KAAd,CAAP;EACH;;AAJoD,CAA1C,C"}
1
+ {"version":3,"file":"modifiers/dateTimeModifier.js","sources":["../../src/modifiers/dateTimeModifier.ts"],"sourcesContent":["import type { Modifier, ModifierOptions } from \"~/types.js\";\n\nexport default ({ i18n }: ModifierOptions): Modifier => ({\n name: \"dateTime\",\n execute(value: string) {\n return i18n.dateTime(value);\n }\n});\n"],"names":["i18n","value"],"mappings":"AAEA,yBAAgB,GAAEA,IAAI,EAAmB,GAAgB;QACrD,MAAM;QACN,SAAQC,KAAa;YACjB,OAAOD,KAAK,QAAQ,CAACC;QACzB;IACJ"}
@@ -1,3 +1,3 @@
1
- import { Modifier } from "../types";
1
+ import type { Modifier } from "../types.js";
2
2
  declare const _default: () => Modifier;
3
3
  export default _default;
@@ -1,19 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _default = () => {
9
- return {
10
- name: "gender",
11
-
12
- execute(value, parameters) {
13
- return value === "male" ? parameters[0] : parameters[1];
14
- }
15
-
16
- };
17
- };
18
-
19
- exports.default = _default;
1
+ const genderModifier = ()=>({
2
+ name: "gender",
3
+ execute (value, parameters) {
4
+ return "male" === value ? parameters[0] : parameters[1];
5
+ }
6
+ });
7
+ export default genderModifier;
8
+
9
+ //# sourceMappingURL=genderModifier.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["name","execute","value","parameters"],"sources":["genderModifier.ts"],"sourcesContent":["import { Modifier } from \"~/types\";\n\nexport default (): Modifier => {\n return {\n name: \"gender\",\n execute(value: string, parameters: Array<string>) {\n return value === \"male\" ? parameters[0] : parameters[1];\n }\n };\n};\n"],"mappings":";;;;;;;eAEe,MAAgB;EAC3B,OAAO;IACHA,IAAI,EAAE,QADH;;IAEHC,OAAO,CAACC,KAAD,EAAgBC,UAAhB,EAA2C;MAC9C,OAAOD,KAAK,KAAK,MAAV,GAAmBC,UAAU,CAAC,CAAD,CAA7B,GAAmCA,UAAU,CAAC,CAAD,CAApD;IACH;;EAJE,CAAP;AAMH,C"}
1
+ {"version":3,"file":"modifiers/genderModifier.js","sources":["../../src/modifiers/genderModifier.ts"],"sourcesContent":["import type { Modifier } from \"~/types.js\";\n\nexport default (): Modifier => {\n return {\n name: \"gender\",\n execute(value: string, parameters: Array<string>) {\n return value === \"male\" ? parameters[0] : parameters[1];\n }\n };\n};\n"],"names":["value","parameters"],"mappings":"AAEA,uBAAgB,IACL;QACH,MAAM;QACN,SAAQA,KAAa,EAAEC,UAAyB;YAC5C,OAAOD,AAAU,WAAVA,QAAmBC,UAAU,CAAC,EAAE,GAAGA,UAAU,CAAC,EAAE;QAC3D;IACJ"}
@@ -1,3 +1,3 @@
1
- import { Modifier } from "../types";
1
+ import type { Modifier } from "../types.js";
2
2
  declare const _default: () => Modifier;
3
3
  export default _default;