Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svelte-i18n

Package Overview
Dependencies
Maintainers
1
Versions
80
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 0.0.4 to 0.0.5

2

dist/i18n.js

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

function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("deepmerge")),n=e(require("object-resolve-path")),r=function(e){return e.replace(/(^|\s)\S/,function(e){return e.toUpperCase()})},o=function(e){return e.replace(/(^|\s)\S/g,function(e){return e.toUpperCase()})},a=function(e){return e.toLocaleUpperCase()},u=function(e){return e.toLocaleLowerCase()},i=function(e){return null!==e&&"object"==typeof e},c=/^(\d)+/,l=/^(\w)+/,s=function(){this._caches=Object.create(null)};s.prototype.interpolate=function(e,t){if(!t)return[e];var n=this._caches[e];return n||(n=function(e){var t=[],n=0,r="";for(;n<e.length;){var o=e[n++];if("{"!==o||n>0&&"\\"===o[n-1])r+=o;else{r.length&&t.push({type:"text",value:r}),r="";var a="";for(o=e[n++];"}"!==o;)a+=o,o=e[n++];var u=c.test(a)?"list":l.test(a)?"named":"unknown";t.push({value:a,type:u})}}r&&t.push({type:"text",value:r});return t}(e),this._caches[e]=n),function(e,t){var n=[],r=0,o=Array.isArray(t)?"list":i(t)?"named":"unknown";if("unknown"===o)return n;for(;r<e.length;){var a=e[r++];switch(a.type){case"text":n.push(a.value);break;case"list":n.push(t[parseInt(a.value,10)]);break;case"named":"named"===o?n.push(t[a.value]):"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Type of token '"+a.type+"' and format of value '"+o+"' don't match!");break;case"unknown":"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Detect 'unknown' type of token!")}}return n}(n,t)},exports.capital=r,exports.title=o,exports.upper=a,exports.lower=u,exports.i18n=function(e,i){var c,l,p=i.dictionary,f=new s,v=function(e,t,r,o){void 0===r&&(r=l),void 0===o&&(o=void 0);var a=n(c[r],e);if(!a)return e;if(o)for(var u=0,i=o.length;u<i;u++)a=o[u](a);return t&&(a=f.interpolate(a,t).join("")),a.trim()},h=function(e,t,n){return r(v(e,t,n))},d=function(e,t,n){return o(v(e,t,n))},y=function(e,t,n){return a(v(e,t,n))},w=function(e,t,n){return u(v(e,t,n))},k=function(e,t,n,r){return v(e,n,r,[function(e){var n="number"==typeof t?Math.min(Math.abs(t),2):0;return e.split("|")[n]}])};return e.on("locale",function(t){if(Object.keys(c).includes(t)){l=t;var n=v;n.upper=y,n.lower=w,n.title=d,n.capital=h,n.plural=k,e.set({locale:t,_:n})}else console.error("[svelte-i18n] Couldn't find the \""+t+'" locale.')}),e.i18n={setLocale:function(t){e.fire("locale",t)},extendDictionary:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];c=t.all([c].concat(e))}},Array.isArray(p)?c=t.all(p):p=c,e};
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("deepmerge")),n=e(require("object-resolve-path")),r=function(e){return e.replace(/(^|\s)\S/,function(e){return e.toUpperCase()})},o=function(e){return e.replace(/(^|\s)\S/g,function(e){return e.toUpperCase()})},a=function(e){return e.toLocaleUpperCase()},u=function(e){return e.toLocaleLowerCase()},i=function(e){return null!==e&&"object"==typeof e},c=/^(\d)+/,l=/^(\w)+/,s=function(){this._caches=Object.create(null)};s.prototype.interpolate=function(e,t){if(!t)return[e];var n=this._caches[e];return n||(n=function(e){var t=[],n=0,r="";for(;n<e.length;){var o=e[n++];if("{"!==o||n>0&&"\\"===o[n-1])r+=o;else{r.length&&t.push({type:"text",value:r}),r="";var a="";for(o=e[n++];"}"!==o;)a+=o,o=e[n++];var u=c.test(a)?"list":l.test(a)?"named":"unknown";t.push({value:a,type:u})}}r&&t.push({type:"text",value:r});return t}(e),this._caches[e]=n),function(e,t){var n=[],r=0,o=Array.isArray(t)?"list":i(t)?"named":"unknown";if("unknown"===o)return n;for(;r<e.length;){var a=e[r++];switch(a.type){case"text":n.push(a.value);break;case"list":n.push(t[parseInt(a.value,10)]);break;case"named":"named"===o?n.push(t[a.value]):"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Type of token '"+a.type+"' and format of value '"+o+"' don't match!");break;case"unknown":"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Detect 'unknown' type of token!")}}return n}(n,t)},exports.capital=r,exports.title=o,exports.upper=a,exports.lower=u,exports.i18n=function(e,i){var c,l=i.dictionary,p=new s,f=Array.isArray(l)?t.all(l):l,v=function(e,t,r,o){void 0===r&&(r=c),void 0===o&&(o=void 0);var a=n(f[r],e);if(!a)return e;if(o)for(var u=0,i=o.length;u<i;u++)a=o[u](a);return t&&(a=p.interpolate(a,t).join("")),a.trim()},h=function(e,t,n){return r(v(e,t,n))},d=function(e,t,n){return o(v(e,t,n))},y=function(e,t,n){return a(v(e,t,n))},w=function(e,t,n){return u(v(e,t,n))},k=function(e,t,n,r){return v(e,n,r,[function(e){var n=e.split("|"),r=2===n.length,o=r?1:0;return"number"==typeof t&&(o=Math.min(Math.abs(t)-(r?1:0),n.length-1)),n[o]}])};return e.on("locale",function(t){if(Object.keys(f).includes(t)){c=t;var n=v;n.upper=y,n.lower=w,n.title=d,n.capital=h,n.plural=k,e.set({locale:t,_:n})}else console.error("[svelte-i18n] Couldn't find the \""+t+'" locale.')}),e.i18n={setLocale:function(t){e.fire("locale",t)},extendDictionary:function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];f=t.all([f].concat(e))}},e};
//# sourceMappingURL=i18n.js.map

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

