Socket
Socket
Sign inDemoInstall

svelte-i18n

Package Overview
Dependencies
30
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.5.2 to 3.6.0

2

dist/runtime.cjs.js

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

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

@@ -100,5 +101,30 @@

type UnwrapStore<T> = T extends Readable<infer U> ? U : T;
/**
* Unwraps a function from a store and make it function calleable easily outside of a Svelte component.
*
* It works by creating a subscription to the store and getting local reference to the store value.
* Then when the returned function is called, it will execute the function by using the local reference.
*
* The returned function has a 'freeze' method that will stop listening to the store.
*
* @example
* // some-js-file.js
* import { format } from 'svelte-i18n';
*
* const $format = unwrapFunctionStore(format);
*
* console.log($format('hello', { name: 'John' }));
*
*/
declare function unwrapFunctionStore<S extends Readable<(...args: any[]) => any>, Fn extends UnwrapStore<S>>(store: S): Fn & {
/**
* Stops listening to the store.
*/
freeze: () => void;
};
declare function defineMessages(i: Record<string, MessageObject>): Record<string, MessageObject>;
declare function waitLocale(locale?: string): Promise<void>;
export { $format as _, addMessages, $formatDate as date, defineMessages, $dictionary as dictionary, $format as format, getDateFormatter, getLocaleFromHash, getLocaleFromHostname, getLocaleFromNavigator, getLocaleFromPathname, getLocaleFromQueryString, getMessageFormatter, getNumberFormatter, getTimeFormatter, init, $isLoading as isLoading, $getJSON as json, $locale as locale, $locales as locales, $formatNumber as number, registerLocaleLoader as register, $format as t, $formatTime as time, waitLocale };
export { $format as _, addMessages, $formatDate as date, defineMessages, $dictionary as dictionary, $format as format, getDateFormatter, getLocaleFromHash, getLocaleFromHostname, getLocaleFromNavigator, getLocaleFromPathname, getLocaleFromQueryString, getMessageFormatter, getNumberFormatter, getTimeFormatter, init, $isLoading as isLoading, $getJSON as json, $locale as locale, $locales as locales, $formatNumber as number, registerLocaleLoader as register, $format as t, $formatTime as time, unwrapFunctionStore, waitLocale };

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

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

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

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc