Socket
Socket
Sign inDemoInstall

svelte-i18n

Package Overview
Dependencies
Maintainers
1
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-i18n - npm Package Compare versions

Comparing version 3.2.0 to 3.2.1

9

CHANGELOG.md

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

## [3.2.1](https://github.com/kaisermann/svelte-i18n/compare/v3.2.0...v3.2.1) (2020-11-05)
### Bug Fixes
* 🐛 interpolate values for default values and missing keys ([330f20b](https://github.com/kaisermann/svelte-i18n/commit/330f20b7bd55af1e565de7ba0449a03cc24738aa)), closes [#101](https://github.com/kaisermann/svelte-i18n/issues/101)
# [3.2.0](https://github.com/kaisermann/svelte-i18n/compare/v3.1.0...v3.2.0) (2020-11-05)

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

4

dist/cli.js
#!/usr/bin/env node
"use strict";var e=require("fs"),t=require("path"),r=require("commander"),n=require("tiny-glob"),i=require("svelte/compiler"),o=require("estree-walker"),a=require("dlv");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=l(e),u=l(r),f=l(n),p=l(a);
"use strict";var e=require("fs"),t=require("path"),r=require("sade"),n=require("tiny-glob"),i=require("svelte/compiler"),o=require("estree-walker"),a=require("dlv");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=l(e),u=l(r),f=l(n),p=l(a);
/*! *****************************************************************************

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

***************************************************************************** */
function d(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=d(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 y(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,10))?e[t]={}:e[t]=[]):e[t]=r;var o}),e)}function h(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 v=new Set(["format","_","t"]),w=new Set(["number","date","time"]);function b(e){return e.instance?e.instance.content.body.filter((e=>"ImportDeclaration"===e.type&&"svelte-i18n"===e.source.value)):[]}function g(e){return e.specifiers.find((e=>"imported"in e&&"defineMessages"===e.imported.name))}function j(e){const t=b(e);if(0===t.length)return[];const r=new Set(t.flatMap((e=>function(e){return e.specifiers.filter((e=>"imported"in e&&v.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||w.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 o.walk(e.instance,{enter:i}),o.walk(e.html,{enter:i}),n}function S(e){const t=i.parse(e),r=j(t);return[...function(e){const t=[],r=b(e).find(g);if(null==r)return[];const n=g(r).local.name;return o.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=>{if("Property"!==e.type)throw new Error(`Found invalid '${e.type}' at L${e.loc.start.line}:${e.loc.start.column}`);return e.value}))))}(t).map((e=>h(e))),...r.map((e=>{const[t,r]=e.arguments;if("ObjectExpression"===t.type)return h(t);const n=t,i=n.value;if(r&&"ObjectExpression"===r.type){const e=h(r);return e.meta.id=i,e}return{node:n,meta:{id:i}}}))].filter(Boolean)}function O(e,{accumulator:t={},shallow:r=!1,overwrite:n=!1}={}){return S(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!==p.default(t,e.meta.id))return;y(t,e.meta.id,i)}})),t}const{readFile:x,writeFile:E,mkdir:I,access:k}=s.default.promises;u.default.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,r,{shallow:n,overwrite:o,config:a})=>{var l,s;const u=(await f.default(e)).filter((e=>e.match(/\.html|svelte$/i))),p=await Promise.resolve().then((function(){return c(require(t.resolve(a,"svelte.config.js")))})).catch((()=>null));let d={};null!=r&&!1===o&&await(e=>k(e).then((()=>!0)).catch((()=>!1)))(r)&&(d=await x(r).then((e=>JSON.parse(e.toString()))).catch((e=>{console.warn(e),d={}})));try{for(var y,h=m(u);!(y=await h.next()).done;){const e=y.value;let t=(await x(e)).toString();if(null==p?void 0:p.preprocess){t=(await i.preprocess(t,p.preprocess,{filename:e})).code}O(t,{filePath:e,accumulator:d,shallow:n})}}catch(e){l={error:e}}finally{try{y&&!y.done&&(s=h.return)&&await s.call(h)}finally{if(l)throw l.error}}const v=JSON.stringify(d,null," ");if(null==r)return console.log(v);await I(t.dirname(r),{recursive:!0}),await E(r,v)})),u.default.parse(process.argv);
function d(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function m(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=d(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 y(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,10))?e[t]={}:e[t]=[]):e[t]=r;var o}),e)}function v(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 h=new Set(["format","_","t"]),w=new Set(["number","date","time"]);function b(e){return e.instance?e.instance.content.body.filter((e=>"ImportDeclaration"===e.type&&"svelte-i18n"===e.source.value)):[]}function g(e){return e.specifiers.find((e=>"imported"in e&&"defineMessages"===e.imported.name))}function j(e){const t=b(e);if(0===t.length)return[];const r=new Set(t.flatMap((e=>function(e){return e.specifiers.filter((e=>"imported"in e&&h.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||w.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 o.walk(e.instance,{enter:i}),o.walk(e.html,{enter:i}),n}function S(e){const t=i.parse(e),r=j(t);return[...function(e){const t=[],r=b(e).find(g);if(null==r)return[];const n=g(r).local.name;return o.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=>{if("Property"!==e.type)throw new Error(`Found invalid '${e.type}' at L${e.loc.start.line}:${e.loc.start.column}`);return e.value}))))}(t).map((e=>v(e))),...r.map((e=>{const[t,r]=e.arguments;if("ObjectExpression"===t.type)return v(t);const n=t,i=n.value;if(r&&"ObjectExpression"===r.type){const e=v(r);return e.meta.id=i,e}return{node:n,meta:{id:i}}}))].filter(Boolean)}function O(e,{accumulator:t={},shallow:r=!1,overwrite:n=!1}={}){return S(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!==p.default(t,e.meta.id))return;y(t,e.meta.id,i)}})),t}const{readFile:x,writeFile:E,mkdir:I,access:k}=s.default.promises,q=u.default("svelte-i18n");q.command("extract <glob> [output]").describe("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,r,{shallow:n,overwrite:o,config:a})=>{var l,s;const u=(await f.default(e)).filter((e=>e.match(/\.html|svelte$/i))),p=await Promise.resolve().then((function(){return c(require(t.resolve(a,"svelte.config.js")))})).catch((()=>null));let d={};null!=r&&!1===o&&await(e=>k(e).then((()=>!0)).catch((()=>!1)))(r)&&(d=await x(r).then((e=>JSON.parse(e.toString()))).catch((e=>{console.warn(e),d={}})));try{for(var y,v=m(u);!(y=await v.next()).done;){const e=y.value;let t=(await x(e)).toString();if(null==p?void 0:p.preprocess){t=(await i.preprocess(t,p.preprocess,{filename:e})).code}O(t,{filePath:e,accumulator:d,shallow:n})}}catch(e){l={error:e}}finally{try{y&&!y.done&&(s=v.return)&&await s.call(v)}finally{if(l)throw l.error}}const h=JSON.stringify(d,null," ");if(null==r)return console.log(h);await I(t.dirname(r),{recursive:!0}),await E(r,h)})),q.parse(process.argv);

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

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

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

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

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

PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */function y(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}const v={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function O(){return v}function j(e){const{formats:n}=e,t=y(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(v,t,{initialLocale:o}),n&&("number"in n&&Object.assign(v.formats.number,n.number),"date"in n&&Object.assign(v.formats.date,n.date),"time"in n&&Object.assign(v.formats.time,n.time)),x.set(o)}const L=e(!1);let k;const x=e(null);function E(e,n){return 0===n.indexOf(e)&&e!==n}function D(e,n){return e===n||E(e,n)||E(n,e)}function I(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=O();return t&&!D(e,t)?t:null}function N(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=O();return t&&!D(e,t)?n.concat(N(t)):n}function P(){return k}x.subscribe((e=>{k=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const S=x.set;x.set=e=>{if(u(e)&&w(e)){const{loadingDelay:n}=O();let t;return"undefined"!=typeof window&&null!=P()&&n?t=window.setTimeout((()=>L.set(!0)),n):L.set(!0),h(e).then((()=>{S(e)})).finally((()=>{clearTimeout(t),L.set(!1)}))}return S(e)},x.update=e=>S(e(k));const T=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(n+"=")));return t?t.split("=").pop():null},$=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},A=e=>"undefined"==typeof window?null:$(window.location.hostname,e),M=e=>"undefined"==typeof window?null:$(window.location.pathname,e),F=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],z=e=>"undefined"==typeof window?null:T(window.location.search.substr(1),e),Z=e=>"undefined"==typeof window?null:T(window.location.hash.substr(1),e),C={},J=(e,n)=>{if(null==n)return null;const t=s(n,e);return t||J(e,I(n))},U=(e,n)=>{if(n in C&&e in C[n])return C[n][e];const t=J(e,n);return t?((e,n,t)=>t?(n in C||(C[n]={}),e in C[n]||(C[n][e]=t),t):t)(e,n,t):null},_=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},q=(e,n)=>{const{formats:t}=O();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},B=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=q("number",t)),new Intl.NumberFormat(n,o)})),G=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=q("date",t):0===Object.keys(o).length&&(o=q("date","short")),new Intl.DateTimeFormat(n,o)})),H=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=q("time",t):0===Object.keys(o).length&&(o=q("time","short")),new Intl.DateTimeFormat(n,o)})),K=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return B(Object.assign({locale:n},t))},Q=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return G(Object.assign({locale:n},t))},R=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return H(Object.assign({locale:n},t))},V=_(((e,n=P())=>new r(e,n,O().formats))),W=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=P(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");const i=U(e,o);return i?t?V(i,o).format(t):i:(O().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${N(o).join('", "')}".${w(P())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),r||e)},X=(e,n)=>R(n).format(e),Y=(e,n)=>Q(n).format(e),ee=(e,n)=>K(n).format(e),ne=n([x,a],(()=>W)),te=n([x],(()=>X)),oe=n([x],(()=>Y)),re=n([x],(()=>ee));function ie(e){return e}function ae(e){return h(e||P()||O().initialLocale)}export{ne as _,c as addMessages,oe as date,ie as defineMessages,a as dictionary,ne as format,Q as getDateFormatter,Z as getLocaleFromHash,A as getLocaleFromHostname,F as getLocaleFromNavigator,M as getLocaleFromPathname,z as getLocaleFromQueryString,V as getMessageFormatter,K as getNumberFormatter,R as getTimeFormatter,j as init,L as isLoading,x as locale,m as locales,re as number,b as register,ne as t,te as time,ae as waitLocale};
***************************************************************************** */function y(e,n){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&n.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)n.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(t[o[r]]=e[o[r]])}return t}const v={fallbackLocale:null,initialLocale:null,loadingDelay:200,formats:{number:{scientific:{notation:"scientific"},engineering:{notation:"engineering"},compactLong:{notation:"compact",compactDisplay:"long"},compactShort:{notation:"compact",compactDisplay:"short"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},warnOnMissingMessages:!0};function O(){return v}function j(e){const{formats:n}=e,t=y(e,["formats"]),o=e.initialLocale||e.fallbackLocale;return Object.assign(v,t,{initialLocale:o}),n&&("number"in n&&Object.assign(v.formats.number,n.number),"date"in n&&Object.assign(v.formats.date,n.date),"time"in n&&Object.assign(v.formats.time,n.time)),x.set(o)}const L=e(!1);let k;const x=e(null);function E(e,n){return 0===n.indexOf(e)&&e!==n}function D(e,n){return e===n||E(e,n)||E(n,e)}function I(e){const n=e.lastIndexOf("-");if(n>0)return e.slice(0,n);const{fallbackLocale:t}=O();return t&&!D(e,t)?t:null}function N(e){const n=e.split("-").map(((e,n,t)=>t.slice(0,n+1).join("-"))),{fallbackLocale:t}=O();return t&&!D(e,t)?n.concat(N(t)):n}function P(){return k}x.subscribe((e=>{k=e,"undefined"!=typeof window&&document.documentElement.setAttribute("lang",e)}));const S=x.set;x.set=e=>{if(s(e)&&w(e)){const{loadingDelay:n}=O();let t;return"undefined"!=typeof window&&null!=P()&&n?t=window.setTimeout((()=>L.set(!0)),n):L.set(!0),h(e).then((()=>{S(e)})).finally((()=>{clearTimeout(t),L.set(!1)}))}return S(e)},x.update=e=>S(e(k));const T=(e,n)=>{const t=e.split("&").find((e=>0===e.indexOf(n+"=")));return t?t.split("=").pop():null},$=(e,n)=>{const t=n.exec(e);return t&&t[1]||null},A=e=>"undefined"==typeof window?null:$(window.location.hostname,e),M=e=>"undefined"==typeof window?null:$(window.location.pathname,e),F=()=>"undefined"==typeof window?null:window.navigator.language||window.navigator.languages[0],z=e=>"undefined"==typeof window?null:T(window.location.search.substr(1),e),Z=e=>"undefined"==typeof window?null:T(window.location.hash.substr(1),e),C={},J=(e,n)=>{if(null==n)return null;const t=u(n,e);return t||J(e,I(n))},U=(e,n)=>{if(n in C&&e in C[n])return C[n][e];const t=J(e,n);return t?((e,n,t)=>t?(n in C||(C[n]={}),e in C[n]||(C[n][e]=t),t):t)(e,n,t):null},_=e=>{const n=Object.create(null);return t=>{const o=JSON.stringify(t);return o in n?n[o]:n[o]=e(t)}},q=(e,n)=>{const{formats:t}=O();if(e in t&&n in t[e])return t[e][n];throw new Error(`[svelte-i18n] Unknown "${n}" ${e} format.`)},B=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format numbers');return t&&(o=q("number",t)),new Intl.NumberFormat(n,o)})),G=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format dates');return t?o=q("date",t):0===Object.keys(o).length&&(o=q("date","short")),new Intl.DateTimeFormat(n,o)})),H=_((e=>{var{locale:n,format:t}=e,o=y(e,["locale","format"]);if(null==n)throw new Error('[svelte-i18n] A "locale" must be set to format time values');return t?o=q("time",t):0===Object.keys(o).length&&(o=q("time","short")),new Intl.DateTimeFormat(n,o)})),K=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return B(Object.assign({locale:n},t))},Q=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return G(Object.assign({locale:n},t))},R=(e={})=>{var{locale:n=P()}=e,t=y(e,["locale"]);return H(Object.assign({locale:n},t))},V=_(((e,n=P())=>new r(e,n,O().formats))),W=(e,n={})=>{"object"==typeof e&&(e=(n=e).id);const{values:t,locale:o=P(),default:r}=n;if(null==o)throw new Error("[svelte-i18n] Cannot format a message without first setting the initial locale.");let i=U(e,o);return i||(O().warnOnMissingMessages&&console.warn(`[svelte-i18n] The message "${e}" was not found in "${N(o).join('", "')}".${w(P())?"\n\nNote: there are at least one loader still registered to this locale that wasn't executed.":""}`),i=r||e),t?V(i,o).format(t):i},X=(e,n)=>R(n).format(e),Y=(e,n)=>Q(n).format(e),ee=(e,n)=>K(n).format(e),ne=n([x,a],(()=>W)),te=n([x],(()=>X)),oe=n([x],(()=>Y)),re=n([x],(()=>ee));function ie(e){return e}function ae(e){return h(e||P()||O().initialLocale)}export{ne as _,c as addMessages,oe as date,ie as defineMessages,a as dictionary,ne as format,Q as getDateFormatter,Z as getLocaleFromHash,A as getLocaleFromHostname,F as getLocaleFromNavigator,M as getLocaleFromPathname,z as getLocaleFromQueryString,V as getMessageFormatter,K as getNumberFormatter,R as getTimeFormatter,j as init,L as isLoading,x as locale,m as locales,re as number,b as register,ne as t,te as time,ae as waitLocale};
{
"name": "svelte-i18n",
"version": "3.2.0",
"version": "3.2.1",
"main": "dist/runtime.cjs.js",

@@ -31,4 +31,6 @@ "module": "dist/runtime.esm.js",

"test:ci": "jest --silent",
"test:watch": "jest --verbose --watchAll",
"lint": "eslint \"{src,test}/**/*.ts\"",
"format": "prettier --loglevel silent --write \"{src,test}/**/*.ts\"",
"release": " git add package.json && git commit -m \"chore(release): v$npm_package_version :tada:\"",
"prebuild": "yarn clean",

@@ -81,2 +83,3 @@ "postbuild": "yarn build:types",

"@types/jest": "^26.0.14",
"@types/sade": "^1.7.2",
"babel-core": "^7.0.0-bridge.0",

@@ -102,3 +105,2 @@ "babel-jest": "^26.3.0",

"dependencies": {
"commander": "^4.0.1",
"deepmerge": "^4.2.2",

@@ -108,4 +110,5 @@ "dlv": "^1.1.3",

"intl-messageformat": "^7.5.2",
"sade": "^1.7.4",
"tiny-glob": "^0.2.6"
}
}
import { Formats } from 'intl-messageformat';
export interface LocaleDictionary {
[key: string]: LocaleDictionary | LocaleDictionary[] | string | string[];
[key: string]: LocaleDictionary | string | Array<string | LocaleDictionary>;
}

@@ -15,3 +15,3 @@ export declare type LocalesDictionary = {

}
export declare type MessageFormatter = (id: string | MessageObject, options?: MessageObject) => string;
export declare type MessageFormatter = (id: string | MessageObject, options?: MessageObject) => string | unknown;
export declare type TimeFormatter = (d: Date | number, options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>) => string;

@@ -18,0 +18,0 @@ export declare type DateFormatter = (d: Date | number, options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>) => string;

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