Socket
Socket
Sign inDemoInstall

svelte-i18n

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-i18n - npm Package Compare versions

Comparing version 2.2.2 to 2.2.3

4

CHANGELOG.md

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

## [2.2.3](https://github.com/kaisermann/svelte-i18n/compare/v2.2.2...v2.2.3) (2020-01-15)
## [2.2.2](https://github.com/kaisermann/svelte-i18n/compare/v2.2.0...v2.2.2) (2020-01-14)

@@ -2,0 +6,0 @@

4

dist/cli.js
#!/usr/bin/env node
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("fs")),r=require("path"),n=e(require("commander")),i=e(require("tiny-glob")),o=require("svelte/compiler"),a=e(require("dlv")),l=require("estree-walker");
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("fs")),r=require("path"),n=e(require("commander")),i=e(require("tiny-glob")),o=require("svelte/compiler"),a=require("estree-walker");
/*! *****************************************************************************

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

***************************************************************************** */
function c(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function s(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=c(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,i){(function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)})(n,i,(t=e[r](t)).done,t.value)}))}}}function u(e,t,r){const n=t.replace(/\[(\w+)\]/gi,".$1").split(".");return n.reduce((e,t,i)=>{return t in e?e[t]:i<n.length-1?(o=n[i+1],Number.isNaN(parseInt(o))?e[t]={}:e[t]=[]):e[t]=r;var o},e)}function f(e){return e.properties.reduce((e,t)=>{if("Literal"===t.value.type&&t.value.value!==Object(t.value.value)){const r=t.key.name;e.meta[r]=t.value.value}return e},{node:e,meta:{}})}const p=new Set(["format","_","t"]),m=new Set(["number","date","time"]);function d(e){return e.instance?e.instance.content.body.filter(e=>"ImportDeclaration"===e.type&&"svelte-i18n"===e.source.value):[]}function y(e){return e.specifiers.find(e=>"imported"in e&&"defineMessages"===e.imported.name)}function v(e){const t=d(e);if(0===t.length)return[];const r=new Set(t.flatMap(e=>function(e){return e.specifiers.filter(e=>"imported"in e&&p.has(e.imported.name))}(e).map(e=>e.local.name)));if(0===r.size)return[];const n=[];function i(e){(function(e,t){if("CallExpression"!==e.type)return!1;let r;if("MemberExpression"!==e.callee.type||"Identifier"!==e.callee.property.type||m.has(e.callee.property.name)?"Identifier"===e.callee.type&&(r=e.callee):r=e.callee.object,!r||"Identifier"!==r.type)return!1;const n=r.name.slice(1);return t.has(n)})(e,r)&&(n.push(e),this.skip())}return l.walk(e.instance,{enter:i}),l.walk(e.html,{enter:i}),n}function w(e){const t=o.parse(e),r=v(t);return[...function(e){const t=[],r=d(e).find(y);if(null==r)return[];const n=y(r).local.name;return l.walk(e.instance,{enter(e){if(!1===function(e,t){return"CallExpression"===e.type&&(e.callee&&"Identifier"===e.callee.type&&e.callee.name===t)}(e,n))return;const[r]=e.arguments;"ObjectExpression"===r.type&&(t.push(r),this.skip())}}),t.flatMap(e=>e.properties.map(e=>e.value))}(t).map(e=>f(e)),...r.map(e=>{const[t,r]=e.arguments;if("ObjectExpression"===t.type)return f(t);const n=t,i=n.value;if(r&&"ObjectExpression"===r.type){const e=f(r);return e.meta.id=i,e}return{node:n,meta:{id:i}}})].filter(Boolean)}function h(e,{accumulator:t={},shallow:r=!1,overwrite:n=!1}={}){return w(e).forEach(e=>{let i=e.meta.default;if(void 0===i&&(i=""),r){if(!1===n&&e.meta.id in t)return;t[e.meta.id]=i}else{if(!1===n&&void 0!==a(t,e.meta.id))return;u(t,e.meta.id,i)}}),t}const{readFile:g,writeFile:b,mkdir:j,access:S}=t.promises;n.command("extract <glob> [output]").description("extract all message definitions from files to a json").option("-s, --shallow","extract to a shallow dictionary (ids with dots interpreted as strings, not paths)",!1).option("--overwrite","overwrite the content of the output file instead of just appending new properties",!1).option("-c, --config <dir>",'path to the "svelte.config.js" file',process.cwd()).action(async(e,t,{shallow:n,overwrite:a,config:l})=>{var c,u;const f=(await i(e)).filter(e=>e.match(/\.html|svelte$/i)),p=await new Promise((function(e){e(function(e){if(e&&e.__esModule)return e;var t={};return e&&Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t.default=e,t}(require(r.resolve(l,"svelte.config.js"))))})).catch(()=>null);let m={};null!=t&&!1===a&&await(e=>S(e).then(()=>!0).catch(()=>!1))(t)&&(m=await g(t).then(e=>JSON.parse(e.toString())).catch(e=>{console.warn(e),m={}}));try{for(var d,y=s(f);!(d=await y.next()).done;){const e=d.value;let t=(await g(e)).toString();if(p&&p.preprocess){t=(await o.preprocess(t,p.preprocess,{filename:e})).code}h(t,{accumulator:m,shallow:n})}}catch(e){c={error:e}}finally{try{d&&!d.done&&(u=y.return)&&await u.call(y)}finally{if(c)throw c.error}}const v=JSON.stringify(m,null," ");if(null==t)return console.log(v);await j(r.dirname(t),{recursive:!0}),await b(t,v)}),n.parse(process.argv);
function c(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function l(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=c(e),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(r){t[r]=e[r]&&function(t){return new Promise((function(n,i){(function(e,t,r,n){Promise.resolve(n).then((function(t){e({value:t,done:r})}),t)})(n,i,(t=e[r](t)).done,t.value)}))}}}function s(e,t,r){const n=t.replace(/\[(\w+)\]/gi,".$1").split(".");return n.reduce((e,t,i)=>{return t in e?e[t]:i<n.length-1?(o=n[i+1],Number.isNaN(parseInt(o))?e[t]={}:e[t]=[]):e[t]=r;var o},e)}function u(e){return e.properties.reduce((e,t)=>{if("Literal"===t.value.type&&t.value.value!==Object(t.value.value)){const r=t.key.name;e.meta[r]=t.value.value}return e},{node:e,meta:{}})}const f=new Set(["format","_","t"]),p=new Set(["number","date","time"]);function m(e){return e.instance?e.instance.content.body.filter(e=>"ImportDeclaration"===e.type&&"svelte-i18n"===e.source.value):[]}function d(e){return e.specifiers.find(e=>"imported"in e&&"defineMessages"===e.imported.name)}function y(e){const t=m(e);if(0===t.length)return[];const r=new Set(t.flatMap(e=>function(e){return e.specifiers.filter(e=>"imported"in e&&f.has(e.imported.name))}(e).map(e=>e.local.name)));if(0===r.size)return[];const n=[];function i(e){(function(e,t){if("CallExpression"!==e.type)return!1;let r;if("MemberExpression"!==e.callee.type||"Identifier"!==e.callee.property.type||p.has(e.callee.property.name)?"Identifier"===e.callee.type&&(r=e.callee):r=e.callee.object,!r||"Identifier"!==r.type)return!1;const n=r.name.slice(1);return t.has(n)})(e,r)&&(n.push(e),this.skip())}return a.walk(e.instance,{enter:i}),a.walk(e.html,{enter:i}),n}function w(e){const t=o.parse(e),r=y(t);return[...function(e){const t=[],r=m(e).find(d);if(null==r)return[];const n=d(r).local.name;return a.walk(e.instance,{enter(e){if(!1===function(e,t){return"CallExpression"===e.type&&(e.callee&&"Identifier"===e.callee.type&&e.callee.name===t)}(e,n))return;const[r]=e.arguments;"ObjectExpression"===r.type&&(t.push(r),this.skip())}}),t.flatMap(e=>e.properties.map(e=>e.value))}(t).map(e=>u(e)),...r.map(e=>{const[t,r]=e.arguments;if("ObjectExpression"===t.type)return u(t);const n=t,i=n.value;if(r&&"ObjectExpression"===r.type){const e=u(r);return e.meta.id=i,e}return{node:n,meta:{id:i}}})].filter(Boolean)}function h(e,{accumulator:t={},shallow:r=!1,overwrite:n=!1}={}){return w(e).forEach(e=>{let i=e.meta.default;if(void 0===i&&(i=""),r){if(!1===n&&e.meta.id in t)return;t[e.meta.id]=i}else{if(!1===n&&"undefined"!=(o=t,typeof e.meta.id.split(".").reduce((e,t)=>"object"!=typeof e?e:e[t],o)))return;s(t,e.meta.id,i)}var o}),t}const{readFile:v,writeFile:g,mkdir:b,access:j}=t.promises;n.command("extract <glob> [output]").description("extract all message definitions from files to a json").option("-s, --shallow","extract to a shallow dictionary (ids with dots interpreted as strings, not paths)",!1).option("--overwrite","overwrite the content of the output file instead of just appending new properties",!1).option("-c, --config <dir>",'path to the "svelte.config.js" file',process.cwd()).action(async(e,t,{shallow:n,overwrite:a,config:c})=>{var s,u;const f=(await i(e)).filter(e=>e.match(/\.html|svelte$/i)),p=await new Promise((function(e){e(function(e){if(e&&e.__esModule)return e;var t={};return e&&Object.keys(e).forEach((function(r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})})),t.default=e,t}(require(r.resolve(c,"svelte.config.js"))))})).catch(()=>null);let m={};null!=t&&!1===a&&await(e=>j(e).then(()=>!0).catch(()=>!1))(t)&&(m=await v(t).then(e=>JSON.parse(e.toString())).catch(e=>{console.warn(e),m={}}));try{for(var d,y=l(f);!(d=await y.next()).done;){const e=d.value;let t=(await v(e)).toString();if(p&&p.preprocess){t=(await o.preprocess(t,p.preprocess,{filename:e})).code}h(t,{accumulator:m,shallow:n})}}catch(e){s={error:e}}finally{try{d&&!d.done&&(u=y.return)&&await u.call(y)}finally{if(s)throw s.error}}const w=JSON.stringify(m,null," ");if(null==t)return console.log(w);await b(r.dirname(t),{recursive:!0}),await g(t,w)}),n.parse(process.argv);

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

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

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

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

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

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

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

@@ -82,4 +82,2 @@ "module": "dist/i18n.esm.js",

"commander": "^4.0.1",
"deepmerge": "^4.2.2",
"dlv": "^1.1.3",
"estree-walker": "^0.9.0",

@@ -86,0 +84,0 @@ "fast-memoize": "^2.5.1",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc