Comparing version 4.1.1 to 4.2.0
import BigNumber from "bignumber.js"; | ||
import { repeat } from "lodash"; | ||
import { roundNumber } from "."; | ||
import { roundNumber } from "./roundNumber"; | ||
function replaceInFormat(format, { formattedNumber, unit }) { | ||
@@ -5,0 +5,0 @@ return format.replace("%n", formattedNumber).replace("%u", unit); |
export function inferType(instance) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
if (instance === null) { | ||
@@ -10,4 +10,4 @@ return "null"; | ||
} | ||
return ((_b = (_a = instance === null || instance === void 0 ? void 0 : instance.constructor) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "object"; | ||
return ((_c = (_b = (_a = instance) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || "object"; | ||
} | ||
//# sourceMappingURL=inferType.js.map |
@@ -111,2 +111,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
} | ||
if (options && translation instanceof Array) { | ||
translation = translation.map((entry) => typeof entry === "string" | ||
? interpolate(this, entry, options) | ||
: entry); | ||
} | ||
return translation; | ||
@@ -252,2 +257,5 @@ } | ||
} | ||
formatNumber(input, options) { | ||
return formatNumber(input, options); | ||
} | ||
get(scope) { | ||
@@ -254,0 +262,0 @@ return lookup(this, scope); |
@@ -10,3 +10,3 @@ "use strict"; | ||
return Object.keys(target).reduce((buffer, key) => { | ||
buffer[(0, lodash_1.camelCase)(key)] = target[key]; | ||
buffer[lodash_1.camelCase(key)] = target[key]; | ||
return buffer; | ||
@@ -13,0 +13,0 @@ }, {}); |
@@ -7,6 +7,6 @@ "use strict"; | ||
let translationOptions = [{ scope }]; | ||
if ((0, isSet_1.isSet)(options.defaults)) { | ||
if (isSet_1.isSet(options.defaults)) { | ||
translationOptions = translationOptions.concat(options.defaults); | ||
} | ||
if ((0, isSet_1.isSet)(options.defaultValue)) { | ||
if (isSet_1.isSet(options.defaultValue)) { | ||
const message = typeof options.defaultValue === "function" | ||
@@ -13,0 +13,0 @@ ? options.defaultValue(i18n, scope, options) |
@@ -9,3 +9,3 @@ "use strict"; | ||
const lodash_1 = require("lodash"); | ||
const _1 = require("."); | ||
const roundNumber_1 = require("./roundNumber"); | ||
function replaceInFormat(format, { formattedNumber, unit }) { | ||
@@ -27,3 +27,3 @@ return format.replace("%n", formattedNumber).replace("%u", unit); | ||
} | ||
const roundedNumber = (0, _1.roundNumber)(originalNumber, options); | ||
const roundedNumber = roundNumber_1.roundNumber(originalNumber, options); | ||
const numeric = new bignumber_js_1.default(roundedNumber); | ||
@@ -53,3 +53,3 @@ const isNegative = numeric.lt(0); | ||
else { | ||
significand = significand !== null && significand !== void 0 ? significand : (0, lodash_1.repeat)("0", (_c = options.precision) !== null && _c !== void 0 ? _c : 0); | ||
significand = significand !== null && significand !== void 0 ? significand : lodash_1.repeat("0", (_c = options.precision) !== null && _c !== void 0 ? _c : 0); | ||
} | ||
@@ -56,0 +56,0 @@ if (options.stripInsignificantZeros && significand) { |
@@ -5,3 +5,3 @@ "use strict"; | ||
function inferType(instance) { | ||
var _a, _b; | ||
var _a, _b, _c; | ||
if (instance === null) { | ||
@@ -14,5 +14,5 @@ return "null"; | ||
} | ||
return ((_b = (_a = instance === null || instance === void 0 ? void 0 : instance.constructor) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "object"; | ||
return ((_c = (_b = (_a = instance) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || "object"; | ||
} | ||
exports.inferType = inferType; | ||
//# sourceMappingURL=inferType.js.map |
@@ -18,3 +18,3 @@ "use strict"; | ||
const name = placeholder.replace(i18n.placeholder, "$1"); | ||
if ((0, isSet_1.isSet)(options[name])) { | ||
if (isSet_1.isSet(options[name])) { | ||
value = options[name].toString().replace(/\$/gm, "_#$#_"); | ||
@@ -21,0 +21,0 @@ } |
@@ -11,15 +11,15 @@ "use strict"; | ||
const locale = "locale" in options ? options.locale : i18n.locale; | ||
const localeType = (0, inferType_1.inferType)(locale); | ||
const localeType = inferType_1.inferType(locale); | ||
const locales = i18n.locales | ||
.get(localeType === "string" ? locale : typeof locale) | ||
.slice(); | ||
scope = (0, getFullScope_1.getFullScope)(i18n, scope, options) | ||
scope = getFullScope_1.getFullScope(i18n, scope, options) | ||
.split(i18n.defaultSeparator) | ||
.map((component) => i18n.transformKey(component)) | ||
.join("."); | ||
const entries = locales.map((locale) => (0, lodash_1.get)(i18n.translations, [locale, scope].join("."))); | ||
const entries = locales.map((locale) => lodash_1.get(i18n.translations, [locale, scope].join("."))); | ||
entries.push(options.defaultValue); | ||
return entries.find((entry) => (0, isSet_1.isSet)(entry)); | ||
return entries.find((entry) => isSet_1.isSet(entry)); | ||
} | ||
exports.lookup = lookup; | ||
//# sourceMappingURL=lookup.js.map |
@@ -30,3 +30,3 @@ "use strict"; | ||
}; | ||
const INVERTED_DECIMAL_UNITS = (0, lodash_1.zipObject)(Object.values(DECIMAL_UNITS), Object.keys(DECIMAL_UNITS).map((key) => parseInt(key, 10))); | ||
const INVERTED_DECIMAL_UNITS = lodash_1.zipObject(Object.values(DECIMAL_UNITS), Object.keys(DECIMAL_UNITS).map((key) => parseInt(key, 10))); | ||
function numberToHuman(i18n, input, options) { | ||
@@ -39,7 +39,7 @@ const roundOptions = { | ||
let units; | ||
if ((0, inferType_1.inferType)(options.units) === "string") { | ||
if (inferType_1.inferType(options.units) === "string") { | ||
const scope = options.units; | ||
units = (0, lookup_1.lookup)(i18n, scope); | ||
units = lookup_1.lookup(i18n, scope); | ||
if (!units) { | ||
throw new Error(`The scope "${i18n.locale}${i18n.defaultSeparator}${(0, getFullScope_1.getFullScope)(i18n, scope, {})}" couldn't be found`); | ||
throw new Error(`The scope "${i18n.locale}${i18n.defaultSeparator}${getFullScope_1.getFullScope(i18n, scope, {})}" couldn't be found`); | ||
} | ||
@@ -50,4 +50,4 @@ } | ||
} | ||
let formattedNumber = (0, roundNumber_1.roundNumber)(new bignumber_js_1.default(input), roundOptions); | ||
const unitExponents = (units) => (0, lodash_1.sortBy)(Object.keys(units).map((name) => INVERTED_DECIMAL_UNITS[name]), (numeric) => numeric * -1); | ||
let formattedNumber = roundNumber_1.roundNumber(new bignumber_js_1.default(input), roundOptions); | ||
const unitExponents = (units) => lodash_1.sortBy(Object.keys(units).map((name) => INVERTED_DECIMAL_UNITS[name]), (numeric) => numeric * -1); | ||
const calculateExponent = (num, units) => { | ||
@@ -65,3 +65,3 @@ const exponent = num.isZero() | ||
const unit = determineUnit(units, exponent); | ||
formattedNumber = (0, roundNumber_1.roundNumber)(new bignumber_js_1.default(formattedNumber).div(Math.pow(10, exponent)), roundOptions); | ||
formattedNumber = roundNumber_1.roundNumber(new bignumber_js_1.default(formattedNumber).div(Math.pow(10, exponent)), roundOptions); | ||
if (options.stripInsignificantZeros) { | ||
@@ -68,0 +68,0 @@ let [whole, significand] = formattedNumber.split("."); |
@@ -12,3 +12,3 @@ "use strict"; | ||
function numberToHumanSize(i18n, input, options) { | ||
const roundMode = (0, expandRoundMode_1.expandRoundMode)(options.roundMode); | ||
const roundMode = expandRoundMode_1.expandRoundMode(options.roundMode); | ||
const base = 1024; | ||
@@ -35,3 +35,3 @@ const num = new bignumber_js_1.default(input).abs(); | ||
else { | ||
numberToBeFormatted = new bignumber_js_1.default((0, roundNumber_1.roundNumber)(num.div(Math.pow(base, exponent)), { | ||
numberToBeFormatted = new bignumber_js_1.default(roundNumber_1.roundNumber(num.div(Math.pow(base, exponent)), { | ||
significant: options.significant, | ||
@@ -38,0 +38,0 @@ precision: options.precision, |
@@ -14,3 +14,3 @@ "use strict"; | ||
else { | ||
translations = (0, lookup_1.lookup)(i18n, scope, options); | ||
translations = lookup_1.lookup(i18n, scope, options); | ||
} | ||
@@ -24,3 +24,3 @@ if (!translations) { | ||
const key = keys.shift(); | ||
if ((0, isSet_1.isSet)(translations[key])) { | ||
if (isSet_1.isSet(translations[key])) { | ||
message = translations[key]; | ||
@@ -27,0 +27,0 @@ break; |
@@ -10,3 +10,3 @@ "use strict"; | ||
call() { | ||
const keys = (0, lodash_1.flattenDeep)(Object.keys(this.target).map((key) => this.compute(this.target[key], key))); | ||
const keys = lodash_1.flattenDeep(Object.keys(this.target).map((key) => this.compute(this.target[key], key))); | ||
keys.sort(); | ||
@@ -16,3 +16,3 @@ return keys; | ||
compute(value, path) { | ||
if (!(0, lodash_1.isArray)(value) && (0, lodash_1.isObject)(value)) { | ||
if (!lodash_1.isArray(value) && lodash_1.isObject(value)) { | ||
return Object.keys(value).map((key) => this.compute(value[key], `${path}.${key}`)); | ||
@@ -19,0 +19,0 @@ } |
@@ -26,3 +26,3 @@ "use strict"; | ||
} | ||
const roundMode = (0, expandRoundMode_1.expandRoundMode)(options.roundMode); | ||
const roundMode = expandRoundMode_1.expandRoundMode(options.roundMode); | ||
if (precision >= 0) { | ||
@@ -29,0 +29,0 @@ return numeric.toFixed(precision, roundMode); |
@@ -10,4 +10,4 @@ "use strict"; | ||
const t = (name, count = 0) => i18n.t(name, { count, scope }); | ||
fromTime = (0, parseDate_1.parseDate)(fromTime); | ||
toTime = (0, parseDate_1.parseDate)(toTime); | ||
fromTime = parseDate_1.parseDate(fromTime); | ||
toTime = parseDate_1.parseDate(toTime); | ||
let fromInSeconds = fromTime.getTime() / 1000; | ||
@@ -84,3 +84,3 @@ let toInSeconds = toTime.getTime() / 1000; | ||
? 0 | ||
: (0, lodash_1.range)(fromYear, toYear).filter((year) => new Date(year, 1, 29).getMonth() == 1).length; | ||
: lodash_1.range(fromYear, toYear).filter((year) => new Date(year, 1, 29).getMonth() == 1).length; | ||
const minutesInYear = 525600; | ||
@@ -87,0 +87,0 @@ const minuteOffsetForLeapYear = leapYears * 1440; |
@@ -60,4 +60,4 @@ "use strict"; | ||
store(translations) { | ||
const map = (0, helpers_1.propertyFlatList)(translations); | ||
map.forEach((path) => (0, lodash_1.set)(this.translations, path, (0, lodash_1.get)(translations, path))); | ||
const map = helpers_1.propertyFlatList(translations); | ||
map.forEach((path) => lodash_1.set(this.translations, path, lodash_1.get(translations, path))); | ||
this.hasChanged(); | ||
@@ -70,3 +70,3 @@ } | ||
if (typeof newLocale !== "string") { | ||
throw new Error(`Expected newLocale to be a string; got ${(0, helpers_1.inferType)(newLocale)}`); | ||
throw new Error(`Expected newLocale to be a string; got ${helpers_1.inferType(newLocale)}`); | ||
} | ||
@@ -84,3 +84,3 @@ const changed = this._locale !== newLocale; | ||
if (typeof newLocale !== "string") { | ||
throw new Error(`Expected newLocale to be a string; got ${(0, helpers_1.inferType)(newLocale)}`); | ||
throw new Error(`Expected newLocale to be a string; got ${helpers_1.inferType(newLocale)}`); | ||
} | ||
@@ -95,9 +95,9 @@ const changed = this._defaultLocale !== newLocale; | ||
options = Object.assign({}, options); | ||
const translationOptions = (0, helpers_1.createTranslationOptions)(this, scope, options); | ||
const translationOptions = helpers_1.createTranslationOptions(this, scope, options); | ||
let translation; | ||
const hasFoundTranslation = translationOptions.some((translationOption) => { | ||
if ((0, helpers_1.isSet)(translationOption.scope)) { | ||
translation = (0, helpers_1.lookup)(this, translationOption.scope, options); | ||
if (helpers_1.isSet(translationOption.scope)) { | ||
translation = helpers_1.lookup(this, translationOption.scope, options); | ||
} | ||
else if ((0, helpers_1.isSet)(translationOption.message)) { | ||
else if (helpers_1.isSet(translationOption.message)) { | ||
translation = translationOption.message; | ||
@@ -115,9 +115,14 @@ } | ||
translation && | ||
(0, helpers_1.isSet)(options.count)) { | ||
helpers_1.isSet(options.count)) { | ||
translation = this.pluralize(options.count || 0, translation, options); | ||
} | ||
if (options && translation instanceof Array) { | ||
translation = translation.map((entry) => typeof entry === "string" | ||
? helpers_1.interpolate(this, entry, options) | ||
: entry); | ||
} | ||
return translation; | ||
} | ||
pluralize(count, scope, options) { | ||
return (0, helpers_1.pluralize)(this, count, scope, Object.assign({}, options)); | ||
return helpers_1.pluralize(this, count, scope, Object.assign({}, options)); | ||
} | ||
@@ -133,3 +138,3 @@ localize(type, value, options) { | ||
case "number": | ||
return (0, helpers_1.formatNumber)(value, Object.assign({ delimiter: ",", precision: 3, separator: ".", significant: false, stripInsignificantZeros: false }, (0, helpers_1.lookup)(this, "number.format"))); | ||
return helpers_1.formatNumber(value, Object.assign({ delimiter: ",", precision: 3, separator: ".", significant: false, stripInsignificantZeros: false }, helpers_1.lookup(this, "number.format"))); | ||
case "percentage": | ||
@@ -145,3 +150,3 @@ return this.numberToPercentage(value); | ||
} | ||
return (0, helpers_1.interpolate)(this, localizedValue, options); | ||
return helpers_1.interpolate(this, localizedValue, options); | ||
} | ||
@@ -151,4 +156,4 @@ } | ||
toTime(scope, input) { | ||
const date = (0, helpers_1.parseDate)(input); | ||
const format = (0, helpers_1.lookup)(this, scope); | ||
const date = helpers_1.parseDate(input); | ||
const format = helpers_1.lookup(this, scope); | ||
if (date.toString().match(/invalid/i)) { | ||
@@ -163,9 +168,9 @@ return date.toString(); | ||
numberToCurrency(input, options = {}) { | ||
return (0, helpers_1.formatNumber)(input, Object.assign(Object.assign(Object.assign({ delimiter: ",", format: "%u%n", precision: 2, separator: ".", significant: false, stripInsignificantZeros: false, unit: "$" }, (0, helpers_1.camelCaseKeys)(this.get("number.format"))), (0, helpers_1.camelCaseKeys)(this.get("number.currency.format"))), options)); | ||
return helpers_1.formatNumber(input, Object.assign(Object.assign(Object.assign({ delimiter: ",", format: "%u%n", precision: 2, separator: ".", significant: false, stripInsignificantZeros: false, unit: "$" }, helpers_1.camelCaseKeys(this.get("number.format"))), helpers_1.camelCaseKeys(this.get("number.currency.format"))), options)); | ||
} | ||
numberToPercentage(input, options = {}) { | ||
return (0, helpers_1.formatNumber)(input, Object.assign(Object.assign(Object.assign({ delimiter: "", format: "%n%", precision: 3, stripInsignificantZeros: false, separator: ".", significant: false }, (0, helpers_1.camelCaseKeys)(this.get("number.format"))), (0, helpers_1.camelCaseKeys)(this.get("number.percentage.format"))), options)); | ||
return helpers_1.formatNumber(input, Object.assign(Object.assign(Object.assign({ delimiter: "", format: "%n%", precision: 3, stripInsignificantZeros: false, separator: ".", significant: false }, helpers_1.camelCaseKeys(this.get("number.format"))), helpers_1.camelCaseKeys(this.get("number.percentage.format"))), options)); | ||
} | ||
numberToHumanSize(input, options = {}) { | ||
return (0, helpers_1.numberToHumanSize)(this, input, Object.assign(Object.assign(Object.assign({ delimiter: "", precision: 3, significant: true, stripInsignificantZeros: true, units: { | ||
return helpers_1.numberToHumanSize(this, input, Object.assign(Object.assign(Object.assign({ delimiter: "", precision: 3, significant: true, stripInsignificantZeros: true, units: { | ||
billion: "Billion", | ||
@@ -177,6 +182,6 @@ million: "Million", | ||
unit: "", | ||
} }, (0, helpers_1.camelCaseKeys)(this.get("number.human.format"))), (0, helpers_1.camelCaseKeys)(this.get("number.human.storage_units"))), options)); | ||
} }, helpers_1.camelCaseKeys(this.get("number.human.format"))), helpers_1.camelCaseKeys(this.get("number.human.storage_units"))), options)); | ||
} | ||
numberToHuman(input, options = {}) { | ||
return (0, helpers_1.numberToHuman)(this, input, Object.assign(Object.assign(Object.assign({ delimiter: "", separator: ".", precision: 3, significant: true, stripInsignificantZeros: true, format: "%n %u", roundMode: "default", units: { | ||
return helpers_1.numberToHuman(this, input, Object.assign(Object.assign(Object.assign({ delimiter: "", separator: ".", precision: 3, significant: true, stripInsignificantZeros: true, format: "%n %u", roundMode: "default", units: { | ||
billion: "Billion", | ||
@@ -188,9 +193,9 @@ million: "Million", | ||
unit: "", | ||
} }, (0, helpers_1.camelCaseKeys)(this.get("number.human.format"))), (0, helpers_1.camelCaseKeys)(this.get("number.human.decimal_units"))), options)); | ||
} }, helpers_1.camelCaseKeys(this.get("number.human.format"))), helpers_1.camelCaseKeys(this.get("number.human.decimal_units"))), options)); | ||
} | ||
numberToRounded(input, options) { | ||
return (0, helpers_1.formatNumber)(input, Object.assign({ unit: "", precision: 3, significant: false, separator: ".", delimiter: "", stripInsignificantZeros: false }, options)); | ||
return helpers_1.formatNumber(input, Object.assign({ unit: "", precision: 3, significant: false, separator: ".", delimiter: "", stripInsignificantZeros: false }, options)); | ||
} | ||
numberToDelimited(input, options = {}) { | ||
return (0, helpers_1.numberToDelimited)(input, Object.assign({ delimiterPattern: /(\d)(?=(\d\d\d)+(?!\d))/g, delimiter: ",", separator: "." }, options)); | ||
return helpers_1.numberToDelimited(input, Object.assign({ delimiterPattern: /(\d)(?=(\d\d\d)+(?!\d))/g, delimiter: ",", separator: "." }, options)); | ||
} | ||
@@ -210,14 +215,14 @@ withLocale(locale, callback) { | ||
strftime(date, format, options = {}) { | ||
return (0, helpers_1.strftime)(date, format, Object.assign(Object.assign(Object.assign({}, (0, helpers_1.camelCaseKeys)((0, helpers_1.lookup)(this, "date"))), { meridian: { | ||
am: (0, helpers_1.lookup)(this, "time.am") || "AM", | ||
pm: (0, helpers_1.lookup)(this, "time.pm") || "PM", | ||
return helpers_1.strftime(date, format, Object.assign(Object.assign(Object.assign({}, helpers_1.camelCaseKeys(helpers_1.lookup(this, "date"))), { meridian: { | ||
am: helpers_1.lookup(this, "time.am") || "AM", | ||
pm: helpers_1.lookup(this, "time.pm") || "PM", | ||
} }), options)); | ||
} | ||
update(path, override, options = { strict: false }) { | ||
if (options.strict && !(0, lodash_1.has)(this.translations, path)) { | ||
if (options.strict && !lodash_1.has(this.translations, path)) { | ||
throw new Error(`The path "${path}" is not currently defined`); | ||
} | ||
const currentNode = (0, lodash_1.get)(this.translations, path); | ||
const currentType = (0, helpers_1.inferType)(currentNode); | ||
const overrideType = (0, helpers_1.inferType)(override); | ||
const currentNode = lodash_1.get(this.translations, path); | ||
const currentType = helpers_1.inferType(currentNode); | ||
const overrideType = helpers_1.inferType(override); | ||
if (options.strict && currentType !== overrideType) { | ||
@@ -233,7 +238,7 @@ throw new Error(`The current type for "${path}" is "${currentType}", but you're trying to override it with "${overrideType}"`); | ||
} | ||
(0, lodash_1.set)(this.translations, path, newNode); | ||
lodash_1.set(this.translations, path, newNode); | ||
this.hasChanged(); | ||
} | ||
toSentence(items, options = {}) { | ||
const { wordsConnector, twoWordsConnector, lastWordConnector } = Object.assign(Object.assign({ wordsConnector: ", ", twoWordsConnector: " and ", lastWordConnector: ", and " }, (0, helpers_1.camelCaseKeys)((0, helpers_1.lookup)(this, "support.array"))), options); | ||
const { wordsConnector, twoWordsConnector, lastWordConnector } = Object.assign(Object.assign({ wordsConnector: ", ", twoWordsConnector: " and ", lastWordConnector: ", and " }, helpers_1.camelCaseKeys(helpers_1.lookup(this, "support.array"))), options); | ||
const size = items.length; | ||
@@ -256,3 +261,3 @@ switch (size) { | ||
timeAgoInWords(fromTime, toTime, options = {}) { | ||
return (0, helpers_1.timeAgoInWords)(this, fromTime, toTime, options); | ||
return helpers_1.timeAgoInWords(this, fromTime, toTime, options); | ||
} | ||
@@ -268,4 +273,7 @@ onChange(callback) { | ||
} | ||
formatNumber(input, options) { | ||
return helpers_1.formatNumber(input, options); | ||
} | ||
get(scope) { | ||
return (0, helpers_1.lookup)(this, scope); | ||
return helpers_1.lookup(this, scope); | ||
} | ||
@@ -272,0 +280,0 @@ runCallbacks() { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
@@ -10,0 +6,0 @@ if (k2 === undefined) k2 = k; |
@@ -31,3 +31,3 @@ "use strict"; | ||
}); | ||
return (0, lodash_1.uniq)(list); | ||
return lodash_1.uniq(list); | ||
}; | ||
@@ -34,0 +34,0 @@ exports.defaultLocaleResolver = defaultLocaleResolver; |
@@ -17,5 +17,5 @@ "use strict"; | ||
const messageStrategy = (i18n, scope, options) => { | ||
const fullScope = (0, helpers_1.getFullScope)(i18n, scope, options); | ||
const fullScope = helpers_1.getFullScope(i18n, scope, options); | ||
const locale = "locale" in options ? options.locale : i18n.locale; | ||
const localeType = (0, helpers_1.inferType)(locale); | ||
const localeType = helpers_1.inferType(locale); | ||
const fullScopeWithLocale = [ | ||
@@ -29,3 +29,3 @@ localeType == "string" ? locale : localeType, | ||
const errorStrategy = (i18n, scope, options) => { | ||
const fullScope = (0, helpers_1.getFullScope)(i18n, scope, options); | ||
const fullScope = helpers_1.getFullScope(i18n, scope, options); | ||
const fullScopeWithLocale = [i18n.locale, fullScope].join(i18n.defaultSeparator); | ||
@@ -32,0 +32,0 @@ throw new Error(`Missing translation: ${fullScopeWithLocale}`); |
{ | ||
"name": "i18n-js", | ||
"version": "4.1.1", | ||
"version": "4.2.0", | ||
"description": "A small library to provide I18n on JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/import/index.js", |
@@ -191,4 +191,19 @@ <p align="center"> | ||
You may want to override the default [`interpolate`](https://github.com/fnando/i18n/blob/main/src/helpers/interpolate.ts) function with your own, if for instance you want these dynamic values to be React elements: | ||
If the translation is an array and the entry is a string, values will be | ||
interpolated in a shallow way. | ||
```js | ||
const i18n = new I18n({ | ||
en: { messages: ["Hello there!", "Welcome back, %{name}!"] }, | ||
}); | ||
i18n.t("messages", { name: "John" }); | ||
//=> ["Hello there!", "Welcome back, John!"] | ||
``` | ||
You may want to override the default | ||
[`interpolate`](https://github.com/fnando/i18n/blob/main/src/helpers/interpolate.ts) | ||
function with your own, if for instance you want these dynamic values to be | ||
React elements: | ||
```jsx | ||
@@ -202,9 +217,5 @@ const i18n = new I18n({ | ||
// ... | ||
} | ||
}; | ||
return ( | ||
<Text> | ||
{i18n.t("greetings", { name: <BoldText>John</BoldText> })} | ||
</Text> | ||
) | ||
return <Text>{i18n.t("greetings", { name: <BoldText>John</BoldText> })}</Text>; | ||
``` | ||
@@ -1009,3 +1020,3 @@ | ||
count: points, | ||
points: i18n.toNumber(points), | ||
points: i18n.formatNumber(points), | ||
}); | ||
@@ -1012,0 +1023,0 @@ ``` |
@@ -1,2 +0,2 @@ | ||
import { DateTime, Dict, I18nOptions, MissingPlaceholderHandler, NullPlaceholderHandler, NumberToCurrencyOptions, NumberToDelimitedOptions, NumberToHumanOptions, NumberToHumanSizeOptions, NumberToPercentageOptions, NumberToRoundedOptions, Numeric, OnChangeHandler, Scope, StrftimeOptions, TimeAgoInWordsOptions, ToSentenceOptions, TranslateOptions } from "./typing"; | ||
import { DateTime, Dict, FormatNumberOptions, I18nOptions, MissingPlaceholderHandler, NullPlaceholderHandler, NumberToCurrencyOptions, NumberToDelimitedOptions, NumberToHumanOptions, NumberToHumanSizeOptions, NumberToPercentageOptions, NumberToRoundedOptions, Numeric, OnChangeHandler, Scope, StrftimeOptions, TimeAgoInWordsOptions, ToSentenceOptions, TranslateOptions } from "./typing"; | ||
import { Locales } from "./Locales"; | ||
@@ -31,7 +31,7 @@ import { Pluralization } from "./Pluralization"; | ||
translate(scope: Scope, options?: TranslateOptions): string; | ||
t: (scope: Scope, options?: TranslateOptions) => string; | ||
t: (scope: Scope, options?: TranslateOptions | undefined) => string; | ||
pluralize(count: number, scope: Scope, options?: TranslateOptions): string; | ||
p: (count: number, scope: Scope, options?: TranslateOptions) => string; | ||
p: (count: number, scope: Scope, options?: TranslateOptions | undefined) => string; | ||
localize(type: string, value: string | number | Date | null | undefined, options?: Dict): string; | ||
l: (type: string, value: string | number | Date | null | undefined, options?: Dict) => string; | ||
l: (type: string, value: string | number | Date | null | undefined, options?: Dict | undefined) => string; | ||
toTime(scope: Scope, input: DateTime): string; | ||
@@ -54,2 +54,3 @@ numberToCurrency(input: Numeric, options?: Partial<NumberToCurrencyOptions>): string; | ||
get version(): number; | ||
formatNumber(input: Numeric, options: FormatNumberOptions): string; | ||
get(scope: Scope): any; | ||
@@ -56,0 +57,0 @@ private runCallbacks; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1794501
27163
1110