import e from"deepmerge";import n from"object-resolve-path";var t=function(e){return e.replace(/(^|\s)\S/,function(e){return e.toUpperCase()})},r=function(e){return e.replace(/(^|\s)\S/g,function(e){return e.toUpperCase()})},o=function(e){return e.toLocaleUpperCase()},a=function(e){return e.toLocaleLowerCase()},u=function(e){return null!==e&&"object"==typeof e},i=/^(\d)+/,c=/^(\w)+/,l=function(){this._caches=Object.create(null)};function s(u,i){var c,s,f=i.dictionary,p=new l,v=function(e,t,r,o){void 0===r&&(r=s),void 0===o&&(o=void 0);var a=n(c[r],e);if(!a)return e;if(o)for(var u=0,i=o.length;u<i;u++)a=o[u](a);return t&&(a=p.interpolate(a,t).join("")),a.trim()},h=function(e,n,r){return t(v(e,n,r))},d=function(e,n,t){return r(v(e,n,t))},y=function(e,n,t){return o(v(e,n,t))},m=function(e,n,t){return a(v(e,n,t))},w=function(e,n,t,r){return v(e,t,r,[function(e){var t="number"==typeof n?Math.min(Math.abs(n),2):0;return e.split("|")[t]}])};return u.on("locale",function(e){if(Object.keys(c).includes(e)){s=e;var n=v;n.upper=y,n.lower=m,n.title=d,n.capital=h,n.plural=w,u.set({locale:e,_:n})}else console.error("[svelte-i18n] Couldn't find the \""+e+'" locale.')}),u.i18n={setLocale:function(e){u.fire("locale",e)},extendDictionary:function(){for(var n=[],t=arguments.length;t--;)n[t]=arguments[t];c=e.all([c].concat(n))}},Array.isArray(f)?c=e.all(f):f=c,u}l.prototype.interpolate=function(e,n){if(!n)return[e];var t=this._caches[e];return t||(t=function(e){var n=[],t=0,r="";for(;t<e.length;){var o=e[t++];if("{"!==o||t>0&&"\\"===o[t-1])r+=o;else{r.length&&n.push({type:"text",value:r}),r="";var a="";for(o=e[t++];"}"!==o;)a+=o,o=e[t++];var u=i.test(a)?"list":c.test(a)?"named":"unknown";n.push({value:a,type:u})}}r&&n.push({type:"text",value:r});return n}(e),this._caches[e]=t),function(e,n){var t=[],r=0,o=Array.isArray(n)?"list":u(n)?"named":"unknown";if("unknown"===o)return t;for(;r<e.length;){var a=e[r++];switch(a.type){case"text":t.push(a.value);break;case"list":t.push(n[parseInt(a.value,10)]);break;case"named":"named"===o?t.push(n[a.value]):"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Type of token '"+a.type+"' and format of value '"+o+"' don't match!");break;case"unknown":"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Detect 'unknown' type of token!")}}return t}(t,n)};export{t as capital,r as title,o as upper,a as lower,s as i18n};
import e from"deepmerge";import n from"object-resolve-path";var t=function(e){return e.replace(/(^|\s)\S/,function(e){return e.toUpperCase()})},r=function(e){return e.replace(/(^|\s)\S/g,function(e){return e.toUpperCase()})},o=function(e){return e.toLocaleUpperCase()},a=function(e){return e.toLocaleLowerCase()},u=function(e){return null!==e&&"object"==typeof e},i=/^(\d)+/,c=/^(\w)+/,l=function(){this._caches=Object.create(null)};function s(u,i){var c,s=i.dictionary,f=new l,p=Array.isArray(s)?e.all(s):s,v=function(e,t,r,o){void 0===r&&(r=c),void 0===o&&(o=void 0);var a=n(p[r],e);if(!a)return e;if(o)for(var u=0,i=o.length;u<i;u++)a=o[u](a);return t&&(a=f.interpolate(a,t).join("")),a.trim()},h=function(e,n,r){return t(v(e,n,r))},d=function(e,n,t){return r(v(e,n,t))},y=function(e,n,t){return o(v(e,n,t))},m=function(e,n,t){return a(v(e,n,t))},w=function(e,n,t,r){return v(e,t,r,[function(e){var t=e.split("|"),r=2===t.length,o=r?1:0;return"number"==typeof n&&(o=Math.min(Math.abs(n)-(r?1:0),t.length-1)),t[o]}])};return u.on("locale",function(e){if(Object.keys(p).includes(e)){c=e;var n=v;n.upper=y,n.lower=m,n.title=d,n.capital=h,n.plural=w,u.set({locale:e,_:n})}else console.error("[svelte-i18n] Couldn't find the \""+e+'" locale.')}),u.i18n={setLocale:function(e){u.fire("locale",e)},extendDictionary:function(){for(var n=[],t=arguments.length;t--;)n[t]=arguments[t];p=e.all([p].concat(n))}},u}l.prototype.interpolate=function(e,n){if(!n)return[e];var t=this._caches[e];return t||(t=function(e){var n=[],t=0,r="";for(;t<e.length;){var o=e[t++];if("{"!==o||t>0&&"\\"===o[t-1])r+=o;else{r.length&&n.push({type:"text",value:r}),r="";var a="";for(o=e[t++];"}"!==o;)a+=o,o=e[t++];var u=i.test(a)?"list":c.test(a)?"named":"unknown";n.push({value:a,type:u})}}r&&n.push({type:"text",value:r});return n}(e),this._caches[e]=t),function(e,n){var t=[],r=0,o=Array.isArray(n)?"list":u(n)?"named":"unknown";if("unknown"===o)return t;for(;r<e.length;){var a=e[r++];switch(a.type){case"text":t.push(a.value);break;case"list":t.push(n[parseInt(a.value,10)]);break;case"named":"named"===o?t.push(n[a.value]):"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Type of token '"+a.type+"' and format of value '"+o+"' don't match!");break;case"unknown":"production"!==process.env.NODE_ENV&&console.warn("[svelte-i18n] Detect 'unknown' type of token!")}}return t}(t,n)};export{t as capital,r as title,o as upper,a as lower,s as i18n};
//# sourceMappingURL=i18n.m.js.map
{
"name": "svelte-i18n",
"version": "0.0.4",
"version": "0.0.5",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "dist/i18n.js",

# svelte-i18n
> Internationalization for svelte
> Internationalization for Svelte
**Work-in-progress**
## Usage

@@ -16,6 +14,12 @@

/** i18n(svelteStore, { dictionary }) */
const store = i18n(new Store(), {
let store = new Store()
store = i18n(store, {
dictionary: {
'pt-BR': {
message: 'Mensagem',
greeting: 'Olá {name}, como vai?',
greetingIndex: 'Olá {0}, como vai?',
meter: 'metros | metro | metros',
book: 'livro | livros',
messages: {

@@ -28,2 +32,6 @@ alert: 'Alerta',

message: 'Message',
greeting: 'Hello {name}, how are you?',
greetingIndex: 'Hello {0}, how are you?',
meter: 'meters | meter | meters',
book: 'book | books',
messages: {

@@ -62,12 +70,62 @@ alert: 'Alert',

#### Basic usage
```html
<div>
{$_('message')}: {$_.upper('messages.success'))}
{$_('message')}: {$_('messages.success'))}
<!-- Message: SUCCESS-->
</div>
```
Renders:
#### Interpolation
```html
Message: SUCCESS
<div>
<!-- Named interpolation -->
{$_('greeting', { name: 'John' }))}
<!-- Hello John, how are you?-->
<!-- List interpolation -->
{$_('greetingIndex', ['John']))}
<!-- Hello John, how are you?-->
</div>
```
#### Pluralization
```html
<div>
0 {$_.plural('meter', 0))}
<!-- 0 meters -->
1 {$_.plural('meter', 1))}
<!-- 1 meter -->
100 {$_.plural('meter', 100))}
<!-- 100 meters -->
0 {$_.plural('book', 0))}
<!-- 0 books -->
10 {$_.plural('book', 10))}
<!-- 10 books -->
</div>
```
#### Utilities
```html
<div>
{$_.upper('message'))}
<!-- MESSAGE -->
{$_.lower('message'))}
<!-- message -->
{$_.capital('message'))}
<!-- Message -->
{$_.title('greeting', { name: 'John' }))}
<!-- Hello John, How Are You?-->
</div>
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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