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.0.0-alpha.1 to 3.0.0

23

CHANGELOG.md

@@ -1,14 +0,9 @@

# [3.0.0-alpha.1](https://github.com/kaisermann/svelte-i18n/compare/v2.3.0...v3.0.0-alpha.1) (2020-01-30)
# [3.0.0](https://github.com/kaisermann/svelte-i18n/compare/v2.3.1...v3.0.0) (2020-02-03)
### Bug Fixes
* 🐛 types from v3 branch leaking to master branch :shrug: ([88f7762](https://github.com/kaisermann/svelte-i18n/commit/88f7762e96c4eae963722bdedf601afbce4b2f17))
### Features
* 🎸 add runtime typings ([d59105b](https://github.com/kaisermann/svelte-i18n/commit/d59105b1fb30f8adaa80bf43b865a6bb6bad2fa1)), closes [#43](https://github.com/kaisermann/svelte-i18n/issues/43)
* 🎸 make date,time and number formatters tree-shakeable ([c9c7448](https://github.com/kaisermann/svelte-i18n/commit/c9c74480c38bc504713083d920d31070813b1cd8))
* 🎸 make getClientLocale tree-shakeable ([6d557a9](https://github.com/kaisermann/svelte-i18n/commit/6d557a98fc2a8632ca629968b46f50ab0b3a04fb))
* 🎸 add runtime typings ([90bf171](https://github.com/kaisermann/svelte-i18n/commit/90bf171139ad6b55faa0e36b3d28d317de538985)), closes [#43](https://github.com/kaisermann/svelte-i18n/issues/43)
* 🎸 make date,time and number formatters tree-shakeable ([fb82a40](https://github.com/kaisermann/svelte-i18n/commit/fb82a400f349d8d997c1d14f8d16b1d5c8da7f3e))
* 🎸 make getClientLocale tree-shakeable ([4881acb](https://github.com/kaisermann/svelte-i18n/commit/4881acb7b3a9aacd64b0f00f3b85fd736aa53316))

@@ -36,2 +31,12 @@

## [2.3.1](https://github.com/kaisermann/svelte-i18n/compare/v2.3.0...v2.3.1) (2020-01-29)
### Bug Fixes
* 🐛 types from v3 branch leaking to master branch :shrug: ([88f7762](https://github.com/kaisermann/svelte-i18n/commit/88f7762e96c4eae963722bdedf601afbce4b2f17))
* memoizing of formatters when no locale is given. ([#47](https://github.com/kaisermann/svelte-i18n/issues/47)) ([27871f9](https://github.com/kaisermann/svelte-i18n/commit/27871f9775a96e0a2627a143635d4f4750b9f945))
# [2.3.0](https://github.com/kaisermann/svelte-i18n/compare/v2.2.4...v2.3.0) (2020-01-23)

@@ -38,0 +43,0 @@

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

"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 i=t+o;"object"==typeof e[o]?Object.assign(n,r(e[o],`${i}.`)):n[i]=e[o]}return n};let o;const i=t.writable({});function a(e){return e in o}function s(e,t){if(a(e)){const n=function(e){return o[e]||null}(e);if(t in n)return n[t]}return null}function l(e,...t){const n=t.map(e=>r(e));i.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const c=t.derived([i],([e])=>Object.keys(e));i.subscribe(e=>o=e);const u=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};let o;const a=t.writable({});function i(e){return e in o}function s(e,t){if(i(e)){const n=function(e){return o[e]||null}(e);if(t in n)return n[t]}return null}function l(e,...t){const n=t.map(e=>r(e));a.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const c=t.derived([a],([e])=>Object.keys(e));a.subscribe(e=>o=e);const u=t.writable(!1);
/*! *****************************************************************************

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

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

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

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

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

and limitations under the License.
***************************************************************************** */function m(n,t){var e={};for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&t.indexOf(o)<0&&(e[o]=n[o]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(n);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(n,o[r])&&(e[o[r]]=n[o[r]])}return e}const f={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 d(){return f}function h(n){const{formats:t}=n,e=m(n,["formats"]),o=n.initialLocale||n.fallbackLocale;return Object.assign(f,e,{initialLocale:o}),t&&("number"in t&&Object.assign(f.formats.number,t.number),"date"in t&&Object.assign(f.formats.date,t.date),"time"in t&&Object.assign(f.formats.time,t.time)),j.set(o)}const g={};function w(n){return g[n]}function b(n){return E(n).reverse().some(w)}const p={};function y(n){if(!b(n))return;if(n in p)return p[n];const t=function(n){return E(n).reverse().map(n=>{const t=w(n);return[n,t?[...t]:[]]}).filter(([,n])=>n.length>0)}(n);if(0===t.length)return;const e=setTimeout(()=>u.set(!0),d().loadingDelay);return p[n]=Promise.all(t.map(([n,t])=>Promise.all(t.map(n=>n())).then(t=>{!function(n){delete g[n]}(n),t=t.map(n=>n.default||n),l(n,...t)}))).then(()=>{clearTimeout(e),u.set(!1),delete p[n]}),p[n]}function O(n,t){w(n)||function(n){g[n]=new Set}(n);const e=w(n);w(n).has(t)||(a(n)||i.update(t=>(t[n]={},t)),e.add(t))}let v;const j=n(null);function L(n,t){return 0===t.indexOf(n)&&n!==t}function k(n,t){return n===t||L(n,t)||L(t,n)}function x(n){const t=n.lastIndexOf("-");if(t>0)return n.slice(0,t);const{fallbackLocale:e}=d();return e&&!k(n,e)?e:null}function E(n){const t=n.split("-").map((n,t,e)=>e.slice(0,t+1).join("-")),{fallbackLocale:e}=d();return e&&!k(n,e)?t.concat(E(e)):t}function $(){return v}j.subscribe(n=>{v=n,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",n)});const D=j.set;j.set=n=>function n(t){return null==t||a(t)?t:n(x(t))}(n)&&b(n)?y(n).then(()=>D(n)):D(n),j.update=n=>D(n(v));const I=(n,t)=>{const e=n.split("&").find(n=>0===n.indexOf(`${t}=`));return e?e.split("=").pop():null},N=(n,t)=>{const e=t.exec(n);return e&&e[1]||null},P=({navigator:n,hash:t,search:e,pathname:o,hostname:r})=>{let i;return"undefined"==typeof window?null:r&&(i=N(window.location.hostname,r),i)?i:o&&(i=N(window.location.pathname,o),i)?i:n&&(i=window.navigator.language||window.navigator.languages[0],i)?i:e&&(i=I(window.location.search.substr(1),e),i)?i:t&&(i=I(window.location.hash.substr(1),t),i)?i:null},S={},T=(n,t)=>{if(null==t)return null;const e=s(t,n);return e||T(n,x(t))},A=(n,t)=>{if(t in S&&n in S[t])return S[t][n];const e=T(n,t);return e?((n,t,e)=>e?(t in S||(S[t]={}),n in S[t]||(S[t][n]=e),e):e)(n,t,e):null},M=n=>{const t=Object.create(null);return e=>{const o=JSON.stringify(e);return o in t?t[o]:t[o]=n(e)}},F=(n,t)=>{const e=d().formats;if(n in e&&t in e[n])return e[n][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${n} format.`)},Z=M((n={})=>{var{locale:t,format:e}=n,o=m(n,["locale","format"]);if(null==(t=t||$()))throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return e&&(o=F("number",e)),new Intl.NumberFormat(t,o)}),C=M((n={})=>{var{locale:t,format:e}=n,o=m(n,["locale","format"]);if(null==(t=t||$()))throw new Error('[svelte-i18n] A "locale" must be set to format dates');return e?o=F("date",e):0===Object.keys(o).length&&(o=F("date","short")),new Intl.DateTimeFormat(t,o)}),J=M((n={})=>{var{locale:t,format:e}=n,o=m(n,["locale","format"]);if(null==(t=t||$()))throw new Error('[svelte-i18n] A "locale" must be set to format time values');return e?o=F("time",e):0===Object.keys(o).length&&(o=F("time","short")),new Intl.DateTimeFormat(t,o)}),U=M((n,t=$())=>new e(n,t,d().formats)),_=(n,t={})=>{"object"==typeof n&&(n=(t=n).id);const{values:e,locale:o=$(),default:r}=t;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const i=A(n,o);return i?e?U(i,o).format(e):i:(d().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${n}" was not found in "${E(o).join('", "')}".${b($())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),r||n)},q=(n,t)=>J(t).format(n),z=(n,t)=>C(t).format(n),B=(n,t)=>Z(t).format(n),G=t([j,i],()=>_),H=t([j],()=>q),K=t([j],()=>z),Q=t([j],()=>B);function R(n){return n}function V(n){return y(n||$()||d().initialLocale)}export{G as _,l as addMessages,K as date,R as defineMessages,i as dictionary,G as format,P as getClientLocale,C as getDateFormatter,U as getMessageFormatter,Z as getNumberFormatter,J as getTimeFormatter,h as init,u as isLoading,j as locale,c as locales,Q as number,O as register,G as t,H as time,V as waitLocale};
***************************************************************************** */function m(n,t){var e={};for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&t.indexOf(o)<0&&(e[o]=n[o]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(n);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(n,o[r])&&(e[o[r]]=n[o[r]])}return e}const f={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 d(){return f}function g(n){const{formats:t}=n,e=m(n,["formats"]),o=n.initialLocale||n.fallbackLocale;return Object.assign(f,e,{initialLocale:o}),t&&("number"in t&&Object.assign(f.formats.number,t.number),"date"in t&&Object.assign(f.formats.date,t.date),"time"in t&&Object.assign(f.formats.time,t.time)),j.set(o)}const h={};function b(n){return h[n]}function w(n){return E(n).reverse().some(b)}const p={};function y(n){if(!w(n))return;if(n in p)return p[n];const t=function(n){return E(n).reverse().map(n=>{const t=b(n);return[n,t?[...t]:[]]}).filter(([,n])=>n.length>0)}(n);if(0===t.length)return;const e=setTimeout(()=>u.set(!0),d().loadingDelay);return p[n]=Promise.all(t.map(([n,t])=>Promise.all(t.map(n=>n())).then(t=>{!function(n){delete h[n]}(n),t=t.map(n=>n.default||n),s(n,...t)}))).then(()=>{clearTimeout(e),u.set(!1),delete p[n]}),p[n]}function O(n,t){b(n)||function(n){h[n]=new Set}(n);const e=b(n);b(n).has(t)||(i(n)||a.update(t=>(t[n]={},t)),e.add(t))}let v;const j=n(null);function L(n,t){return 0===t.indexOf(n)&&n!==t}function k(n,t){return n===t||L(n,t)||L(t,n)}function x(n){const t=n.lastIndexOf("-");if(t>0)return n.slice(0,t);const{fallbackLocale:e}=d();return e&&!k(n,e)?e:null}function E(n){const t=n.split("-").map((n,t,e)=>e.slice(0,t+1).join("-")),{fallbackLocale:e}=d();return e&&!k(n,e)?t.concat(E(e)):t}function $(){return v}j.subscribe(n=>{v=n,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",n)});const D=j.set;j.set=n=>function n(t){return null==t||i(t)?t:n(x(t))}(n)&&w(n)?y(n).then(()=>D(n)):D(n),j.update=n=>D(n(v));const I=(n,t)=>{const e=n.split("&").find(n=>0===n.indexOf(`${t}=`));return e?e.split("=").pop():null},N=(n,t)=>{const e=t.exec(n);return e&&e[1]||null},P=({navigator:n,hash:t,search:e,pathname:o,hostname:r})=>{let a;return"undefined"==typeof window?null:r&&(a=N(window.location.hostname,r),a)?a:o&&(a=N(window.location.pathname,o),a)?a:n&&(a=window.navigator.language||window.navigator.languages[0],a)?a:e&&(a=I(window.location.search.substr(1),e),a)?a:t&&(a=I(window.location.hash.substr(1),t),a)?a:null},S={},T=(n,t)=>{if(null==t)return null;const e=l(t,n);return e||T(n,x(t))},A=(n,t)=>{if(t in S&&n in S[t])return S[t][n];const e=T(n,t);return e?((n,t,e)=>e?(t in S||(S[t]={}),n in S[t]||(S[t][n]=e),e):e)(n,t,e):null},M=n=>{const t=Object.create(null);return e=>{const o=JSON.stringify(e);return o in t?t[o]:t[o]=n(e)}},F=(n,t)=>{const e=d().formats;if(n in e&&t in e[n])return e[n][t];throw new Error(`[svelte-i18n] Unknown "${t}" ${n} format.`)},Z=M(n=>{var{locale:t,format:e}=n,o=m(n,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return e&&(o=F("number",e)),new Intl.NumberFormat(t,o)}),C=M(n=>{var{locale:t,format:e}=n,o=m(n,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return e?o=F("date",e):0===Object.keys(o).length&&(o=F("date","short")),new Intl.DateTimeFormat(t,o)}),J=M(n=>{var{locale:t,format:e}=n,o=m(n,["locale","format"]);if(null==t)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return e?o=F("time",e):0===Object.keys(o).length&&(o=F("time","short")),new Intl.DateTimeFormat(t,o)}),U=(n={})=>{var{locale:t=$()}=n,e=m(n,["locale"]);return Z(Object.assign({locale:t},e))},_=(n={})=>{var{locale:t=$()}=n,e=m(n,["locale"]);return C(Object.assign({locale:t},e))},q=(n={})=>{var{locale:t=$()}=n,e=m(n,["locale"]);return J(Object.assign({locale:t},e))},z=M((n,t=$())=>new e(n,t,d().formats)),B=(n,t={})=>{"object"==typeof n&&(n=(t=n).id);const{values:e,locale:o=$(),default:r}=t;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const a=A(n,o);return a?e?z(a,o).format(e):a:(d().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${n}" was not found in "${E(o).join('", "')}".${w($())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),r||n)},G=(n,t)=>q(t).format(n),H=(n,t)=>_(t).format(n),K=(n,t)=>U(t).format(n),Q=t([j,a],()=>B),R=t([j],()=>G),V=t([j],()=>H),W=t([j],()=>K);function X(n){return n}function Y(n){return y(n||$()||d().initialLocale)}export{Q as _,s as addMessages,V as date,X as defineMessages,a as dictionary,Q as format,P as getClientLocale,_ as getDateFormatter,z as getMessageFormatter,U as getNumberFormatter,q as getTimeFormatter,g as init,u as isLoading,j as locale,c as locales,W as number,O as register,Q as t,R as time,Y as waitLocale};
{
"name": "svelte-i18n",
"version": "3.0.0-alpha.1",
"version": "3.0.0",
"main": "dist/runtime.cjs.js",

@@ -46,2 +46,16 @@ "module": "dist/runtime.esm.js",

],
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{ts,js}": [
"eslint --fix",
"prettier --write"
],
"*.json": [
"prettier --write"
]
},
"jest": {

@@ -73,3 +87,5 @@ "collectCoverage": true,

"eslint-config-kaisermann": "0.0.3",
"husky": "^4.2.1",
"jest": "^24.9.0",
"lint-staged": "^10.0.4",
"npm-run-all": "^4.1.5",

@@ -76,0 +92,0 @@ "prettier": "^1.19.1",

import IntlMessageFormat from 'intl-messageformat';
import { MemoizedIntlFormatter } from '../types';
export declare const getNumberFormatter: MemoizedIntlFormatter<Intl.NumberFormat, Intl.NumberFormatOptions>;
export declare const getDateFormatter: MemoizedIntlFormatter<Intl.DateTimeFormat, Intl.DateTimeFormatOptions>;
export declare const getTimeFormatter: MemoizedIntlFormatter<Intl.DateTimeFormat, Intl.DateTimeFormatOptions>;
declare type MemoizedNumberFormatterFactory = MemoizedIntlFormatter<Intl.NumberFormat, Intl.NumberFormatOptions>;
declare type MemoizedDateTimeFormatterFactory = MemoizedIntlFormatter<Intl.DateTimeFormat, Intl.DateTimeFormatOptions>;
export declare const getNumberFormatter: MemoizedNumberFormatterFactory;
export declare const getDateFormatter: MemoizedDateTimeFormatterFactory;
export declare const getTimeFormatter: MemoizedDateTimeFormatterFactory;
export declare const getMessageFormatter: (message: string, locale?: string) => IntlMessageFormat;
export {};
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