frenchkiss
Advanced tools
Comparing version 0.0.6 to 0.0.7
/** | ||
* @license frenchkiss 0.0.6 | ||
* @license frenchkiss 0.0.7 | ||
* Copyright (c) 2018-2019 Koala Interactive, Inc. | ||
* License: MIT | ||
*/ | ||
"use strict";var t=/^\s*\w+\s*$/,r=/^\s*(\w+)\s*,\s*(select|plural)\s*,/i,n=JSON.stringify,e=function(t){return'(p["'+t.trim()+'"]||"")'};function u(t){for(var r={},u=function t(r,u){var o=[];var f=r.length;for(var i=0;i<f;++i){var s=r[i],a=s[0],c=s[1],l="";if(0===a&&c)l=n(c);else if(1===a)l=e(c);else if(2===a){for(var v=s[2],p=s[3],h=s[4],g=p.length,d=0;d<g;++d)h?"="===p[d][0][0]?l+='p["'+v+'"]=='+n(p[d][0].substr(1)):(u[v]=1,l+='m["'+v+'"]=='+n(p[d][0])):l+='p["'+v+'"]=='+n(p[d][0]),l+="?"+t(p[d][1],u)+":";l="("+l+t(c,u)+")"}l&&o.push(l)}return o.join("+")||'""'}(o(t),r),f=Object.keys(r),i=f.length,s=[],a=0;a<i;++a)s[a]=f[a]+':f(p["'+f[a]+'"])';return Function("a","f","var p=a||{}"+(i?",m=f?{"+s+"}:{}":"")+";return "+u)}function o(n){for(var e=0,u="",o=n.length,i=[],s=0;s<o;++s){var a=n[s],c=void 0;"{"===a?e++||(c=[0,u]):"}"===a&&(--e||(c=t.test(u)?[1,u]:r.test(u)?f(u):[0,u])),c?(i.push(c),u=""):u+=a}return i.push([0,u]),i}function f(t){for(var n=t.match(r),e=n[1],u="p"===n[2][0].toLowerCase(),f=o(t.replace(r,"")),i=f.length,s=[],a=[0,""],c=0;c<i-1;){var l=f[c++][1].trim(),v=o(f[c++][1]);"other"===l?a=v:s.push([l,v])}return[2,a,e,s,u]}var i={},s={},a={},c="",l="",v=function(t){return t},p=function(t,r){return i[r]||(i[r]={}),!i[r][t]&&s[r]&&"string"==typeof s[r][t]&&(i[r][t]=u(s[r][t])),i[r][t]},h={cache:i,store:s,t:function(t,r,n){var e,u=n||c;return u&&(e=p(t,u)),!e&&l&&(e=p(t,u=l)),e?e(r,a[u]):v(t)},onMissingKey:function(t){v=t},locale:function(t){return t&&(c=t),c},fallback:function(t){return t&&(l=t),l},set:function(t,r){i[t]={},s[t]=r},unset:function(t){delete i[t],delete s[t]},extend:function(t,r){s[t]||(s[t]={}),i[t]||(i[t]={});for(var n=Object.keys(r),e=n.length,u=0;u<e;++u){var o=n[u];s[t][o]=r[o],delete i[t][o]}},plural:function(t,r){a[t]=r}};module.exports=h; | ||
"use strict";var t=/^\s*\w+\s*$/,r=/^\s*(\w+)\s*,\s*(select|plural)\s*,/i,n=JSON.stringify,e=function(t){return'(p["'+t+'"]||(p["'+t+'"]=="0"?0:""))'};function u(t){for(var r={},u=function t(r,u){var o=[];var f=r.length;for(var i=0;i<f;++i){var s=r[i],a=s[0],c=s[1],l="";if(0===a&&c)l=n(c);else if(1===a)l=e(c.trim());else if(2===a){for(var v=s[2],p=s[3],h=s[4],g=p.length,d=0;d<g;++d)h?"="===p[d][0][0]?l+='p["'+v+'"]=='+n(p[d][0].substr(1)):(u[v]=1,l+='m["'+v+'"]=='+n(p[d][0])):l+='p["'+v+'"]=='+n(p[d][0]),l+="?"+t(p[d][1],u)+":";l="("+l+t(c,u)+")"}l&&o.push(l)}return o.join("+")||'""'}(o(t),r),f=Object.keys(r),i=f.length,s=[],a=0;a<i;++a)s[a]=f[a]+':f(p["'+f[a]+'"])';return Function("a","f","var p=a||{}"+(i?",m=f?{"+s+"}:{}":"")+";return "+u)}function o(n){for(var e=0,u="",o=n.length,i=[],s=0;s<o;++s){var a=n[s],c=void 0;"{"===a?e++||(c=[0,u]):"}"===a&&(--e||(c=t.test(u)?[1,u]:r.test(u)?f(u):[0,u])),c?(i.push(c),u=""):u+=a}return i.push([0,u]),i}function f(t){for(var n=t.match(r),e=n[1],u="p"===n[2][0].toLowerCase(),f=o(t.replace(r,"")),i=f.length,s=[],a=[0,""],c=0;c<i-1;){var l=f[c++][1].trim(),v=o(f[c++][1]);"other"===l?a=v:s.push([l,v])}return[2,a,e,s,u]}var i={},s={},a={},c="",l="",v=function(t){return t},p=function(t,r){return i[r]||(i[r]={}),!i[r][t]&&s[r]&&"string"==typeof s[r][t]&&(i[r][t]=u(s[r][t])),i[r][t]},h={cache:i,store:s,t:function(t,r,n){var e,u=n||c;return u&&(e=p(t,u)),!e&&l&&(e=p(t,u=l)),e?e(r,a[u]):v(t)},onMissingKey:function(t){v=t},locale:function(t){return t&&(c=t),c},fallback:function(t){return t&&(l=t),l},set:function(t,r){i[t]={},s[t]=r},unset:function(t){delete i[t],delete s[t]},extend:function(t,r){s[t]||(s[t]={}),i[t]||(i[t]={});for(var n=Object.keys(r),e=n.length,u=0;u<e;++u){var o=n[u];s[t][o]=r[o],delete i[t][o]}},plural:function(t,r){a[t]=r}};module.exports=h; |
/** | ||
* @license frenchkiss 0.0.6 | ||
* @license frenchkiss 0.0.7 | ||
* Copyright (c) 2018-2019 Koala Interactive, Inc. | ||
* License: MIT | ||
*/ | ||
const t=/^\s*\w+\s*$/,e=/^\s*(\w+)\s*,\s*(select|plural)\s*,/i,n=JSON.stringify,s=t=>'(p["'+t.trim()+'"]||"")';function l(t){const e={},l=function t(e,l){const o=[];const r=e.length;for(let c=0;c<r;++c){const r=e[c],f=r[0],u=r[1];let i="";if(0===f&&u)i=n(u);else if(1===f)i=s(u);else if(2===f){const e=r[2],s=r[3],o=r[4],c=s.length;for(let r=0;r<c;++r)o?"="===s[r][0][0]?i+='p["'+e+'"]=='+n(s[r][0].substr(1)):(l[e]=1,i+='m["'+e+'"]=='+n(s[r][0])):i+='p["'+e+'"]=='+n(s[r][0]),i+="?"+t(s[r][1],l)+":";i="("+i+t(u,l)+")"}i&&o.push(i)}return o.join("+")||'""'}(o(t),e),r=Object.keys(e),c=r.length,f=[];for(let t=0;t<c;++t)f[t]=r[t]+':f(p["'+r[t]+'"])';return Function("a","f","var p=a||{}"+(c?",m=f?{"+f+"}:{}":"")+";return "+l)}function o(n){let s=0,l="";const o=n.length,c=[];for(let f=0;f<o;++f){const o=n[f];let u;"{"===o?s++||(u=[0,l]):"}"===o&&(--s||(u=t.test(l)?[1,l]:e.test(l)?r(l):[0,l])),u?(c.push(u),l=""):l+=o}return c.push([0,l]),c}function r(t){const n=t.match(e),s=n[1],l="p"===n[2][0].toLowerCase(),r=o(t.replace(e,"")),c=r.length,f=[];let u=[0,""];for(let t=0;t<c-1;){let e=r[t++][1].trim();const n=o(r[t++][1]);"other"===e?u=n:f.push([e,n])}return[2,u,s,f,l]}const c={},f={};let u={},i="",p="",a=t=>t;const h=(t,e)=>(c[e]||(c[e]={}),!c[e][t]&&f[e]&&"string"==typeof f[e][t]&&(c[e][t]=l(f[e][t])),c[e][t]),g=(t,e,n)=>{let s,l=n||i;return l&&(s=h(t,l)),!s&&p&&(s=h(t,l=p)),s?s(e,u[l]):a(t)},d=t=>{a=t},m=t=>(t&&(i=t),i),y=t=>(t&&(p=t),p),b=(t,e)=>{c[t]={},f[t]=e},j=(t,e)=>{u[t]=e},k=(t,e)=>{f[t]||(f[t]={}),c[t]||(c[t]={});const n=Object.keys(e),s=n.length;for(let l=0;l<s;++l){const s=n[l];f[t][s]=e[s],delete c[t][s]}},w=t=>{delete c[t],delete f[t]};export default{cache:c,store:f,t:g,onMissingKey:d,locale:m,fallback:y,set:b,unset:w,extend:k,plural:j};export{c as cache,f as store,g as t,d as onMissingKey,m as locale,y as fallback,b as set,j as plural,k as extend,w as unset}; | ||
const t=/^\s*\w+\s*$/,e=/^\s*(\w+)\s*,\s*(select|plural)\s*,/i,n=JSON.stringify,s=t=>'(p["'+t+'"]||(p["'+t+'"]=="0"?0:""))';function l(t){const e={},l=function t(e,l){const o=[];const r=e.length;for(let c=0;c<r;++c){const r=e[c],f=r[0],u=r[1];let i="";if(0===f&&u)i=n(u);else if(1===f)i=s(u.trim());else if(2===f){const e=r[2],s=r[3],o=r[4],c=s.length;for(let r=0;r<c;++r)o?"="===s[r][0][0]?i+='p["'+e+'"]=='+n(s[r][0].substr(1)):(l[e]=1,i+='m["'+e+'"]=='+n(s[r][0])):i+='p["'+e+'"]=='+n(s[r][0]),i+="?"+t(s[r][1],l)+":";i="("+i+t(u,l)+")"}i&&o.push(i)}return o.join("+")||'""'}(o(t),e),r=Object.keys(e),c=r.length,f=[];for(let t=0;t<c;++t)f[t]=r[t]+':f(p["'+r[t]+'"])';return Function("a","f","var p=a||{}"+(c?",m=f?{"+f+"}:{}":"")+";return "+l)}function o(n){let s=0,l="";const o=n.length,c=[];for(let f=0;f<o;++f){const o=n[f];let u;"{"===o?s++||(u=[0,l]):"}"===o&&(--s||(u=t.test(l)?[1,l]:e.test(l)?r(l):[0,l])),u?(c.push(u),l=""):l+=o}return c.push([0,l]),c}function r(t){const n=t.match(e),s=n[1],l="p"===n[2][0].toLowerCase(),r=o(t.replace(e,"")),c=r.length,f=[];let u=[0,""];for(let t=0;t<c-1;){let e=r[t++][1].trim();const n=o(r[t++][1]);"other"===e?u=n:f.push([e,n])}return[2,u,s,f,l]}const c={},f={};let u={},i="",p="",a=t=>t;const h=(t,e)=>(c[e]||(c[e]={}),!c[e][t]&&f[e]&&"string"==typeof f[e][t]&&(c[e][t]=l(f[e][t])),c[e][t]),g=(t,e,n)=>{let s,l=n||i;return l&&(s=h(t,l)),!s&&p&&(s=h(t,l=p)),s?s(e,u[l]):a(t)},d=t=>{a=t},m=t=>(t&&(i=t),i),y=t=>(t&&(p=t),p),b=(t,e)=>{c[t]={},f[t]=e},j=(t,e)=>{u[t]=e},k=(t,e)=>{f[t]||(f[t]={}),c[t]||(c[t]={});const n=Object.keys(e),s=n.length;for(let l=0;l<s;++l){const s=n[l];f[t][s]=e[s],delete c[t][s]}},w=t=>{delete c[t],delete f[t]};export default{cache:c,store:f,t:g,onMissingKey:d,locale:m,fallback:y,set:b,unset:w,extend:k,plural:j};export{c as cache,f as store,g as t,d as onMissingKey,m as locale,y as fallback,b as set,j as plural,k as extend,w as unset}; |
/** | ||
* @license frenchkiss 0.0.6 | ||
* @license frenchkiss 0.0.7 | ||
* Copyright (c) 2018-2019 Koala Interactive, Inc. | ||
* License: MIT | ||
*/ | ||
var e,t;e=this,t=function(){"use strict";var e=/^\s*\w+\s*$/,t=/^\s*(\w+)\s*,\s*(select|plural)\s*,/i,n=JSON.stringify,r=function(e){return'(p["'+e.trim()+'"]||"")'};function u(e){for(var t={},u=function e(t,u){var f=[];var o=t.length;for(var i=0;i<o;++i){var s=t[i],c=s[0],a=s[1],l="";if(0===c&&a)l=n(a);else if(1===c)l=r(a);else if(2===c){for(var p=s[2],v=s[3],h=s[4],d=v.length,g=0;g<d;++g)h?"="===v[g][0][0]?l+='p["'+p+'"]=='+n(v[g][0].substr(1)):(u[p]=1,l+='m["'+p+'"]=='+n(v[g][0])):l+='p["'+p+'"]=='+n(v[g][0]),l+="?"+e(v[g][1],u)+":";l="("+l+e(a,u)+")"}l&&f.push(l)}return f.join("+")||'""'}(f(e),t),o=Object.keys(t),i=o.length,s=[],c=0;c<i;++c)s[c]=o[c]+':f(p["'+o[c]+'"])';return Function("a","f","var p=a||{}"+(i?",m=f?{"+s+"}:{}":"")+";return "+u)}function f(n){for(var r=0,u="",f=n.length,i=[],s=0;s<f;++s){var c=n[s],a=void 0;"{"===c?r++||(a=[0,u]):"}"===c&&(--r||(a=e.test(u)?[1,u]:t.test(u)?o(u):[0,u])),a?(i.push(a),u=""):u+=c}return i.push([0,u]),i}function o(e){for(var n=e.match(t),r=n[1],u="p"===n[2][0].toLowerCase(),o=f(e.replace(t,"")),i=o.length,s=[],c=[0,""],a=0;a<i-1;){var l=o[a++][1].trim(),p=f(o[a++][1]);"other"===l?c=p:s.push([l,p])}return[2,c,r,s,u]}var i={},s={},c={},a="",l="",p=function(e){return e},v=function(e,t){return i[t]||(i[t]={}),!i[t][e]&&s[t]&&"string"==typeof s[t][e]&&(i[t][e]=u(s[t][e])),i[t][e]};return{cache:i,store:s,t:function(e,t,n){var r,u=n||a;return u&&(r=v(e,u)),!r&&l&&(r=v(e,u=l)),r?r(t,c[u]):p(e)},onMissingKey:function(e){p=e},locale:function(e){return e&&(a=e),a},fallback:function(e){return e&&(l=e),l},set:function(e,t){i[e]={},s[e]=t},unset:function(e){delete i[e],delete s[e]},extend:function(e,t){s[e]||(s[e]={}),i[e]||(i[e]={});for(var n=Object.keys(t),r=n.length,u=0;u<r;++u){var f=n[u];s[e][f]=t[f],delete i[e][f]}},plural:function(e,t){c[e]=t}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).frenchkiss=t(); | ||
var e,t;e=this,t=function(){"use strict";var e=/^\s*\w+\s*$/,t=/^\s*(\w+)\s*,\s*(select|plural)\s*,/i,n=JSON.stringify,r=function(e){return'(p["'+e+'"]||(p["'+e+'"]=="0"?0:""))'};function u(e){for(var t={},u=function e(t,u){var f=[];var o=t.length;for(var i=0;i<o;++i){var s=t[i],c=s[0],a=s[1],l="";if(0===c&&a)l=n(a);else if(1===c)l=r(a.trim());else if(2===c){for(var p=s[2],v=s[3],h=s[4],d=v.length,g=0;g<d;++g)h?"="===v[g][0][0]?l+='p["'+p+'"]=='+n(v[g][0].substr(1)):(u[p]=1,l+='m["'+p+'"]=='+n(v[g][0])):l+='p["'+p+'"]=='+n(v[g][0]),l+="?"+e(v[g][1],u)+":";l="("+l+e(a,u)+")"}l&&f.push(l)}return f.join("+")||'""'}(f(e),t),o=Object.keys(t),i=o.length,s=[],c=0;c<i;++c)s[c]=o[c]+':f(p["'+o[c]+'"])';return Function("a","f","var p=a||{}"+(i?",m=f?{"+s+"}:{}":"")+";return "+u)}function f(n){for(var r=0,u="",f=n.length,i=[],s=0;s<f;++s){var c=n[s],a=void 0;"{"===c?r++||(a=[0,u]):"}"===c&&(--r||(a=e.test(u)?[1,u]:t.test(u)?o(u):[0,u])),a?(i.push(a),u=""):u+=c}return i.push([0,u]),i}function o(e){for(var n=e.match(t),r=n[1],u="p"===n[2][0].toLowerCase(),o=f(e.replace(t,"")),i=o.length,s=[],c=[0,""],a=0;a<i-1;){var l=o[a++][1].trim(),p=f(o[a++][1]);"other"===l?c=p:s.push([l,p])}return[2,c,r,s,u]}var i={},s={},c={},a="",l="",p=function(e){return e},v=function(e,t){return i[t]||(i[t]={}),!i[t][e]&&s[t]&&"string"==typeof s[t][e]&&(i[t][e]=u(s[t][e])),i[t][e]};return{cache:i,store:s,t:function(e,t,n){var r,u=n||a;return u&&(r=v(e,u)),!r&&l&&(r=v(e,u=l)),r?r(t,c[u]):p(e)},onMissingKey:function(e){p=e},locale:function(e){return e&&(a=e),a},fallback:function(e){return e&&(l=e),l},set:function(e,t){i[e]={},s[e]=t},unset:function(e){delete i[e],delete s[e]},extend:function(e,t){s[e]||(s[e]={}),i[e]||(i[e]={});for(var n=Object.keys(t),r=n.length,u=0;u<r;++u){var f=n[u];s[e][f]=t[f],delete i[e][f]}},plural:function(e,t){c[e]=t}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).frenchkiss=t(); |
{ | ||
"name": "frenchkiss", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "The blazing fast lightweight translation module for javascript", | ||
@@ -5,0 +5,0 @@ "author": "Vincent Thibault <vthibault.mobile@gmail.com>", |
@@ -1,11 +0,14 @@ | ||
# FrenchKiss.js | ||
<div align="center"> | ||
<h1>💋 FrenchKiss.js</h1> | ||
[![Build Status](https://travis-ci.com/koala-interactive/frenchkiss.js.svg?branch=master)](https://travis-ci.com/koala-interactive/frenchkiss.js) | ||
[![File size](https://img.shields.io/badge/GZIP%20size-1021%20B-brightgreen.svg)](./dist/umd/frenchkiss.js) | ||
![](https://img.shields.io/badge/dependencies-0-brightgreen.svg) | ||
[![File size](https://img.shields.io/badge/GZIP%20size-1028%20B-brightgreen.svg)](./dist/umd/frenchkiss.js) | ||
![](https://img.shields.io/badge/dependencies-none-brightgreen.svg) | ||
![](https://img.shields.io/snyk/vulnerabilities/github/koala-interactive/frenchkiss.js.svg) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT) | ||
FrenchKiss.js is a blazing fast lightweight i18n helper library written in JavaScript, working both in the browser and NodeJS environments. It provides a simple and really fast solution for handling internationalization. | ||
</div> | ||
FrenchKiss.js is a blazing fast lightweight i18n library written in JavaScript, working both in the browser and NodeJS environments. It provides a simple and really fast solution for handling internationalization. | ||
FrenchKiss is by now, _the fastest i18n JS package_ out there, working **5 to 1000 times faster** than any others by **JIT compiling** the translations, try it by running the benchmarks ! | ||
@@ -42,2 +45,3 @@ | ||
$ yarn start | ||
$ open ./result.html | ||
@@ -310,1 +314,8 @@ ![i18n benchmark](./benchmark/benchmark.jpg) | ||
``` | ||
--- | ||
## 🔗 Related projects | ||
- [i18next-scanner](https://github.com/i18next/i18next-scanner): Scan your code, extract translation keys/values, and merge them into i18n resource files. | ||
- [i18n-extract](https://github.com/oliviertassinari/i18n-extract): Manage localization with static analysis. (report unused/missing/duplicated key, extract them). |
18635
320