@sveltekit-i18n/parser-default
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,1 +0,1 @@ | ||
var R=Object.defineProperty,j=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var w=(t,e,i)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,m=(t,e)=>{for(var i in e||(e={}))C.call(e,i)&&w(t,i,e[i]);if(k)for(var i of k(e))O.call(e,i)&&w(t,i,e[i]);return t},T=(t,e)=>j(t,E(e));var l=(t,e)=>{var i={};for(var r in t)C.call(t,r)&&e.indexOf(r)<0&&(i[r]=t[r]);if(t!=null&&k)for(var r of k(t))e.indexOf(r)<0&&O.call(t,r)&&(i[r]=t[r]);return i};var v=(t,e)=>{for(var i in e)R(t,i,{get:e[i],enumerable:!0})};var h={};v(h,{ago:()=>X,date:()=>J,eq:()=>D,gt:()=>U,gte:()=>G,lt:()=>L,lte:()=>B,ne:()=>z,number:()=>H});var x=(t,e)=>{let{modifierDefaults:i}=e||{},{[t]:r}=i||{};return r||{}};var D=({value:t,options:e=[],defaultValue:i=""})=>(e.find(({key:r})=>`${r}`.toLowerCase()===`${t}`.toLowerCase())||{}).value||i,z=({value:t,options:e=[],defaultValue:i=""})=>(e.find(({key:r})=>`${r}`.toLowerCase()!==`${t}`.toLowerCase())||{}).value||i,L=({value:t,options:e=[],defaultValue:i=""})=>(e.sort((o,n)=>+o.key-+n.key).find(({key:o})=>+t<+o)||{}).value||i,U=({value:t,options:e=[],defaultValue:i=""})=>(e.sort((o,n)=>+n.key-+o.key).find(({key:o})=>+t>+o)||{}).value||i,B=({value:t,options:e=[],defaultValue:i=""})=>D({value:t,options:e,defaultValue:L({value:t,options:e,defaultValue:i})}),G=({value:t,options:e=[],defaultValue:i=""})=>D({value:t,options:e,defaultValue:U({value:t,options:e,defaultValue:i})}),H=({value:t,props:e,defaultValue:i="",locale:r="",parserOptions:o})=>{if(!r)return"";let s=x("number",o),{maximumFractionDigits:n}=s,a=l(s,["maximumFractionDigits"]),d=(e==null?void 0:e.number)||{},{maximumFractionDigits:f=n||2}=d,u=l(d,["maximumFractionDigits"]);return new Intl.NumberFormat(r,m(T(m({},a),{maximumFractionDigits:f}),u)).format(+t||+i)},J=({value:t,props:e,defaultValue:i="",locale:r="",parserOptions:o})=>{if(!r)return"";let M=x("date",o),{dateStyle:n,timeStyle:a}=M,f=l(M,["dateStyle","timeStyle"]),c=(e==null?void 0:e.date)||{},{dateStyle:u=n||"medium",timeStyle:s=a||"short"}=c,d=l(c,["dateStyle","timeStyle"]);return new Intl.DateTimeFormat(r,m(T(m({},f),{dateStyle:u,timeStyle:s}),d)).format(+t||+i)},P=[{key:"second",multiplier:1e3},{key:"minute",multiplier:60},{key:"hour",multiplier:60},{key:"day",multiplier:24},{key:"week",multiplier:7},{key:"month",multiplier:13/3},{key:"year",multiplier:12}],q=(t="",e="")=>new RegExp(`^${t}s?$`).test(e),Q=t=>P.indexOf(P.find(({key:e})=>q(e,t))),W=(t,e)=>P.reduce(([i,r],{key:o,multiplier:n},a)=>{if(q(r,e))return[i,r];if(!r||a===Q(r)+1){let f=Math.round(i/n);if(!r||Math.abs(f)>=1||e!=="auto")return[f,o]}return[i,r]},[t,""]),X=({value:t,defaultValue:e="",locale:i="",props:r,parserOptions:o})=>{if(!i)return"";let y=x("ago",o),{format:n,numeric:a}=y,f=l(y,["format","numeric"]),g=(r==null?void 0:r.ago)||{},{format:u=n||"auto",numeric:s=a||"auto"}=g,d=l(g,["format","numeric"]),M=+t||+e,c=W(M,u);return new Intl.RelativeTimeFormat(i,m(T(m({},f),{numeric:s}),d)).format(...c)};var Y=t=>typeof t=="string"&&/{{(?:(?!{{|}}).)+}}/.test(t),p=t=>typeof t=="string"?t.replace(/\\(?=:|;|{|})/g,""):t,Z=({value:t,props:e,payload:i,parserOptions:r,locale:o})=>`${t}`.replace(/{{\s*(?:(?!{{|}}).)+\s*}}/g,n=>{let a=p(`${n.match(/(?!{|\s).+?(?!\\[:;]).(?=\s*(?:[:;]|}}$))/)}`),f=i==null?void 0:i[a],[,u=""]=n.match(/.+?(?!\\;).;\s*default\s*:\s*([^\s:;].+?(?:\\[:;]|[^;\s}])*)(?=\s*(?:;|}}$))/i)||[];u=u||(i==null?void 0:i.default)||"";let[,s=""]=n.match(/{{\s*(?:[^;]|(?:\\;))+\s*(?:(?!\\:).[:])\s*(?!\s)((?:\\;|[^;])+?)(?=\s*(?:[;]|}}$))/i)||[];if(f===void 0&&s!=="ne")return u;let d=!!s,{customModifiers:M}=r||{},c=m(m({},h),M||{});s=Object.keys(c).includes(s)?s:"eq";let y=c[s],g=(n.match(/[^\s:;{](?:[^;]|\\[;])+[^\s:;}]/gi)||[]).reduce((F,b,A)=>{if(A>0){let $=p(`${b.match(/(?:(?:\\:)|[^:])+/)}`.trim()),I=`${b.match(/(?:(?:\\:)|[^:])+$/)}`.trim();if($&&$!=="default"&&I)return[...F,{key:$,value:I}]}return F},[]);return!d&&!g.length?f:y({value:f,options:g,props:e,defaultValue:u,locale:o,parserOptions:r})}),N=({value:t,props:e,payload:i,parserOptions:r,locale:o})=>{if(Y(t)){let n=Z({value:t,payload:i,props:e,parserOptions:r,locale:o});return N({value:n,payload:i,props:e,parserOptions:r,locale:o})}else return p(t)},_=t=>({parse:(e,[i,r],o,n)=>((i==null?void 0:i.default)&&e===void 0&&(e=`${i.default}`),e===void 0&&(e=`${n}`),N({value:e,payload:i,props:r,parserOptions:t,locale:o}))}),it=_;export{it as default}; | ||
var R=Object.defineProperty,E=Object.defineProperties;var v=Object.getOwnPropertyDescriptors;var k=Object.getOwnPropertySymbols;var C=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var w=(t,e,r)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,u=(t,e)=>{for(var r in e||(e={}))C.call(e,r)&&w(t,r,e[r]);if(k)for(var r of k(e))O.call(e,r)&&w(t,r,e[r]);return t},$=(t,e)=>E(t,v(e));var d=(t,e)=>{var r={};for(var i in t)C.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&k)for(var i of k(t))e.indexOf(i)<0&&O.call(t,i)&&(r[i]=t[i]);return r};var z=(t,e)=>{for(var r in e)R(t,r,{get:e[r],enumerable:!0})};var h={};z(h,{ago:()=>X,date:()=>Q,eq:()=>p,gt:()=>q,gte:()=>H,lt:()=>U,lte:()=>G,ne:()=>B,number:()=>J});var T=(t,e)=>{let{modifierDefaults:r}=e||{},{[t]:i}=r||{};return i||{}};var p=({value:t,options:e=[],defaultValue:r=""})=>(e.find(({key:i})=>`${i}`.toLowerCase()===`${t}`.toLowerCase())||{}).value||r,B=({value:t,options:e=[],defaultValue:r=""})=>(e.find(({key:i})=>`${i}`.toLowerCase()!==`${t}`.toLowerCase())||{}).value||r,U=({value:t,options:e=[],defaultValue:r=""})=>(e.sort((o,n)=>+o.key-+n.key).find(({key:o})=>+t<+o)||{}).value||r,q=({value:t,options:e=[],defaultValue:r=""})=>(e.sort((o,n)=>+n.key-+o.key).find(({key:o})=>+t>+o)||{}).value||r,G=({value:t,options:e=[],defaultValue:r=""})=>p({value:t,options:e,defaultValue:U({value:t,options:e,defaultValue:r})}),H=({value:t,options:e=[],defaultValue:r=""})=>p({value:t,options:e,defaultValue:q({value:t,options:e,defaultValue:r})}),J=({value:t,props:e,defaultValue:r="",locale:i="",parserOptions:o})=>{if(!i)return"";let s=T("number",o),{maximumFractionDigits:n}=s,m=d(s,["maximumFractionDigits"]),c=(e==null?void 0:e.number)||{},{maximumFractionDigits:f=n||2}=c,a=d(c,["maximumFractionDigits"]);return new Intl.NumberFormat(i,u($(u({},m),{maximumFractionDigits:f}),a)).format(+t||+r)},Q=({value:t,props:e,defaultValue:r="",locale:i="",parserOptions:o})=>{if(!i)return"";let n=d(T("date",o),[]),m=d((e==null?void 0:e.date)||{},[]);return new Intl.DateTimeFormat(i,u(u({},n),m)).format(+t||+r)},P=[{key:"second",multiplier:1e3},{key:"minute",multiplier:60},{key:"hour",multiplier:60},{key:"day",multiplier:24},{key:"week",multiplier:7},{key:"month",multiplier:13/3},{key:"year",multiplier:12}],N=(t="",e="")=>new RegExp(`^${t}s?$`).test(e),S=t=>P.indexOf(P.find(({key:e})=>N(e,t))),W=(t,e)=>P.reduce(([r,i],{key:o,multiplier:n},m)=>{if(N(i,e))return[r,i];if(!i||m===S(i)+1){let f=Math.round(r/n);if(!i||Math.abs(f)>=1||e!=="auto")return[f,o]}return[r,i]},[t,""]),X=({value:t,defaultValue:e="",locale:r="",props:i,parserOptions:o})=>{if(!r)return"";let g=T("ago",o),{format:n,numeric:m}=g,f=d(g,["format","numeric"]),l=(i==null?void 0:i.ago)||{},{format:a=n||"auto",numeric:s=m||"auto"}=l,c=d(l,["format","numeric"]),x=+t||+e,M=W(x,a);return new Intl.RelativeTimeFormat(r,u($(u({},f),{numeric:s}),c)).format(...M)};var Y=t=>typeof t=="string"&&/{{(?:(?!{{|}}).)+}}/.test(t),D=t=>typeof t=="string"?t.replace(/\\(?=:|;|{|})/g,""):t,Z=({value:t,props:e,payload:r,parserOptions:i,locale:o})=>`${t}`.replace(/{{\s*(?:(?!{{|}}).)+\s*}}/g,n=>{let m=D(`${n.match(/(?!{|\s).+?(?!\\[:;]).(?=\s*(?:[:;]|}}$))/)}`),f=r==null?void 0:r[m],[,a=""]=n.match(/.+?(?!\\;).;\s*default\s*:\s*([^\s:;].+?(?:\\[:;]|[^;\s}])*)(?=\s*(?:;|}}$))/i)||[];a=a||(r==null?void 0:r.default)||"";let[,s=""]=n.match(/{{\s*(?:[^;]|(?:\\;))+\s*(?:(?!\\:).[:])\s*(?!\s)((?:\\;|[^;])+?)(?=\s*(?:[;]|}}$))/i)||[];if(f===void 0&&s!=="ne")return a;let c=!!s,{customModifiers:x}=i||{},M=u(u({},h),x||{});s=Object.keys(M).includes(s)?s:"eq";let g=M[s],l=(n.match(/[^\s:;{](?:[^;]|\\[;])+[^\s:;}]/gi)||[]).reduce((F,b,j)=>{if(j>0){let y=D(`${b.match(/(?:(?:\\:)|[^:])+/)}`.trim()),I=`${b.match(/(?:(?:\\:)|[^:])+$/)}`.trim();if(y&&y!=="default"&&I)return[...F,{key:y,value:I}]}return F},[]);return!c&&!l.length?f:g({value:f,options:l,props:e,defaultValue:a,locale:o,parserOptions:i})}),A=({value:t,props:e,payload:r,parserOptions:i,locale:o})=>{if(Y(t)){let n=Z({value:t,payload:r,props:e,parserOptions:i,locale:o});return A({value:n,payload:r,props:e,parserOptions:i,locale:o})}else return D(t)},_=t=>({parse:(e,[r,i],o,n)=>((r==null?void 0:r.default)&&e===void 0&&(e=`${r.default}`),e===void 0&&(e=`${n}`),A({value:e,payload:r,props:i,parserOptions:t,locale:o}))}),rt=_;export{rt as default}; |
{ | ||
"name": "@sveltekit-i18n/parser-default", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Default parser for sveltekit-i18n library.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -126,3 +126,3 @@ [![npm version](https://badge.fury.io/js/@sveltekit-i18n%2Fparser-default.svg)](https://badge.fury.io/js/@sveltekit-i18n%2Fparser-default) ![](https://github.com/sveltekit-i18n/parsers/workflows/Tests/badge.svg) [![Tests](https://github.com/sveltekit-i18n/parsers/actions/workflows/tests-parser-default.yml/badge.svg)](https://github.com/sveltekit-i18n/parsers/actions/workflows/tests-parser-default.yml) | ||
You are allowed to use nested `placeholders` and `modifiers` within your modifier definition or include your own modifiers in [Options](#options)! See `parser-default` example in [Examples](https://github.com/sveltekit-i18n/lib/tree/master/examples). | ||
You are allowed to use nested `placeholders` and `modifiers` within your modifier definition or include your own modifiers in [Options](#options)! See `parser-default` [example](https://github.com/sveltekit-i18n/lib/tree/master/examples/parser-default). | ||
@@ -132,3 +132,7 @@ | ||
## More info | ||
[Examples](https://github.com/sveltekit-i18n/lib/tree/master/examples)\ | ||
[Changelog](https://github.com/sveltekit-i18n/parsers/blob/master/parser-default/CHANGELOG.md) | ||
## Issues | ||
If you are facing issues with this parser, create a ticket [here](https://github.com/sveltekit-i18n/lib/issues). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
137
20584
115