New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ckpack/i18n

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckpack/i18n - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

2

dist/i18n.cjs.js

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

"use strict";var e=Object.defineProperty,s=(s,t,a)=>(((s,t,a)=>{t in s?e(s,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[t]=a})(s,"symbol"!=typeof t?t+"":t,a),a);module.exports=class{constructor(e){s(this,"locale"),s(this,"fallbackLocale"),s(this,"messages");const{locale:t,fallbackLocale:a,messages:l}=e;this.locale=t,this.fallbackLocale=a||t,this.messages=l||{}}t(e,s){const t=this.locale,a=e.split(".");return function(e,s){if(!e||"string"!=typeof e||!s)return e;const t=e.split(/[{}]/);let a="";for(let l=0;l<t.length;l+=1){const e=t[l];if(e)if(l%2!=0){if(!(e in s)&&!Array.isArray(s))throw new Error(`${e} not in params`);a+=s[e]}else a+=e}return a}(this.getMessagesByLocale(a,t)||this.getMessagesByLocale(a,this.fallbackLocale),s)}getMessagesByLocale(e,s){return e.reduce(((e,s)=>{if(e&&s in e)return e[s]}),this.messages[s])}setLocale(e){return-1!==Object.keys(this.messages).indexOf(e)&&(this.locale=e,!0)}setLocaleMessage(e,s){this.messages[e]=s}};
"use strict";module.exports=class{constructor(e){const{locale:s,fallbackLocale:t,messages:a}=e;this.locale=s,this.fallbackLocale=t||s,this.messages=a||{}}t(e,s){const t=this.locale,a=e.split(".");return function(e,s){if("function"==typeof e)return e(s);if(!e||"string"!=typeof e||!s)return e;const t=e.split(/[{}]/);let a="";for(let r=0;r<t.length;r+=1){const e=t[r];!e||(r%2!=0?e in s||Array.isArray(s)?a+=s[e]:(a+=`{${e}}`,console.error(new Error(`${e} not in params`))):a+=e)}return a}(this.getMessagesByLocale(a,t)||this.getMessagesByLocale(a,this.fallbackLocale),s)}getMessagesByLocale(e,s){return e.reduce(((e,s)=>{if(e&&s in e)return e[s]}),this.messages[s])}setLocale(e){return-1!==Object.keys(this.messages).indexOf(e)&&(this.locale=e,!0)}setLocaleMessage(e,s){this.messages[e]=s}};

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

var i=Object.defineProperty;var r=(a,e,s)=>e in a?i(a,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):a[e]=s;var o=(a,e,s)=>(r(a,typeof e!="symbol"?e+"":e,s),s);function n(a,e){if(!a||typeof a!="string"||!e)return a;const s=a.split(/[{}]/);let l="";for(let t=0;t<s.length;t+=1){const c=s[t];if(c)if(t%2!==0)if(c in e||Array.isArray(e))l+=e[c];else throw new Error(`${c} not in params`);else l+=c}return l}class g{constructor(e){o(this,"locale");o(this,"fallbackLocale");o(this,"messages");const{locale:s,fallbackLocale:l,messages:t}=e;this.locale=s,this.fallbackLocale=l||s,this.messages=t||{}}t(e,s){const l=this.locale,t=e.split("."),c=this.getMessagesByLocale(t,l)||this.getMessagesByLocale(t,this.fallbackLocale);return n(c,s)}getMessagesByLocale(e,s){return e.reduce((l,t)=>{if(l&&t in l)return l[t]},this.messages[s])}setLocale(e){return Object.keys(this.messages).indexOf(e)!==-1?(this.locale=e,!0):!1}setLocaleMessage(e,s){this.messages[e]=s}}export{g as default};
function r(o,e){if(typeof o=="function")return o(e);if(!o||typeof o!="string"||!e)return o;const a=o.split(/[{}]/);let s="";for(let t=0;t<a.length;t+=1){const l=a[t];!l||(t%2!==0?l in e||Array.isArray(e)?s+=e[l]:(s+=`{${l}}`,console.error(new Error(`${l} not in params`))):s+=l)}return s}class c{constructor(e){const{locale:a,fallbackLocale:s,messages:t}=e;this.locale=a,this.fallbackLocale=s||a,this.messages=t||{}}t(e,a){const s=this.locale,t=e.split("."),l=this.getMessagesByLocale(t,s)||this.getMessagesByLocale(t,this.fallbackLocale);return r(l,a)}getMessagesByLocale(e,a){return e.reduce((s,t)=>{if(s&&t in s)return s[t]},this.messages[a])}setLocale(e){return Object.keys(this.messages).indexOf(e)!==-1?(this.locale=e,!0):!1}setLocaleMessage(e,a){this.messages[e]=a}}export{c as default};

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

var n=Object.defineProperty,g=(e,s,t)=>s in e?n(e,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[s]=t,r=(e,s,t)=>(g(e,"symbol"!=typeof s?s+"":s,t),t),I18n=function(){"use strict";return class{constructor(e){r(this,"locale"),r(this,"fallbackLocale"),r(this,"messages");const{locale:s,fallbackLocale:t,messages:a}=e;this.locale=s,this.fallbackLocale=t||s,this.messages=a||{}}t(e,s){const t=this.locale,a=e.split(".");return function(e,s){if(!e||"string"!=typeof e||!s)return e;const t=e.split(/[{}]/);let a="";for(let l=0;l<t.length;l+=1){const e=t[l];if(e)if(l%2!=0){if(!(e in s)&&!Array.isArray(s))throw new Error(`${e} not in params`);a+=s[e]}else a+=e}return a}(this.getMessagesByLocale(a,t)||this.getMessagesByLocale(a,this.fallbackLocale),s)}getMessagesByLocale(e,s){return e.reduce(((e,s)=>{if(e&&s in e)return e[s]}),this.messages[s])}setLocale(e){return-1!==Object.keys(this.messages).indexOf(e)&&(this.locale=e,!0)}setLocaleMessage(e,s){this.messages[e]=s}}}();
var I18n=function(){"use strict";return class{constructor(e){const{locale:s,fallbackLocale:t,messages:r}=e;this.locale=s,this.fallbackLocale=t||s,this.messages=r||{}}t(e,s){const t=this.locale,r=e.split(".");return function(e,s){if("function"==typeof e)return e(s);if(!e||"string"!=typeof e||!s)return e;const t=e.split(/[{}]/);let r="";for(let a=0;a<t.length;a+=1){const e=t[a];!e||(a%2!=0?e in s||Array.isArray(s)?r+=s[e]:(r+=`{${e}}`,console.error(new Error(`${e} not in params`))):r+=e)}return r}(this.getMessagesByLocale(r,t)||this.getMessagesByLocale(r,this.fallbackLocale),s)}getMessagesByLocale(e,s){return e.reduce(((e,s)=>{if(e&&s in e)return e[s]}),this.messages[s])}setLocale(e){return-1!==Object.keys(this.messages).indexOf(e)&&(this.locale=e,!0)}setLocaleMessage(e,s){this.messages[e]=s}}}();

@@ -5,3 +5,4 @@ export interface Params {

}
declare function formatMessage(message: string, params?: Params): string;
declare type Fun = (...args: any[]) => string;
declare function formatMessage(message: string | Fun, params?: Params): string;
export { formatMessage, };
{
"name": "@ckpack/i18n",
"version": "0.2.1",
"version": "0.2.2",
"description": "A lightweight internationalization library",

@@ -39,3 +39,3 @@ "type": "module",

},
"author": "陈锴",
"author": "ckvv",
"license": "MIT",

@@ -60,3 +60,4 @@ "private": false,

]
}
},
"packageManager": "pnpm@9.12.0+sha512.4abf725084d7bcbafbd728bfc7bee61f2f791f977fd87542b3579dcb23504d170d46337945e4c66485cd12d588a0c0e570ed9c477e7ccdd8507cf05f3f92eaca"
}

@@ -14,3 +14,4 @@ # i18n

author: "作者: {name}"
}
},
amount: (v: string | number) => `${v}元`
},

@@ -21,3 +22,4 @@ en: {

author: "author: {name}"
}
},
amount: (v: string | number) => `${v}$`
}

@@ -24,0 +26,0 @@ }

@@ -6,2 +6,4 @@ export interface Params {

type Fun = (...args: any[]) => string
/**

@@ -13,4 +15,10 @@ * 格式化

*/
function formatMessage(message: string, params?: Params) {
function formatMessage(message: string | Fun, params?: Params) {
if(typeof message === 'function') {
return message(params);
}
if (!message || typeof message !== 'string' || !params) return message;
const messageArr = message.split(/[{}]/);

@@ -26,3 +34,4 @@

} else {
throw new Error(`${item} not in params`);
messageFormat += `{${item}}`;
console.error(new Error(`${item} not in params`))
}

@@ -29,0 +38,0 @@ } else {

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