@sveltekit-i18n/parser-mf2 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -359,7 +359,7 @@ A report carries `code`, the `key` and `locale` the call was made for, a one-sen
|
|
|
359
359
|
|
|
360
360
|
| `code` | When |
|
|
361
361
|
| --- | --- |
|
|
362
|
-
| `failed-message` | The message could not be compiled - a syntax error, or a data model error such as a selector without an annotation or a `.match` without a `*` variant - or could not be formatted at all. The raw message is returned. |
|
|
362
|
+
| `failed-message` | The message could not be compiled - a syntax error, or a data model error such as a selector without an annotation or a `.match` without a `*` variant - or could not be formatted at all. The raw message is returned; a leaf that is not text and cannot become any renders as the empty string. |
|
|
363
363
|
| `fallback-value` | One expression could not be resolved: a variable the payload lacks, a function nobody registered, or a function that rejected its operand or options. The rest of the message rendered, and the output carries the format's fallback for that expression, `{$name}`. |
|
|
364
364
|
|
|
365
365
|
```javascript
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{MessageFormat as b}from"messageformat";import{DraftFunctions as
|
|
1
|
+
import{MessageFormat as b}from"messageformat";import{DraftFunctions as K}from"messageformat/functions";import{parseMessage as k,validate as v}from"messageformat";var w=o=>{switch(o){case"number":case"integer":case"offset":case"currency":case"percent":case"unit":return"number";case"string":return"string";case"date":case"datetime":case"time":return"date";default:return"unknown"}},B=/^-?(?:0|[1-9]\d*)(?:\.\d+)?$/,x=(o,a)=>{let m=Array.isArray(o)?o:[o],p=a==="unknown"?m:[...m.filter(u=>u!=="unknown"),a],s=[...new Set(p)];return s.length===1?s[0]:s},E=()=>o=>{if(typeof o!="string")return[];let a;try{a=k(o),v(a)}catch{return[]}let m=new Map,p=e=>m.get(e)??{param:e};a.declarations.forEach(({type:e,name:n,value:{arg:r,functionRef:t}})=>{let d=e==="input"?{param:n}:r?.type==="variable"?p(r.name):{};m.set(n,{param:d.param,fn:t?.name??d.fn})});let s=[],u=new Map,y=(e,n,r,t)=>{let d=u.get(e);if(d===void 0){s.push(e),u.set(e,{name:e,kind:n,...t?{values:t}:{},optional:r.length>0,...r.length>0?{when:r}:{}});return}let{when:h,...P}=d,g=r.length>0&&h!==void 0;u.set(e,{...P,kind:x(d.kind??"unknown",n),...t?{values:[...new Set([...d.values??[],...t])]}:{},optional:g,...g?{when:h}:{}})},i=(e,n)=>{Object.values(e??{}).forEach(r=>{if(r.type!=="variable")return;let{param:t}=p(r.name);t!==void 0&&y(t,"unknown",n)})},l=({arg:e,functionRef:n},r)=>{if(e?.type==="variable"){let{param:t}=p(e.name);t!==void 0&&y(t,w(n?.name),r)}i(n?.options,r)},f=(e,n)=>{e.forEach(r=>{if(typeof r!="string"){if(r.type==="markup"){i(r.options,n);return}l(r,n)}})};if(a.declarations.forEach(({value:e})=>l(e,[])),a.type==="message")return f(a.pattern,[]),s.map(e=>u.get(e));let c=a.selectors.map(({name:e},n)=>{let{param:r,fn:t}=p(e),d=w(t),h=a.variants.flatMap(({keys:g})=>{let M=g[n];return M?.type==="literal"?[M.value]:[]}),P=d==="string"?h:d==="number"?h.filter(g=>B.test(g)):[];return r!==void 0&&y(r,d,[],P.length>0?P:void 0),r??e});return a.variants.forEach(({keys:e,value:n})=>{f(n,e.map((r,t)=>({param:c[t],branch:r.type==="*"?"*":r.value})))}),s.map(e=>u.get(e))};var F=1e4,S=o=>{try{return String(o)}catch{return}},$=({onReport:o,functions:a,...m})=>{let p={...m,functions:{...K,...a}},s=new Map,u=i=>{if(o)try{o(i)}catch{return}},y=(i,l)=>{if(typeof i!="string")return new b(l,i,p);let f=`${l}\0${i}`,c=s.get(f);if(c===void 0){if(c=new b(l,i,p),s.size>=F){let e=s.keys().next().value;e!==void 0&&s.delete(e)}}else s.delete(f);return s.set(f,c),c};return{parse:(i,[l],f,c)=>{if(i===void 0)return"";try{return y(i,f).format(l,e=>{u({code:"fallback-value",key:c,locale:f,message:`An expression in the message for key '${c}' could not be resolved and was rendered as its fallback.`,error:e})})}catch(e){let n=S(i);return u({code:"failed-message",key:c,locale:f,message:n===void 0?`Message for key '${c}' could not be rendered as text.`:`Message for key '${c}' could not be formatted and was returned raw.`,error:e}),n??""}}}},L=$;export{L as default,E as extractParamsFactory};
|