Socket
Socket
Sign inDemoInstall

svelte-i18n

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-i18n - npm Package Compare versions

Comparing version 2.2.3 to 2.2.4

7

CHANGELOG.md

@@ -0,5 +1,12 @@

## [2.2.4](https://github.com/kaisermann/svelte-i18n/compare/v2.2.2...v2.2.4) (2020-01-21)
## [2.2.3](https://github.com/kaisermann/svelte-i18n/compare/v2.2.2...v2.2.3) (2020-01-15)
### Refactor
* 💡 remove deepmerge and dlv dependencies ([270aefa](https://github.com/kaisermann/svelte-i18n/commit/270aefa1998d89215d8bdd1f813bdb9c690a5a2c))
## [2.2.2](https://github.com/kaisermann/svelte-i18n/compare/v2.2.0...v2.2.2) (2020-01-14)

@@ -6,0 +13,0 @@

4

dist/i18n.cjs.js

@@ -1,2 +0,2 @@

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("svelte/store"),n=e(require("intl-messageformat")),o=e(require("fast-memoize"));const r=(e,t="")=>{const n={};for(const o in e){const a=t+o;"object"==typeof e[o]?Object.assign(n,r(e[o],`${a}.`)):n[a]=e[o]}return n},a=(e,t)=>{const n=e.split("&").find(e=>0===e.indexOf(`${t}=`));return n?n.split("=").pop():null},i=(e,t)=>{const n=t.exec(e);return n&&n[1]||null};let s;const l=t.writable({});function c(e){return e in s}function u(e,t){if(c(e)){const n=function(e){return s[e]||null}(e);if(t in n)return n[t]}return null}function m(e,...t){const n=t.map(e=>r(e));l.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const f=t.derived([l],([e])=>Object.keys(e));l.subscribe(e=>s=e);const p=t.writable(!1);
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("svelte/store"),n=(e=require("intl-messageformat"))&&"object"==typeof e&&"default"in e?e.default:e;const r=(e,t="")=>{const n={};for(const o in e){const a=t+o;"object"==typeof e[o]?Object.assign(n,r(e[o],`${a}.`)):n[a]=e[o]}return n},o=(e,t)=>{const n=e.split("&").find(e=>0===e.indexOf(`${t}=`));return n?n.split("=").pop():null},a=(e,t)=>{const n=t.exec(e);return n&&n[1]||null};let i;const s=t.writable({});function l(e){return e in i}function c(e,t){if(l(e)){const n=function(e){return i[e]||null}(e);if(t in n)return n[t]}return null}function u(e,...t){const n=t.map(e=>r(e));s.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const m=t.derived([s],([e])=>Object.keys(e));s.subscribe(e=>i=e);const f=t.writable(!1);
/*! *****************************************************************************

@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation. All rights reserved.

and limitations under the License.
***************************************************************************** */function d(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}const g={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function h(){return g}const w={};function b(e){return w[e]}function y(e){return D(e).reverse().some(b)}const v={};function x(e){if(!y(e))return;if(e in v)return v[e];const t=function(e){return D(e).reverse().map(e=>{const t=b(e);return[e,t?[...t]:[]]}).filter(([,e])=>e.length>0)}(e);if(0===t.length)return;const n=setTimeout(()=>p.set(!0),h().loadingDelay);return v[e]=Promise.all(t.map(([e,t])=>Promise.all(t.map(e=>e())).then(t=>{!function(e){delete w[e]}(e),t=t.map(e=>e.default||e),m(e,...t)}))).then(()=>{clearTimeout(n),p.set(!1),delete v[e]}),v[e]}let O;const L=t.writable(null);function j(e,t){return 0===t.indexOf(e)&&e!==t}function k(e,t){return e===t||j(e,t)||j(t,e)}function M(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=h();return n&&!k(e,n)?n:null}function D(e){const t=e.split("-").map((e,t,n)=>n.slice(0,t+1).join("-")),{fallbackLocale:n}=h();return n&&!k(e,n)?t.concat(D(n)):t}function E(){return O}L.subscribe(e=>{O=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)});const F=L.set;L.set=e=>function e(t){return null==t||c(t)?t:e(M(t))}(e)&&y(e)?x(e).then(()=>F(e)):F(e),L.update=e=>F(e(O));const $={},P=(e,t)=>{if(null==t)return null;const n=u(t,e);return n||P(e,M(t))},S=(e,t)=>{if(t in $&&e in $[t])return $[t][e];const n=P(e,t);return n?((e,t,n)=>n?(t in $||($[t]={}),e in $[t]||($[t][e]=n),n):n)(e,t,n):null},T=(e,t)=>{const n=h().formats;if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},C=o((e={})=>{var{locale:t,format:n}=e,o=d(e,["locale","format"]);if(null==(t=t||E()))throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(o=T("number",n)),new Intl.NumberFormat(t,o)}),I=o((e={})=>{var{locale:t,format:n}=e,o=d(e,["locale","format"]);if(null==(t=t||E()))throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?o=T("date",n):0===Object.keys(o).length&&(o=T("date","short")),new Intl.DateTimeFormat(t,o)}),N=o((e={})=>{var{locale:t,format:n}=e,o=d(e,["locale","format"]);if(null==(t=t||E()))throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?o=T("time",n):0===Object.keys(o).length&&(o=T("time","short")),new Intl.DateTimeFormat(t,o)}),A=o((e,t=E())=>new n(e,t,h().formats)),U=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:o=E(),default:r}=t;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const a=S(e,o);return a?n?A(a,o).format(n):a:(h().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${D(o).join('", "')}".${y(E())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),r||e)};U.time=(e,t)=>N(t).format(e),U.date=(e,t)=>I(t).format(e),U.number=(e,t)=>C(t).format(e),U.capital=(e,t)=>U(e,t).replace(/(^|\s)\S/,e=>e.toLocaleUpperCase()),U.title=(e,t)=>U(e,t).replace(/(^|\s)\S/g,e=>e.toLocaleUpperCase()),U.upper=(e,t)=>U(e,t).toLocaleUpperCase(),U.lower=(e,t)=>U(e,t).toLocaleLowerCase();const q=t.derived([L,l],()=>U);exports._=q,exports.addMessages=m,exports.defineMessages=function(e){return e},exports.dictionary=l,exports.format=q,exports.getDateFormatter=I,exports.getMessageFormatter=A,exports.getNumberFormatter=C,exports.getTimeFormatter=N,exports.init=function(e){const{formats:t}=e,n=d(e,["formats"]),o=e.initialLocale?"string"==typeof e.initialLocale?e.initialLocale:(({navigator:e,hash:t,search:n,pathname:o,hostname:r})=>{let s;return"undefined"==typeof window?null:r&&(s=i(window.location.hostname,r),s)?s:o&&(s=i(window.location.pathname,o),s)?s:e&&(s=window.navigator.language||window.navigator.languages[0],s)?s:n&&(s=a(window.location.search.substr(1),n),s)?s:t&&(s=a(window.location.hash.substr(1),t),s)?s:null})(e.initialLocale)||e.fallbackLocale:e.fallbackLocale;return Object.assign(g,n,{initialLocale:o}),t&&("number"in t&&Object.assign(g.formats.number,t.number),"date"in t&&Object.assign(g.formats.date,t.date),"time"in t&&Object.assign(g.formats.time,t.time)),L.set(o)},exports.isLoading=p,exports.locale=L,exports.locales=f,exports.register=function(e,t){b(e)||function(e){w[e]=new Set}(e);const n=b(e);b(e).has(t)||(c(e)||l.update(t=>(t[e]={},t)),n.add(t))},exports.t=q,exports.waitLocale=function(e){return x(e||E()||h().initialLocale)};
***************************************************************************** */function p(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}const d={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function g(){return d}const b={};function h(e){return b[e]}function w(e){return M(e).reverse().some(h)}const y={};function O(e){if(!w(e))return;if(e in y)return y[e];const t=function(e){return M(e).reverse().map(e=>{const t=h(e);return[e,t?[...t]:[]]}).filter(([,e])=>e.length>0)}(e);if(0===t.length)return;const n=setTimeout(()=>f.set(!0),g().loadingDelay);return y[e]=Promise.all(t.map(([e,t])=>Promise.all(t.map(e=>e())).then(t=>{!function(e){delete b[e]}(e),t=t.map(e=>e.default||e),u(e,...t)}))).then(()=>{clearTimeout(n),f.set(!1),delete y[e]}),y[e]}let v;const x=t.writable(null);function j(e,t){return 0===t.indexOf(e)&&e!==t}function L(e,t){return e===t||j(e,t)||j(t,e)}function k(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=g();return n&&!L(e,n)?n:null}function M(e){const t=e.split("-").map((e,t,n)=>n.slice(0,t+1).join("-")),{fallbackLocale:n}=g();return n&&!L(e,n)?t.concat(M(n)):t}function D(){return v}x.subscribe(e=>{v=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)});const E=x.set;x.set=e=>function e(t){return null==t||l(t)?t:e(k(t))}(e)&&w(e)?O(e).then(()=>E(e)):E(e),x.update=e=>E(e(v));const F={},S=(e,t)=>{if(null==t)return null;const n=c(t,e);return n||S(e,k(t))},$=(e,t)=>{if(t in F&&e in F[t])return F[t][e];const n=S(e,t);return n?((e,t,n)=>n?(t in F||(F[t]={}),e in F[t]||(F[t][e]=n),n):n)(e,t,n):null},N=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},P=(e,t)=>{const n=g().formats;if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},T=N((e={})=>{var{locale:t,format:n}=e,r=p(e,["locale","format"]);if(null==(t=t||D()))throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(r=P("number",n)),new Intl.NumberFormat(t,r)}),C=N((e={})=>{var{locale:t,format:n}=e,r=p(e,["locale","format"]);if(null==(t=t||D()))throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?r=P("date",n):0===Object.keys(r).length&&(r=P("date","short")),new Intl.DateTimeFormat(t,r)}),I=N((e={})=>{var{locale:t,format:n}=e,r=p(e,["locale","format"]);if(null==(t=t||D()))throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?r=P("time",n):0===Object.keys(r).length&&(r=P("time","short")),new Intl.DateTimeFormat(t,r)}),A=N((e,t=D())=>new n(e,t,g().formats)),U=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=D(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const a=$(e,r);return a?n?A(a,r).format(n):a:(g().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${M(r).join('", "')}".${w(D())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),o||e)};U.time=(e,t)=>I(t).format(e),U.date=(e,t)=>C(t).format(e),U.number=(e,t)=>T(t).format(e),U.capital=(e,t)=>U(e,t).replace(/(^|\s)\S/,e=>e.toLocaleUpperCase()),U.title=(e,t)=>U(e,t).replace(/(^|\s)\S/g,e=>e.toLocaleUpperCase()),U.upper=(e,t)=>U(e,t).toLocaleUpperCase(),U.lower=(e,t)=>U(e,t).toLocaleLowerCase();const _=t.derived([x,s],()=>U);exports._=_,exports.addMessages=u,exports.defineMessages=function(e){return e},exports.dictionary=s,exports.format=_,exports.getDateFormatter=C,exports.getMessageFormatter=A,exports.getNumberFormatter=T,exports.getTimeFormatter=I,exports.init=function(e){const{formats:t}=e,n=p(e,["formats"]),r=e.initialLocale?"string"==typeof e.initialLocale?e.initialLocale:(({navigator:e,hash:t,search:n,pathname:r,hostname:i})=>{let s;return"undefined"==typeof window?null:i&&(s=a(window.location.hostname,i),s)?s:r&&(s=a(window.location.pathname,r),s)?s:e&&(s=window.navigator.language||window.navigator.languages[0],s)?s:n&&(s=o(window.location.search.substr(1),n),s)?s:t&&(s=o(window.location.hash.substr(1),t),s)?s:null})(e.initialLocale)||e.fallbackLocale:e.fallbackLocale;return Object.assign(d,n,{initialLocale:r}),t&&("number"in t&&Object.assign(d.formats.number,t.number),"date"in t&&Object.assign(d.formats.date,t.date),"time"in t&&Object.assign(d.formats.time,t.time)),x.set(r)},exports.isLoading=f,exports.locale=x,exports.locales=m,exports.register=function(e,t){h(e)||function(e){b[e]=new Set}(e);const n=h(e);h(e).has(t)||(l(e)||s.update(t=>(t[e]={},t)),n.add(t))},exports.t=_,exports.waitLocale=function(e){return O(e||D()||g().initialLocale)};

@@ -1,2 +0,2 @@

import{writable as e,derived as t}from"svelte/store";import n from"intl-messageformat";import o from"fast-memoize";const r=(e,t="")=>{const n={};for(const o in e){const a=t+o;"object"==typeof e[o]?Object.assign(n,r(e[o],`${a}.`)):n[a]=e[o]}return n},a=(e,t)=>{const n=e.split("&").find(e=>0===e.indexOf(`${t}=`));return n?n.split("=").pop():null},i=(e,t)=>{const n=t.exec(e);return n&&n[1]||null};let l;const s=e({});function c(e){return e in l}function u(e,t){if(c(e)){const n=function(e){return l[e]||null}(e);if(t in n)return n[t]}return null}function m(e,...t){const n=t.map(e=>r(e));s.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const f=t([s],([e])=>Object.keys(e));s.subscribe(e=>l=e);const d=e(!1);
import{writable as e,derived as t}from"svelte/store";import n from"intl-messageformat";const o=(e,t="")=>{const n={};for(const r in e){const a=t+r;"object"==typeof e[r]?Object.assign(n,o(e[r],`${a}.`)):n[a]=e[r]}return n},r=(e,t)=>{const n=e.split("&").find(e=>0===e.indexOf(`${t}=`));return n?n.split("=").pop():null},a=(e,t)=>{const n=t.exec(e);return n&&n[1]||null};let i;const l=e({});function s(e){return e in i}function c(e,t){if(s(e)){const n=function(e){return i[e]||null}(e);if(t in n)return n[t]}return null}function u(e,...t){const n=t.map(e=>o(e));l.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const m=t([l],([e])=>Object.keys(e));l.subscribe(e=>i=e);const f=e(!1);
/*! *****************************************************************************

@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation. All rights reserved.

and limitations under the License.
***************************************************************************** */function p(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}const g={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function h(){return g}function w(e){const{formats:t}=e,n=p(e,["formats"]),o=e.initialLocale?"string"==typeof e.initialLocale?e.initialLocale:(({navigator:e,hash:t,search:n,pathname:o,hostname:r})=>{let l;return"undefined"==typeof window?null:r&&(l=i(window.location.hostname,r),l)?l:o&&(l=i(window.location.pathname,o),l)?l:e&&(l=window.navigator.language||window.navigator.languages[0],l)?l:n&&(l=a(window.location.search.substr(1),n),l)?l:t&&(l=a(window.location.hash.substr(1),t),l)?l:null})(e.initialLocale)||e.fallbackLocale:e.fallbackLocale;return Object.assign(g,n,{initialLocale:o}),t&&("number"in t&&Object.assign(g.formats.number,t.number),"date"in t&&Object.assign(g.formats.date,t.date),"time"in t&&Object.assign(g.formats.time,t.time)),x.set(o)}const b={};function y(e){return b[e]}function O(e){return S(e).reverse().some(y)}const v={};function L(e){if(!O(e))return;if(e in v)return v[e];const t=function(e){return S(e).reverse().map(e=>{const t=y(e);return[e,t?[...t]:[]]}).filter(([,e])=>e.length>0)}(e);if(0===t.length)return;const n=setTimeout(()=>d.set(!0),h().loadingDelay);return v[e]=Promise.all(t.map(([e,t])=>Promise.all(t.map(e=>e())).then(t=>{!function(e){delete b[e]}(e),t=t.map(e=>e.default||e),m(e,...t)}))).then(()=>{clearTimeout(n),d.set(!1),delete v[e]}),v[e]}function j(e,t){y(e)||function(e){b[e]=new Set}(e);const n=y(e);y(e).has(t)||(c(e)||s.update(t=>(t[e]={},t)),n.add(t))}let k;const x=e(null);function E(e,t){return 0===t.indexOf(e)&&e!==t}function $(e,t){return e===t||E(e,t)||E(t,e)}function D(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=h();return n&&!$(e,n)?n:null}function S(e){const t=e.split("-").map((e,t,n)=>n.slice(0,t+1).join("-")),{fallbackLocale:n}=h();return n&&!$(e,n)?t.concat(S(n)):t}function C(){return k}x.subscribe(e=>{k=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)});const I=x.set;x.set=e=>function e(t){return null==t||c(t)?t:e(D(t))}(e)&&O(e)?L(e).then(()=>I(e)):I(e),x.update=e=>I(e(k));const P={},T=(e,t)=>{if(null==t)return null;const n=u(t,e);return n||T(e,D(t))},A=(e,t)=>{if(t in P&&e in P[t])return P[t][e];const n=T(e,t);return n?((e,t,n)=>n?(t in P||(P[t]={}),e in P[t]||(P[t][e]=n),n):n)(e,t,n):null},M=(e,t)=>{const n=h().formats;if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},N=o((e={})=>{var{locale:t,format:n}=e,o=p(e,["locale","format"]);if(null==(t=t||C()))throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(o=M("number",n)),new Intl.NumberFormat(t,o)}),U=o((e={})=>{var{locale:t,format:n}=e,o=p(e,["locale","format"]);if(null==(t=t||C()))throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?o=M("date",n):0===Object.keys(o).length&&(o=M("date","short")),new Intl.DateTimeFormat(t,o)}),F=o((e={})=>{var{locale:t,format:n}=e,o=p(e,["locale","format"]);if(null==(t=t||C()))throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?o=M("time",n):0===Object.keys(o).length&&(o=M("time","short")),new Intl.DateTimeFormat(t,o)}),Z=o((e,t=C())=>new n(e,t,h().formats)),z=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:o=C(),default:r}=t;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const a=A(e,o);return a?n?Z(a,o).format(n):a:(h().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${S(o).join('", "')}".${O(C())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),r||e)};z.time=(e,t)=>F(t).format(e),z.date=(e,t)=>U(t).format(e),z.number=(e,t)=>N(t).format(e),z.capital=(e,t)=>z(e,t).replace(/(^|\s)\S/,e=>e.toLocaleUpperCase()),z.title=(e,t)=>z(e,t).replace(/(^|\s)\S/g,e=>e.toLocaleUpperCase()),z.upper=(e,t)=>z(e,t).toLocaleUpperCase(),z.lower=(e,t)=>z(e,t).toLocaleLowerCase();const _=t([x,s],()=>z);function q(e){return e}function B(e){return L(e||C()||h().initialLocale)}export{_,m as addMessages,q as defineMessages,s as dictionary,_ as format,U as getDateFormatter,Z as getMessageFormatter,N as getNumberFormatter,F as getTimeFormatter,w as init,d as isLoading,x as locale,f as locales,j as register,_ as t,B as waitLocale};
***************************************************************************** */function d(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}const p={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function g(){return p}function h(e){const{formats:t}=e,n=d(e,["formats"]),o=e.initialLocale?"string"==typeof e.initialLocale?e.initialLocale:(({navigator:e,hash:t,search:n,pathname:o,hostname:i})=>{let l;return"undefined"==typeof window?null:i&&(l=a(window.location.hostname,i),l)?l:o&&(l=a(window.location.pathname,o),l)?l:e&&(l=window.navigator.language||window.navigator.languages[0],l)?l:n&&(l=r(window.location.search.substr(1),n),l)?l:t&&(l=r(window.location.hash.substr(1),t),l)?l:null})(e.initialLocale)||e.fallbackLocale:e.fallbackLocale;return Object.assign(p,n,{initialLocale:o}),t&&("number"in t&&Object.assign(p.formats.number,t.number),"date"in t&&Object.assign(p.formats.date,t.date),"time"in t&&Object.assign(p.formats.time,t.time)),k.set(o)}const w={};function b(e){return w[e]}function y(e){return $(e).reverse().some(b)}const O={};function v(e){if(!y(e))return;if(e in O)return O[e];const t=function(e){return $(e).reverse().map(e=>{const t=b(e);return[e,t?[...t]:[]]}).filter(([,e])=>e.length>0)}(e);if(0===t.length)return;const n=setTimeout(()=>f.set(!0),g().loadingDelay);return O[e]=Promise.all(t.map(([e,t])=>Promise.all(t.map(e=>e())).then(t=>{!function(e){delete w[e]}(e),t=t.map(e=>e.default||e),u(e,...t)}))).then(()=>{clearTimeout(n),f.set(!1),delete O[e]}),O[e]}function L(e,t){b(e)||function(e){w[e]=new Set}(e);const n=b(e);b(e).has(t)||(s(e)||l.update(t=>(t[e]={},t)),n.add(t))}let j;const k=e(null);function x(e,t){return 0===t.indexOf(e)&&e!==t}function E(e,t){return e===t||x(e,t)||x(t,e)}function S(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=g();return n&&!E(e,n)?n:null}function $(e){const t=e.split("-").map((e,t,n)=>n.slice(0,t+1).join("-")),{fallbackLocale:n}=g();return n&&!E(e,n)?t.concat($(n)):t}function D(){return j}k.subscribe(e=>{j=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)});const C=k.set;k.set=e=>function e(t){return null==t||s(t)?t:e(S(t))}(e)&&y(e)?v(e).then(()=>C(e)):C(e),k.update=e=>C(e(j));const I={},N=(e,t)=>{if(null==t)return null;const n=c(t,e);return n||N(e,S(t))},P=(e,t)=>{if(t in I&&e in I[t])return I[t][e];const n=N(e,t);return n?((e,t,n)=>n?(t in I||(I[t]={}),e in I[t]||(I[t][e]=n),n):n)(e,t,n):null},T=e=>{const t=Object.create(null);return n=>{const o=JSON.stringify(n);return o in t?t[o]:t[o]=e(n)}},A=(e,t)=>{const n=g().formats;if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},M=T((e={})=>{var{locale:t,format:n}=e,o=d(e,["locale","format"]);if(null==(t=t||D()))throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(o=A("number",n)),new Intl.NumberFormat(t,o)}),U=T((e={})=>{var{locale:t,format:n}=e,o=d(e,["locale","format"]);if(null==(t=t||D()))throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?o=A("date",n):0===Object.keys(o).length&&(o=A("date","short")),new Intl.DateTimeFormat(t,o)}),F=T((e={})=>{var{locale:t,format:n}=e,o=d(e,["locale","format"]);if(null==(t=t||D()))throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?o=A("time",n):0===Object.keys(o).length&&(o=A("time","short")),new Intl.DateTimeFormat(t,o)}),Z=T((e,t=D())=>new n(e,t,g().formats)),J=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:o=D(),default:r}=t;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const a=P(e,o);return a?n?Z(a,o).format(n):a:(g().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${$(o).join('", "')}".${y(D())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),r||e)};J.time=(e,t)=>F(t).format(e),J.date=(e,t)=>U(t).format(e),J.number=(e,t)=>M(t).format(e),J.capital=(e,t)=>J(e,t).replace(/(^|\s)\S/,e=>e.toLocaleUpperCase()),J.title=(e,t)=>J(e,t).replace(/(^|\s)\S/g,e=>e.toLocaleUpperCase()),J.upper=(e,t)=>J(e,t).toLocaleUpperCase(),J.lower=(e,t)=>J(e,t).toLocaleLowerCase();const _=t([k,l],()=>J);function q(e){return e}function z(e){return v(e||D()||g().initialLocale)}export{_,u as addMessages,q as defineMessages,l as dictionary,_ as format,U as getDateFormatter,Z as getMessageFormatter,M as getNumberFormatter,F as getTimeFormatter,h as init,f as isLoading,k as locale,m as locales,L as register,_ as t,z as waitLocale};
{
"name": "svelte-i18n",
"version": "2.2.3",
"version": "2.2.4",
"main": "dist/i18n.cjs.js",

@@ -83,3 +83,2 @@ "module": "dist/i18n.esm.js",

"estree-walker": "^0.9.0",
"fast-memoize": "^2.5.1",
"intl-messageformat": "^7.5.2",

@@ -86,0 +85,0 @@ "tiny-glob": "^0.2.6"

@@ -48,2 +48,2 @@ [![npm version](https://badge.fury.io/js/svelte-i18n.svg)](https://badge.fury.io/js/svelte-i18n) ![](https://github.com/kaisermann/svelte-i18n/workflows/CI/badge.svg)

### [Go see the documentation](https://github.com/kaisermann/svelte-i18n/wiki)
### [Go see the documentation](https://github.com/kaisermann/svelte-i18n/blob/master/docs)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc