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

types/runtime/includes/flatObj.d.ts

29

CHANGELOG.md

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

## [2.3.1](https://github.com/kaisermann/svelte-i18n/compare/v2.3.0...v2.3.1) (2020-01-29)
# [3.0.0-alpha.1](https://github.com/kaisermann/svelte-i18n/compare/v2.3.0...v3.0.0-alpha.1) (2020-01-30)

@@ -7,6 +7,31 @@

* 🐛 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))
### 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))
### BREAKING CHANGES
* It's now needed to explicitly import the `getClientLocale` method to use
its heuristics when setting the initial locale. This makes the method
and its helpers to be tree-shakeable.
```js
import { init, getClientLocale } from 'svelte-i18n'
init({
initialLocale: getClientLocale({ ... })
})
```
* Changes completely the API. Now, to format a number, date or time, the
developer must explicitly import the formatter store:
`import { time, date, number } from 'svelte-i18n'`
# [2.3.0](https://github.com/kaisermann/svelte-i18n/compare/v2.2.4...v2.3.0) (2020-01-23)

@@ -13,0 +38,0 @@

4

dist/runtime.cjs.js

@@ -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 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 l=t.writable({});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=>r(e));l.update(t=>(t[e]=Object.assign(t[e]||{},...n),t))}const m=t.derived([l],([e])=>Object.keys(e));l.subscribe(e=>i=e);const f=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 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);
/*! *****************************************************************************

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

and limitations under the License.
***************************************************************************** */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||s(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)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)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)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=(e={})=>{var{locale:t=D()}=e,n=p(e,["locale"]);return T(Object.assign({locale:t},n))},U=(e={})=>{var{locale:t=D()}=e,n=p(e,["locale"]);return C(Object.assign({locale:t},n))},_=(e={})=>{var{locale:t=D()}=e,n=p(e,["locale"]);return I(Object.assign({locale:t},n))},q=N((e,t=D())=>new n(e,t,g().formats)),Z=(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?q(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)};Z.time=(e,t)=>_(t).format(e),Z.date=(e,t)=>U(t).format(e),Z.number=(e,t)=>A(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 J=t.derived([x,l],()=>Z);exports._=J,exports.addMessages=u,exports.defineMessages=function(e){return e},exports.dictionary=l,exports.format=J,exports.getDateFormatter=U,exports.getMessageFormatter=q,exports.getNumberFormatter=A,exports.getTimeFormatter=_,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 l;return"undefined"==typeof window?null:i&&(l=a(window.location.hostname,i),l)?l:r&&(l=a(window.location.pathname,r),l)?l:e&&(l=window.navigator.language||window.navigator.languages[0],l)?l:n&&(l=o(window.location.search.substr(1),n),l)?l:t&&(l=o(window.location.hash.substr(1),t),l)?l: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)||(s(e)||l.update(t=>(t[e]={},t)),n.add(t))},exports.t=J,exports.waitLocale=function(e){return O(e||D()||g().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 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)};

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

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 c(e){return e in i}function s(e,t){if(c(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);
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);
/*! *****************************************************************************

@@ -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 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 b={};function w(e){return b[e]}function y(e){return $(e).reverse().some(w)}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=w(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 b[e]}(e),t=t.map(e=>e.default||e),u(e,...t)}))).then(()=>{clearTimeout(n),f.set(!1),delete O[e]}),O[e]}function j(e,t){w(e)||function(e){b[e]=new Set}(e);const n=w(e);w(e).has(t)||(c(e)||l.update(t=>(t[e]={},t)),n.add(t))}let L;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 L}k.subscribe(e=>{L=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)});const C=k.set;k.set=e=>function e(t){return null==t||c(t)?t:e(S(t))}(e)&&y(e)?v(e).then(()=>C(e)):C(e),k.update=e=>C(e(L));const I={},N=(e,t)=>{if(null==t)return null;const n=s(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)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)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)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=(e={})=>{var{locale:t=D()}=e,n=d(e,["locale"]);return M(Object.assign({locale:t},n))},J=(e={})=>{var{locale:t=D()}=e,n=d(e,["locale"]);return U(Object.assign({locale:t},n))},_=(e={})=>{var{locale:t=D()}=e,n=d(e,["locale"]);return F(Object.assign({locale:t},n))},q=T((e,t=D())=>new n(e,t,g().formats)),z=(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?q(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)};z.time=(e,t)=>_(t).format(e),z.date=(e,t)=>J(t).format(e),z.number=(e,t)=>Z(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 B=t([k,l],()=>z);function G(e){return e}function H(e){return v(e||D()||g().initialLocale)}export{B as _,u as addMessages,G as defineMessages,l as dictionary,B as format,J as getDateFormatter,q as getMessageFormatter,Z as getNumberFormatter,_ as getTimeFormatter,h as init,f as isLoading,k as locale,m as locales,j as register,B as t,H 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 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};
{
"name": "svelte-i18n",
"version": "2.3.1",
"version": "3.0.0-alpha.1",
"main": "dist/runtime.cjs.js",

@@ -5,0 +5,0 @@ "module": "dist/runtime.esm.js",

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

@@ -5,7 +5,8 @@ import { MessageObject } from './types';

export { init } from './configs';
export { getClientLocale } from './includes/getClientLocale';
export { $locale as locale } from './stores/locale';
export { $dictionary as dictionary, $locales as locales, addMessages, } from './stores/dictionary';
export { registerLocaleLoader as register } from './includes/loaderQueue';
export { $isLoading as isLoading } from './stores/loading';
export { $format as format, $format as _, $format as t } from './stores/format';
export { $format as format, $format as _, $format as t, $formatDate as date, $formatNumber as number, $formatTime as time, } from './stores/formatters';
export { getDateFormatter, getNumberFormatter, getTimeFormatter, getMessageFormatter, } from './includes/formatters';
export { registerLocaleLoader as register } from './includes/loaderQueue';

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

import { DeepDictionary } from '../types';
import { DeepDictionary } from '../types/index';
declare const $dictionary: import("svelte/store").Writable<Record<string, Record<string, string>>>;

@@ -3,0 +3,0 @@ export declare function getLocaleDictionary(locale: string): Record<string, string>;

@@ -1,3 +0,5 @@

import { Formatter } from '../types';
declare const $format: import("svelte/store").Readable<Formatter>;
export { $format };
import { MessageFormatter, TimeFormatter, DateFormatter, NumberFormatter } from '../types';
export declare const $format: import("svelte/store").Readable<MessageFormatter>;
export declare const $formatTime: import("svelte/store").Readable<TimeFormatter>;
export declare const $formatDate: import("svelte/store").Readable<DateFormatter>;
export declare const $formatNumber: import("svelte/store").Readable<NumberFormatter>;

@@ -14,5 +14,6 @@ import { Formats } from 'intl-messageformat';

}
interface FormatterFn {
(id: string | MessageObject, options?: MessageObject): string;
}
export declare type MessageFormatter = (id: string | MessageObject, options?: MessageObject) => string;
export declare type TimeFormatter = (d: Date | number, options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>) => string;
export declare type DateFormatter = (d: Date | number, options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>) => string;
export declare type NumberFormatter = (d: number, options?: IntlFormatterOptions<Intl.NumberFormatOptions>) => string;
declare type IntlFormatterOptions<T> = T & {

@@ -25,11 +26,2 @@ format?: string;

}
export interface Formatter extends FormatterFn {
time: (d: Date | number, options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>) => string;
date: (d: Date | number, options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>) => string;
number: (d: number, options?: IntlFormatterOptions<Intl.NumberFormatOptions>) => string;
capital: FormatterFn;
title: FormatterFn;
upper: FormatterFn;
lower: FormatterFn;
}
export interface MessagesLoader {

@@ -36,0 +28,0 @@ (): Promise<any>;

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