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 3.3.4 to 3.3.5

types/runtime/runtime/configs.d.ts

9

CHANGELOG.md

@@ -0,1 +1,10 @@

## [3.3.5](https://github.com/kaisermann/svelte-i18n/compare/v3.3.4...v3.3.5) (2021-02-21)
### Bug Fixes
* 🐛 support deep properties keyed with dots ([c13ed35](https://github.com/kaisermann/svelte-i18n/commit/c13ed35e5d735ef9a8dd9390c7646d9f5eda55f2)), closes [#129](https://github.com/kaisermann/svelte-i18n/issues/129)
## [3.3.4](https://github.com/kaisermann/svelte-i18n/compare/v3.3.2...v3.3.4) (2021-02-15)

@@ -2,0 +11,0 @@

28

dist/cli.js

@@ -10,3 +10,2 @@ #!/usr/bin/env node

var estreeWalker = require('estree-walker');
var dlv = require('dlv');

@@ -38,3 +37,2 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var glob__default = /*#__PURE__*/_interopDefaultLegacy(glob);
var dlv__default = /*#__PURE__*/_interopDefaultLegacy(dlv);

@@ -106,2 +104,26 @@ /*! *****************************************************************************

function delve(obj, fullKey) {
if (fullKey in obj) {
return obj[fullKey];
}
const keys = fullKey.split('.');
let result = obj;
for (let p = 0; p < keys.length; p++) {
if (typeof result === 'object') {
if (p > 0) {
const partialKey = keys.slice(p, keys.length).join('.');
if (partialKey in result) {
result = result[partialKey];
break;
}
}
result = result[keys[p]];
}
else {
result = undefined;
}
}
return result;
}
const LIB_NAME = 'svelte-i18n';

@@ -230,3 +252,3 @@ const DEFINE_MESSAGES_METHOD_NAME = 'defineMessages';

if (overwrite === false &&
typeof dlv__default['default'](accumulator, messageObj.id) !== 'undefined') {
typeof delve(accumulator, messageObj.id) !== 'undefined') {
return;

@@ -233,0 +255,0 @@ }

4

dist/runtime.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("dlv"),r=require("intl-messageformat");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(t),a=o(n),l=o(r);let s;const u=e.writable({});function c(e){return e in s}function m(e,t){if(!c(e))return null;const n=function(e){return s[e]||null}(e);if(t in n)return n[t];return a.default(n,t)}function f(e){return null==e||c(e)?e:f(T(e))}function d(e,...t){u.update((n=>(n[e]=i.default.all([n[e]||{},...t]),n)))}const g=e.derived([u],(([e])=>Object.keys(e)));u.subscribe((e=>s=e));const p={};function w(e){return p[e]}function h(e){return D(e).reverse().some((e=>{var t;return null===(t=w(e))||void 0===t?void 0:t.size}))}function b(e,t){return Promise.all(t.map((t=>(function(e,t){p[e].delete(t),0===p[e].size&&delete p[e]}(e,t),t().then((e=>e.default||e)))))).then((t=>d(e,...t)))}const y={};function v(e){if(!h(e))return e in y?y[e]:void 0;const t=function(e){return D(e).reverse().map((e=>{const t=w(e);return[e,t?[...t]:[]]})).filter((([,e])=>e.length>0))}(e);return y[e]=Promise.all(t.map((([e,t])=>b(e,t)))).then((()=>{if(h(e))return v(e);delete y[e]})),y[e]}
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("svelte/store"),t=require("deepmerge"),n=require("intl-messageformat");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),i=r(n);let a;const l=e.writable({});function s(e){return e in a}function u(e,t){if(!s(e))return null;return function(e,t){if(t in e)return e[t];const n=t.split(".");let r=e;for(let e=0;e<n.length;e++)if("object"==typeof r){if(e>0){const t=n.slice(e,n.length).join(".");if(t in r){r=r[t];break}}r=r[n[e]]}else r=void 0;return r}(function(e){return a[e]||null}(e),t)}function c(e){return null==e||s(e)?e:c(M(e))}function m(e,...t){l.update((n=>(n[e]=o.default.all([n[e]||{},...t]),n)))}const f=e.derived([l],(([e])=>Object.keys(e)));l.subscribe((e=>a=e));const d={};function g(e){return d[e]}function p(e){return $(e).reverse().some((e=>{var t;return null===(t=g(e))||void 0===t?void 0:t.size}))}function w(e,t){return Promise.all(t.map((t=>(function(e,t){d[e].delete(t),0===d[e].size&&delete d[e]}(e,t),t().then((e=>e.default||e)))))).then((t=>m(e,...t)))}const h={};function b(e){if(!p(e))return e in h?h[e]:void 0;const t=function(e){return $(e).reverse().map((e=>{const t=g(e);return[e,t?[...t]:[]]})).filter((([,e])=>e.length>0))}(e);return h[e]=Promise.all(t.map((([e,t])=>w(e,t)))).then((()=>{if(p(e))return b(e);delete h[e]})),h[e]}
/*! *****************************************************************************

@@ -16,2 +16,2 @@ Copyright (c) Microsoft Corporation.

***************************************************************************** */
function x(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 O={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,ignoreTag:!0};function j(){return O}const L=e.writable(!1);let F;const M=e.writable(null);function $(e,t){return 0===t.indexOf(e)&&e!==t}function k(e,t){return e===t||$(e,t)||$(t,e)}function T(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=j();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}=j();return n&&!k(e,n)?t.concat(D(n)):t}function E(){return F}M.subscribe((e=>{F=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const N=M.set;M.set=e=>{if(f(e)&&h(e)){const{loadingDelay:t}=j();let n;return"undefined"!=typeof window&&null!=E()&&t?n=window.setTimeout((()=>L.set(!0)),t):L.set(!0),v(e).then((()=>{N(e)})).finally((()=>{clearTimeout(n),L.set(!1)}))}return N(e)},M.update=e=>N(e(F));const P=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(`${t}=`)));return n?n.split("=").pop():null},S=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},I={},q=(e,t)=>{if(null==t)return;const n=m(t,e);return n||q(e,T(t))},A=(e,t)=>{if(t in I&&e in I[t])return I[t][e];const n=q(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):void 0},_=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},z=(e,t)=>{const{formats:n}=j();if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},H=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(r=z("number",n)),new Intl.NumberFormat(t,r)})),Z=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?r=z("date",n):0===Object.keys(r).length&&(r=z("date","short")),new Intl.DateTimeFormat(t,r)})),C=_((e=>{var{locale:t,format:n}=e,r=x(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?r=z("time",n):0===Object.keys(r).length&&(r=z("time","short")),new Intl.DateTimeFormat(t,r)})),G=(e={})=>{var{locale:t=E()}=e,n=x(e,["locale"]);return H(Object.assign({locale:t},n))},J=(e={})=>{var{locale:t=E()}=e,n=x(e,["locale"]);return Z(Object.assign({locale:t},n))},Q=(e={})=>{var{locale:t=E()}=e,n=x(e,["locale"]);return C(Object.assign({locale:t},n))},U=_(((e,t=E())=>new l.default(e,t,j().formats,{ignoreTag:j().ignoreTag}))),B=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=E(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=A(e,r);if(i){if("string"!=typeof i)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof i}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),i}else j().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${D(r).join('", "')}".${h(E())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=o||e;if(!n)return i;let a=i;try{a=U(i,r).format(n)}catch(t){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return a},K=(e,t)=>Q(t).format(e),R=(e,t)=>J(t).format(e),V=(e,t)=>G(t).format(e),W=(e,t=E())=>A(e,t),X=e.derived([M,u],(()=>B)),Y=e.derived([M],(()=>K)),ee=e.derived([M],(()=>R)),te=e.derived([M],(()=>V)),ne=e.derived([M,u],(()=>W));exports._=X,exports.addMessages=d,exports.date=ee,exports.defineMessages=function(e){return e},exports.dictionary=u,exports.format=X,exports.getDateFormatter=J,exports.getLocaleFromHash=e=>"undefined"==typeof window?null:P(window.location.hash.substr(1),e),exports.getLocaleFromHostname=e=>"undefined"==typeof window?null:S(window.location.hostname,e),exports.getLocaleFromNavigator=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],exports.getLocaleFromPathname=e=>"undefined"==typeof window?null:S(window.location.pathname,e),exports.getLocaleFromQueryString=e=>"undefined"==typeof window?null:P(window.location.search.substr(1),e),exports.getMessageFormatter=U,exports.getNumberFormatter=G,exports.getTimeFormatter=Q,exports.init=function(e){const{formats:t}=e,n=x(e,["formats"]),r=e.initialLocale||e.fallbackLocale;return Object.assign(O,n,{initialLocale:r}),t&&("number"in t&&Object.assign(O.formats.number,t.number),"date"in t&&Object.assign(O.formats.date,t.date),"time"in t&&Object.assign(O.formats.time,t.time)),M.set(r)},exports.isLoading=L,exports.json=ne,exports.locale=M,exports.locales=g,exports.number=te,exports.register=function(e,t){w(e)||function(e){p[e]=new Set}(e);const n=w(e);w(e).has(t)||(c(e)||u.update((t=>(t[e]={},t))),n.add(t))},exports.t=X,exports.time=Y,exports.waitLocale=function(e){return v(e||E()||j().initialLocale)};
function y(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 v={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,ignoreTag:!0};function x(){return v}const O=e.writable(!1);let j;const L=e.writable(null);function F(e,t){return 0===t.indexOf(e)&&e!==t}function k(e,t){return e===t||F(e,t)||F(t,e)}function M(e){const t=e.lastIndexOf("-");if(t>0)return e.slice(0,t);const{fallbackLocale:n}=x();return n&&!k(e,n)?n:null}function $(e){const t=e.split("-").map(((e,t,n)=>n.slice(0,t+1).join("-"))),{fallbackLocale:n}=x();return n&&!k(e,n)?t.concat($(n)):t}function T(){return j}L.subscribe((e=>{j=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const D=L.set;L.set=e=>{if(c(e)&&p(e)){const{loadingDelay:t}=x();let n;return"undefined"!=typeof window&&null!=T()&&t?n=window.setTimeout((()=>O.set(!0)),t):O.set(!0),b(e).then((()=>{D(e)})).finally((()=>{clearTimeout(n),O.set(!1)}))}return D(e)},L.update=e=>D(e(j));const E=(e,t)=>{const n=e.split("&").find((e=>0===e.indexOf(`${t}=`)));return n?n.split("=").pop():null},N=(e,t)=>{const n=t.exec(e);return n&&n[1]||null},P={},S=(e,t)=>{if(null==t)return;const n=u(t,e);return n||S(e,M(t))},I=(e,t)=>{if(t in P&&e in P[t])return P[t][e];const n=S(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):void 0},A=e=>{const t=Object.create(null);return n=>{const r=JSON.stringify(n);return r in t?t[r]:t[r]=e(n)}},q=(e,t)=>{const{formats:n}=x();if(e in n&&t in n[e])return n[e][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${e} format.`)},_=A((e=>{var{locale:t,format:n}=e,r=y(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return n&&(r=q("number",n)),new Intl.NumberFormat(t,r)})),z=A((e=>{var{locale:t,format:n}=e,r=y(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return n?r=q("date",n):0===Object.keys(r).length&&(r=q("date","short")),new Intl.DateTimeFormat(t,r)})),H=A((e=>{var{locale:t,format:n}=e,r=y(e,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return n?r=q("time",n):0===Object.keys(r).length&&(r=q("time","short")),new Intl.DateTimeFormat(t,r)})),Z=(e={})=>{var{locale:t=T()}=e,n=y(e,["locale"]);return _(Object.assign({locale:t},n))},C=(e={})=>{var{locale:t=T()}=e,n=y(e,["locale"]);return z(Object.assign({locale:t},n))},G=(e={})=>{var{locale:t=T()}=e,n=y(e,["locale"]);return H(Object.assign({locale:t},n))},J=A(((e,t=T())=>new i.default(e,t,x().formats,{ignoreTag:x().ignoreTag}))),Q=(e,t={})=>{"object"==typeof e&&(e=(t=e).id);const{values:n,locale:r=T(),default:o}=t;if(null==r)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=I(e,r);if(i){if("string"!=typeof i)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof i}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),i}else x().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${$(r).join('", "')}".${p(T())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=o||e;if(!n)return i;let a=i;try{a=J(i,r).format(n)}catch(t){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,t.message)}return a},U=(e,t)=>G(t).format(e),B=(e,t)=>C(t).format(e),K=(e,t)=>Z(t).format(e),R=(e,t=T())=>I(e,t),V=e.derived([L,l],(()=>Q)),W=e.derived([L],(()=>U)),X=e.derived([L],(()=>B)),Y=e.derived([L],(()=>K)),ee=e.derived([L,l],(()=>R));exports._=V,exports.addMessages=m,exports.date=X,exports.defineMessages=function(e){return e},exports.dictionary=l,exports.format=V,exports.getDateFormatter=C,exports.getLocaleFromHash=e=>"undefined"==typeof window?null:E(window.location.hash.substr(1),e),exports.getLocaleFromHostname=e=>"undefined"==typeof window?null:N(window.location.hostname,e),exports.getLocaleFromNavigator=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],exports.getLocaleFromPathname=e=>"undefined"==typeof window?null:N(window.location.pathname,e),exports.getLocaleFromQueryString=e=>"undefined"==typeof window?null:E(window.location.search.substr(1),e),exports.getMessageFormatter=J,exports.getNumberFormatter=Z,exports.getTimeFormatter=G,exports.init=function(e){const{formats:t}=e,n=y(e,["formats"]),r=e.initialLocale||e.fallbackLocale;return Object.assign(v,n,{initialLocale:r}),t&&("number"in t&&Object.assign(v.formats.number,t.number),"date"in t&&Object.assign(v.formats.date,t.date),"time"in t&&Object.assign(v.formats.time,t.time)),L.set(r)},exports.isLoading=O,exports.json=ee,exports.locale=L,exports.locales=f,exports.number=Y,exports.register=function(e,t){g(e)||function(e){d[e]=new Set}(e);const n=g(e);g(e).has(t)||(s(e)||l.update((t=>(t[e]={},t))),n.add(t))},exports.t=V,exports.time=W,exports.waitLocale=function(e){return b(e||T()||x().initialLocale)};

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

import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"dlv";import r from"intl-messageformat";let i;const a=e({});function l(e){return e in i}function s(e,n){if(!l(e))return null;const t=function(e){return i[e]||null}(e);if(n in t)return t[n];return o(t,n)}function u(e){return null==e||l(e)?e:u(E(e))}function c(e,...n){a.update((o=>(o[e]=t.all([o[e]||{},...n]),o)))}const m=n([a],(([e])=>Object.keys(e)));a.subscribe((e=>i=e));const f={};function d(e){return f[e]}function g(e){return D(e).reverse().some((e=>{var n;return null===(n=d(e))||void 0===n?void 0:n.size}))}function w(e,n){return Promise.all(n.map((n=>(function(e,n){f[e].delete(n),0===f[e].size&&delete f[e]}(e,n),n().then((e=>e.default||e)))))).then((n=>c(e,...n)))}const h={};function p(e){if(!g(e))return e in h?h[e]:void 0;const n=function(e){return D(e).reverse().map((e=>{const n=d(e);return[e,n?[...n]:[]]})).filter((([,e])=>e.length>0))}(e);return h[e]=Promise.all(n.map((([e,n])=>w(e,n)))).then((()=>{if(g(e))return p(e);delete h[e]})),h[e]}function b(e,n){d(e)||function(e){f[e]=new Set}(e);const t=d(e);d(e).has(n)||(l(e)||a.update((n=>(n[e]={},n))),t.add(n))}
import{writable as e,derived as n}from"svelte/store";import t from"deepmerge";import o from"intl-messageformat";let r;const i=e({});function a(e){return e in r}function l(e,n){if(!a(e))return null;return function(e,n){if(n in e)return e[n];const t=n.split(".");let o=e;for(let e=0;e<t.length;e++)if("object"==typeof o){if(e>0){const n=t.slice(e,t.length).join(".");if(n in o){o=o[n];break}}o=o[t[e]]}else o=void 0;return o}(function(e){return r[e]||null}(e),n)}function s(e){return null==e||a(e)?e:s(T(e))}function u(e,...n){i.update((o=>(o[e]=t.all([o[e]||{},...n]),o)))}const c=n([i],(([e])=>Object.keys(e)));i.subscribe((e=>r=e));const m={};function f(e){return m[e]}function d(e){return E(e).reverse().some((e=>{var n;return null===(n=f(e))||void 0===n?void 0:n.size}))}function g(e,n){return Promise.all(n.map((n=>(function(e,n){m[e].delete(n),0===m[e].size&&delete m[e]}(e,n),n().then((e=>e.default||e)))))).then((n=>u(e,...n)))}const w={};function h(e){if(!d(e))return e in w?w[e]:void 0;const n=function(e){return E(e).reverse().map((e=>{const n=f(e);return[e,n?[...n]:[]]})).filter((([,e])=>e.length>0))}(e);return w[e]=Promise.all(n.map((([e,n])=>g(e,n)))).then((()=>{if(d(e))return h(e);delete w[e]})),w[e]}function p(e,n){f(e)||function(e){m[e]=new Set}(e);const t=f(e);f(e).has(n)||(a(e)||i.update((n=>(n[e]={},n))),t.add(n))}
/*! *****************************************************************************

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

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function y(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}const v={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,ignoreTag:!0};function O(){return v}function j(e){const{formats:n}=e,t=y(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(v,t,{initialLocale:o}),n&&("number"in n&&Object.assign(v.formats.number,n.number),"date"in n&&Object.assign(v.formats.date,n.date),"time"in n&&Object.assign(v.formats.time,n.time)),k.set(o)}const L=e(!1);let $;const k=e(null);function x(e,n){return 0===n.indexOf(e)&&e!==n}function T(e,n){return e===n||x(e,n)||x(n,e)}function E(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=O();return t&&!T(e,t)?t:null}function D(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=O();return t&&!T(e,t)?n.concat(D(t)):n}function M(){return $}k.subscribe((e=>{$=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const I=k.set;k.set=e=>{if(u(e)&&g(e)){const{loadingDelay:n}=O();let t;return"undefined"!=typeof window&&null!=M()&&n?t=window.setTimeout((()=>L.set(!0)),n):L.set(!0),p(e).then((()=>{I(e)})).finally((()=>{clearTimeout(t),L.set(!1)}))}return I(e)},k.update=e=>I(e($));const N=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(`${n}=`)));return t?t.split("=").pop():null},P=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},S=e=>"undefined"==typeof window?null:P(window.location.hostname,e),A=e=>"undefined"==typeof window?null:P(window.location.pathname,e),F=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],z=e=>"undefined"==typeof window?null:N(window.location.search.substr(1),e),Z=e=>"undefined"==typeof window?null:N(window.location.hash.substr(1),e),C={},G=(e,n)=>{if(null==n)return;const t=s(n,e);return t||G(e,E(n))},J=(e,n)=>{if(n in C&&e in C[n])return C[n][e];const t=G(e,n);return t?((e,n,t)=>t?(n in C||(C[n]={}),e in C[n]||(C[n][e]=t),t):t)(e,n,t):void 0},U=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},_=(e,n)=>{const{formats:t}=O();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},q=U((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=_("number",t)),new Intl.NumberFormat(n,o)})),B=U((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=_("date",t):0===Object.keys(o).length&&(o=_("date","short")),new Intl.DateTimeFormat(n,o)})),H=U((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=_("time",t):0===Object.keys(o).length&&(o=_("time","short")),new Intl.DateTimeFormat(n,o)})),K=(e={})=>{var{locale:n=M()}=e,t=y(e,["locale"]);return q(Object.assign({locale:n},t))},Q=(e={})=>{var{locale:n=M()}=e,t=y(e,["locale"]);return B(Object.assign({locale:n},t))},R=(e={})=>{var{locale:n=M()}=e,t=y(e,["locale"]);return H(Object.assign({locale:n},t))},V=U(((e,n=M())=>new r(e,n,O().formats,{ignoreTag:O().ignoreTag}))),W=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=M(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=J(e,o);if(i){if("string"!=typeof i)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof i}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),i}else O().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${D(o).join('", "')}".${g(M())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e;if(!t)return i;let a=i;try{a=V(i,o).format(t)}catch(n){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,n.message)}return a},X=(e,n)=>R(n).format(e),Y=(e,n)=>Q(n).format(e),ee=(e,n)=>K(n).format(e),ne=(e,n=M())=>J(e,n),te=n([k,a],(()=>W)),oe=n([k],(()=>X)),re=n([k],(()=>Y)),ie=n([k],(()=>ee)),ae=n([k,a],(()=>ne));function le(e){return e}function se(e){return p(e||M()||O().initialLocale)}export{te as _,c as addMessages,re as date,le as defineMessages,a as dictionary,te as format,Q as getDateFormatter,Z as getLocaleFromHash,S as getLocaleFromHostname,F as getLocaleFromNavigator,A as getLocaleFromPathname,z as getLocaleFromQueryString,V as getMessageFormatter,K as getNumberFormatter,R as getTimeFormatter,j as init,L as isLoading,ae as json,k as locale,m as locales,ie as number,b as register,te as t,oe as time,se as waitLocale};
***************************************************************************** */function b(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}const y={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,ignoreTag:!0};function v(){return y}function O(e){const{formats:n}=e,t=b(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(y,t,{initialLocale:o}),n&&("number"in n&&Object.assign(y.formats.number,n.number),"date"in n&&Object.assign(y.formats.date,n.date),"time"in n&&Object.assign(y.formats.time,n.time)),L.set(o)}const j=e(!1);let k;const L=e(null);function $(e,n){return 0===n.indexOf(e)&&e!==n}function x(e,n){return e===n||$(e,n)||$(n,e)}function T(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=v();return t&&!x(e,t)?t:null}function E(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=v();return t&&!x(e,t)?n.concat(E(t)):n}function D(){return k}L.subscribe((e=>{k=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const M=L.set;L.set=e=>{if(s(e)&&d(e)){const{loadingDelay:n}=v();let t;return"undefined"!=typeof window&&null!=D()&&n?t=window.setTimeout((()=>j.set(!0)),n):j.set(!0),h(e).then((()=>{M(e)})).finally((()=>{clearTimeout(t),j.set(!1)}))}return M(e)},L.update=e=>M(e(k));const I=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(`${n}=`)));return t?t.split("=").pop():null},N=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},P=e=>"undefined"==typeof window?null:N(window.location.hostname,e),S=e=>"undefined"==typeof window?null:N(window.location.pathname,e),A=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],F=e=>"undefined"==typeof window?null:I(window.location.search.substr(1),e),z=e=>"undefined"==typeof window?null:I(window.location.hash.substr(1),e),Z={},C=(e,n)=>{if(null==n)return;const t=l(n,e);return t||C(e,T(n))},G=(e,n)=>{if(n in Z&&e in Z[n])return Z[n][e];const t=C(e,n);return t?((e,n,t)=>t?(n in Z||(Z[n]={}),e in Z[n]||(Z[n][e]=t),t):t)(e,n,t):void 0},J=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},U=(e,n)=>{const{formats:t}=v();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},_=J((e=>{var{locale:n,format:t}=e,o=b(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=U("number",t)),new Intl.NumberFormat(n,o)})),q=J((e=>{var{locale:n,format:t}=e,o=b(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=U("date",t):0===Object.keys(o).length&&(o=U("date","short")),new Intl.DateTimeFormat(n,o)})),B=J((e=>{var{locale:n,format:t}=e,o=b(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=U("time",t):0===Object.keys(o).length&&(o=U("time","short")),new Intl.DateTimeFormat(n,o)})),H=(e={})=>{var{locale:n=D()}=e,t=b(e,["locale"]);return _(Object.assign({locale:n},t))},K=(e={})=>{var{locale:n=D()}=e,t=b(e,["locale"]);return q(Object.assign({locale:n},t))},Q=(e={})=>{var{locale:n=D()}=e,t=b(e,["locale"]);return B(Object.assign({locale:n},t))},R=J(((e,n=D())=>new o(e,n,v().formats,{ignoreTag:v().ignoreTag}))),V=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=D(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=G(e,o);if(i){if("string"!=typeof i)return console.warn(`[svelte-i18n] Message with id "${e}" must be of type "string", found: "${typeof i}". Gettin its value through the "$format" method is deprecated; use the "json" method instead.`),i}else v().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${E(o).join('", "')}".${d(D())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e;if(!t)return i;let a=i;try{a=R(i,o).format(t)}catch(n){console.warn(`[svelte-i18n] Message "${e}" has syntax error:`,n.message)}return a},W=(e,n)=>Q(n).format(e),X=(e,n)=>K(n).format(e),Y=(e,n)=>H(n).format(e),ee=(e,n=D())=>G(e,n),ne=n([L,i],(()=>V)),te=n([L],(()=>W)),oe=n([L],(()=>X)),re=n([L],(()=>Y)),ie=n([L,i],(()=>ee));function ae(e){return e}function le(e){return h(e||D()||v().initialLocale)}export{ne as _,u as addMessages,oe as date,ae as defineMessages,i as dictionary,ne as format,K as getDateFormatter,z as getLocaleFromHash,P as getLocaleFromHostname,A as getLocaleFromNavigator,S as getLocaleFromPathname,F as getLocaleFromQueryString,R as getMessageFormatter,H as getNumberFormatter,Q as getTimeFormatter,O as init,j as isLoading,ie as json,L as locale,c as locales,re as number,p as register,ne as t,te as time,le as waitLocale};
{
"name": "svelte-i18n",
"version": "3.3.4",
"version": "3.3.5",
"main": "dist/runtime.cjs.js",

@@ -105,3 +105,2 @@ "module": "dist/runtime.esm.js",

"deepmerge": "^4.2.2",
"dlv": "^1.1.3",
"estree-walker": "^2.0.1",

@@ -108,0 +107,0 @@ "intl-messageformat": "^9.3.15",

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