@drewjbartlett/i17n
Advanced tools
Comparing version 0.0.19 to 0.0.20
@@ -22,2 +22,7 @@ export type Translations = { | ||
/** | ||
* The key that will be used to determine if we should do a lookup for __one or __many. | ||
* Default: 'n' | ||
*/ | ||
countKey?: string; | ||
/** | ||
* Optionally pass a prebuilt cache of the resolved { key: value } pairs. | ||
@@ -31,3 +36,3 @@ */ | ||
*/ | ||
export type InterpolatedFn = (interpolations: Interpolations) => string; | ||
export type InterpolatedFn<T = Interpolations> = (interpolations: T) => string; | ||
/** | ||
@@ -46,9 +51,6 @@ * The shape of interpolations. They may only be a key => value pair of strings: { user: 'drew' }. | ||
} | ||
export declare function buildCountValueKey(k: string, count: number): string; | ||
/** | ||
* The interpolations key that determines if we should do a lookup for __one or __many (CountValueIndicators). | ||
*/ | ||
export declare const COUNT_KEY = "count"; | ||
/** | ||
* Initialize the core i17n instance. | ||
*/ | ||
export declare function createI17n(config: I17nConfig): i17n; |
@@ -7,2 +7,2 @@ import { Interpolations } from '../core/create-i17n'; | ||
*/ | ||
export declare function replaceInterpolations(str: string, interpolations: Interpolations): string; | ||
export declare function replaceInterpolations<T extends Interpolations>(str: string, interpolations: T): string; |
@@ -16,4 +16,4 @@ function w(e) { | ||
return r !== null ? r.map((n) => { | ||
const c = n.match(/[\w\.]+/); | ||
return c ? c[0] : ""; | ||
const t = n.match(/[\w\.]+/); | ||
return t ? t[0] : ""; | ||
}).filter((n) => n !== "") : []; | ||
@@ -23,4 +23,4 @@ } | ||
let n = e; | ||
return Object.keys(r).forEach((c) => { | ||
n = n.replace(new RegExp(`{${c}}`, "g"), `${r[c]}`); | ||
return Object.keys(r).forEach((t) => { | ||
n = n.replace(new RegExp(`{${t}}`, "g"), `${r[t]}`); | ||
}), n; | ||
@@ -38,4 +38,4 @@ } | ||
return e in r ? r[e] : null; | ||
const c = n.reduce((t, i) => _(t) ? null : g(t) && i in t ? t[i] : null, r); | ||
return g(c) ? null : c; | ||
const t = n.reduce((c, i) => _(c) ? null : g(c) && i in c ? c[i] : null, r); | ||
return g(t) ? null : t; | ||
} | ||
@@ -45,6 +45,6 @@ function C(e) { | ||
} | ||
var $ = function(r) { | ||
return K(r) && !P(r); | ||
var K = function(r) { | ||
return $(r) && !P(r); | ||
}; | ||
function K(e) { | ||
function $(e) { | ||
return !!e && typeof e == "object"; | ||
@@ -67,4 +67,4 @@ } | ||
function V(e, r, n) { | ||
return e.concat(r).map(function(c) { | ||
return s(c, n); | ||
return e.concat(r).map(function(t) { | ||
return s(t, n); | ||
}); | ||
@@ -97,13 +97,13 @@ } | ||
function D(e, r, n) { | ||
var c = {}; | ||
return n.isMergeableObject(e) && j(e).forEach(function(t) { | ||
c[t] = s(e[t], n); | ||
}), j(r).forEach(function(t) { | ||
L(e, t) || (d(e, t) && n.isMergeableObject(r[t]) ? c[t] = H(t, n)(e[t], r[t], n) : c[t] = s(r[t], n)); | ||
}), c; | ||
var t = {}; | ||
return n.isMergeableObject(e) && j(e).forEach(function(c) { | ||
t[c] = s(e[c], n); | ||
}), j(r).forEach(function(c) { | ||
L(e, c) || (d(e, c) && n.isMergeableObject(r[c]) ? t[c] = H(c, n)(e[c], r[c], n) : t[c] = s(r[c], n)); | ||
}), t; | ||
} | ||
function o(e, r, n) { | ||
n = n || {}, n.arrayMerge = n.arrayMerge || V, n.isMergeableObject = n.isMergeableObject || $, n.cloneUnlessOtherwiseSpecified = s; | ||
var c = Array.isArray(r), t = Array.isArray(e), i = c === t; | ||
return i ? c ? n.arrayMerge(e, r, n) : D(e, r, n) : s(r, n); | ||
n = n || {}, n.arrayMerge = n.arrayMerge || V, n.isMergeableObject = n.isMergeableObject || K, n.cloneUnlessOtherwiseSpecified = s; | ||
var t = Array.isArray(r), c = Array.isArray(e), i = t === c; | ||
return i ? t ? n.arrayMerge(e, r, n) : D(e, r, n) : s(r, n); | ||
} | ||
@@ -113,8 +113,8 @@ o.all = function(r, n) { | ||
throw new Error("first argument should be an array"); | ||
return r.reduce(function(c, t) { | ||
return o(c, t, n); | ||
return r.reduce(function(t, c) { | ||
return o(t, c, n); | ||
}, {}); | ||
}; | ||
var W = o, Y = W; | ||
const B = /* @__PURE__ */ C(Y), b = "count"; | ||
const B = /* @__PURE__ */ C(Y); | ||
function q(e) { | ||
@@ -127,10 +127,10 @@ return e === 0 ? "many" : e === 1 ? "one" : "many"; | ||
function G(e) { | ||
const r = e.cache || /* @__PURE__ */ new Map(); | ||
let n = e.translations; | ||
const r = e.countKey || "n", n = e.cache || /* @__PURE__ */ new Map(); | ||
let t = e.translations; | ||
const c = !!e.loggingEnabled; | ||
function t(u) { | ||
n = B(n, u), r.clear(); | ||
function i(u) { | ||
t = B(t, u), n.clear(); | ||
} | ||
function i(u, l) { | ||
const a = r.get(u); | ||
function b(u, l) { | ||
const a = n.get(u); | ||
return { | ||
@@ -143,7 +143,7 @@ key: u, | ||
function h(u, l) { | ||
if (l && b in l && I(l[b])) { | ||
const a = z(u, l[b]); | ||
if (r.has(a)) | ||
return i(a); | ||
const f = m(a, n); | ||
if (l && r in l && I(l[r])) { | ||
const a = z(u, l[r]); | ||
if (n.has(a)) | ||
return b(a); | ||
const f = m(a, t); | ||
if (f) | ||
@@ -156,3 +156,3 @@ return { | ||
} | ||
return r.has(u) ? i(u, l) : { key: u, value: m(u, n), cacheHit: !1 }; | ||
return n.has(u) ? b(u, l) : { key: u, value: m(u, t), cacheHit: !1 }; | ||
} | ||
@@ -166,5 +166,5 @@ function O(u, l) { | ||
const y = (M) => T(f, M); | ||
return r.set(a, y), y(l); | ||
return n.set(a, y), y(l); | ||
} | ||
return r.set(a, f), f; | ||
return n.set(a, f), f; | ||
} | ||
@@ -178,3 +178,3 @@ return p(`No translation was found for key '${a}'.`), a; | ||
t: O, | ||
extend: t | ||
extend: i | ||
}; | ||
@@ -181,0 +181,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"type": "module", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"files": [ | ||
@@ -8,0 +8,0 @@ "dist" |
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
19813
284