intl-messageformat
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [5.4.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@5.3.0...intl-messageformat@5.4.0) (2019-07-25) | ||
### Features | ||
* **intl-messageformat:** allow mixed placeholder & XML together… ([#126](https://github.com/formatjs/formatjs/issues/126)) ([4a624c0](https://github.com/formatjs/formatjs/commit/4a624c0)) | ||
# [5.3.0](https://github.com/formatjs/formatjs/compare/intl-messageformat@5.2.0...intl-messageformat@5.3.0) (2019-07-25) | ||
@@ -8,0 +19,0 @@ |
@@ -33,3 +33,3 @@ import { MessageFormatElement } from 'intl-messageformat-parser'; | ||
export declare function formatToString(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType>, originalMessage?: string): string; | ||
export declare type FormatXMLElementFn = (str?: string) => string | object; | ||
export declare type FormatXMLElementFn = (...args: any[]) => string | object; | ||
export declare function formatXMLMessage(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | object | FormatXMLElementFn>, originalMessage?: string): Array<string | object>; |
@@ -162,2 +162,8 @@ "use strict"; | ||
var domParser; | ||
var TOKEN_DELIMITER = '@@'; | ||
var TOKEN_REGEX = /@@(.*)@@/; | ||
var counter = 0; | ||
function generateId() { | ||
return Date.now() + "_" + ++counter; | ||
} | ||
function formatXMLMessage(els, locales, formatters, formats, values, | ||
@@ -167,3 +173,11 @@ // For debugging | ||
var parts = formatToParts(els, locales, formatters, formats, values, originalMessage); | ||
var formattedMessage = parts.reduce(function (all, part) { return (all += part.value); }, ''); | ||
var objectParts = {}; | ||
var formattedMessage = parts.reduce(function (all, part) { | ||
if (typeof part.value === 'string' || part.type === 0 /* literal */) { | ||
return (all += part.value); | ||
} | ||
var id = generateId(); | ||
objectParts[id] = part.value; | ||
return (all += "" + TOKEN_DELIMITER + id + TOKEN_DELIMITER); | ||
}, ''); | ||
// Not designed to filter out aggressively | ||
@@ -196,26 +210,34 @@ if (!~formattedMessage.indexOf('<')) { | ||
} | ||
var reconstructedChunks = []; | ||
for (var i = 0; i < content.childNodes.length; i++) { | ||
var node = content.childNodes[i]; | ||
var tagName = node.tagName; | ||
var childNodes = Array.prototype.slice.call(content.childNodes); | ||
return childNodes.reduce(function (reconstructedChunks, _a) { | ||
var tagName = _a.tagName, outerHTML = _a.outerHTML, textContent = _a.textContent; | ||
// Regular text | ||
if (!tagName) { | ||
// Regular text | ||
reconstructedChunks.push(node.textContent || ''); | ||
var chunks = (textContent || '').split(TOKEN_REGEX).filter(Boolean); | ||
return reconstructedChunks.concat.apply(reconstructedChunks, chunks.map(function (c) { return objectParts[c] || c; })); | ||
} | ||
else if (!values[tagName]) { | ||
// Legacy HTML | ||
reconstructedChunks.push(node.outerHTML); | ||
// Legacy HTML | ||
if (!values[tagName]) { | ||
var chunks = outerHTML.split(TOKEN_REGEX).filter(Boolean); | ||
if (chunks.length === 1) { | ||
return reconstructedChunks.concat([chunks[0]]); | ||
} | ||
return reconstructedChunks.concat.apply(reconstructedChunks, chunks.map(function (c) { return objectParts[c] || c; })); | ||
} | ||
else { | ||
var formatFnOrValue = values[tagName]; | ||
if (typeof formatFnOrValue === 'function') { | ||
reconstructedChunks.push(formatFnOrValue(node.textContent || undefined)); | ||
// XML Tag replacement | ||
var formatFnOrValue = values[tagName]; | ||
if (typeof formatFnOrValue === 'function') { | ||
if (textContent == null) { | ||
return reconstructedChunks.concat([ | ||
formatFnOrValue(textContent || undefined) | ||
]); | ||
} | ||
else { | ||
reconstructedChunks.push(formatFnOrValue); | ||
} | ||
var chunks = textContent.split(TOKEN_REGEX).filter(Boolean); | ||
return reconstructedChunks.concat([ | ||
formatFnOrValue.apply(void 0, chunks.map(function (c) { return objectParts[c] || c; })) | ||
]); | ||
} | ||
} | ||
return reconstructedChunks; | ||
return reconstructedChunks.concat([formatFnOrValue]); | ||
}, []); | ||
} | ||
exports.formatXMLMessage = formatXMLMessage; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).IntlMessageFormat={})}(this,function(e){"use strict";var ft,t;function v(e){return e.type===ft.literal}function d(e){return e.type===ft.argument}function y(e){return e.type===ft.number}function g(e){return e.type===ft.date}function b(e){return e.type===ft.time}function A(e){return e.type===ft.select}function w(e){return e.type===ft.plural}(t=ft=ft||{})[t.literal=0]="literal",t[t.argument=1]="argument",t[t.number=2]="number",t[t.date=3]="date",t[t.time=4]="time",t[t.select=5]="select",t[t.plural=6]="plural";var n,u,r=(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),pt=function(){return(pt=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},ht=(u=Error,r(a,u),a.buildMessage=function(e,t){function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function n(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function o(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function u(e){switch(e.type){case"literal":return'"'+n(e.text)+'"';case"class":var t=e.parts.map(function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)});return"["+(e.inverted?"^":"")+t+"]";case"any":return"any character";case"end":return"end of input";case"other":return e.description}}return"Expected "+function(e){var t,r,n=e.map(u);if(n.sort(),0<n.length){for(r=t=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+((a=t)?'"'+n(a)+'"':"end of input")+" found.";var a},a);function a(e,t,r,n){var o=u.call(this)||this;return o.message=e,o.expected=t,o.found=r,o.location=n,o.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(o,a),o}var f=function(f,e){e=void 0!==e?e:{};var t,r,n,o,p={},u={start:Ge},a=Ge,i=function(e){return e.reduce(function(e,t){return e.concat(t)},[]).join("")},s=function(e){return pt({type:ft.literal,value:e},lt())},c=function(e){return e.join("")},l=Ue("argumentElement"),h="{",m=Ze("{",!1),v="}",d=Ze("}",!1),y=function(e){return pt({type:ft.argument,value:e},lt())},g=",",b=Ze(",",!1),A="number",w=Ze("number",!1),C="date",O=Ze("date",!1),x="time",_=Ze("time",!1),j=function(e,t,r){return pt({type:"number"===t?ft.number:"date"===t?ft.date:ft.time,style:r&&r[2],value:e},lt())},F="plural",T=Ze("plural",!1),M="selectordinal",E=Ze("selectordinal",!1),P="offset:",N=Ze("offset:",!1),k=function(e,t,r,n){return pt({type:ft.plural,pluralType:"plural"===t?"cardinal":"ordinal",value:e,offset:r?r[2]:0,options:n.reduce(function(e,t){var r=t.id,n=t.value,o=t.location;return e[r]={value:n,location:o},e},{})},lt())},I="select",R=Ze("select",!1),L=function(e,t){return pt({type:ft.select,value:e,options:t.reduce(function(e,t){var r=t.id,n=t.value,o=t.location;return e[r]={value:n,location:o},e},{})},lt())},S="=0",D=Ze("=0",!1),X="=1",z=Ze("=1",!1),B="=2",H=Ze("=2",!1),Z="zero",J=Ze("zero",!1),U="one",W=Ze("one",!1),$="two",q=Ze("two",!1),G="few",K=Ze("few",!1),Q="many",V=Ze("many",!1),Y="other",ee=Ze("other",!1),te=function(e,t){return pt({id:e,value:t},lt())},re=function(e,t){return pt({id:e,value:t},lt())},ne=Ue("whitespace"),oe=/^[ \t\n\r]/,ue=Je([" ","\t","\n","\r"],!1,!1),ae=Ue("optionalWhitespace"),ie=/^[0-9]/,se=Je([["0","9"]],!1,!1),ce=/^[0-9a-f]/i,le=Je([["0","9"],["a","f"]],!1,!0),fe=function(e){return parseInt(e.join(""),10)},pe="'",he=Ze("'",!1),me=/^[ \t\n\r,.+={}#]/,ve=Je([" ","\t","\n","\r",",",".","+","=","{","}","#"],!1,!1),de={type:"any"},ye=function(e){return e},ge=function(e){return e},be=Ue("apostrophe"),Ae=/^[^{}\\\0-\x1F\x7F \t\n\r]/,we=Je(["{","}","\\",["\0",""],""," ","\t","\n","\r"],!0,!1),Ce="\\\\",Oe=Ze("\\\\",!1),xe=function(){return"\\"},_e="\\#",je=Ze("\\#",!1),Fe=function(){return"\\#"},Te="\\{",Me=Ze("\\{",!1),Ee=function(){return"{"},Pe="\\}",Ne=Ze("\\}",!1),ke=function(){return"}"},Ie="\\u",Re=Ze("\\u",!1),Le=function(e){return String.fromCharCode(parseInt(e,16))},Se=0,De=0,Xe=[{line:1,column:1}],ze=0,Be=[],He=0;if(void 0!==e.startRule){if(!(e.startRule in u))throw new Error("Can't start parsing from rule \""+e.startRule+'".');a=u[e.startRule]}function Ze(e,t){return{type:"literal",text:e,ignoreCase:t}}function Je(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function Ue(e){return{type:"other",description:e}}function We(e){var t,r=Xe[e];if(r)return r;for(t=e-1;!Xe[t];)t--;for(r={line:(r=Xe[t]).line,column:r.column};t<e;)10===f.charCodeAt(t)?(r.line++,r.column=1):r.column++,t++;return Xe[e]=r}function $e(e,t){var r=We(e),n=We(t);return{start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function qe(e){Se<ze||(ze<Se&&(ze=Se,Be=[]),Be.push(e))}function Ge(){return Ke()}function Ke(){var e,t;for(e=[],t=Qe();t!==p;)e.push(t),t=Qe();return e}function Qe(){var e;return(e=function(){var e,t;e=Se,(t=function(){var e,t,r,n,o,u;t=[],r=e=Se,r=(n=rt())!==p?(o=ct(),o!==p?(u=rt())!==p?n=[n,o,u]:(Se=r,p):(Se=r,p)):(Se=r,p);if(r!==p)for(;r!==p;)t.push(r),r=Se,n=rt(),r=n!==p?(o=ct())!==p?(u=rt())!==p?n=[n,o,u]:(Se=r,p):(Se=r,p):(Se=r,p);else t=p;t!==p&&(De=e,t=i(t));(e=t)===p&&(e=Se,t=tt(),e=t!==p?f.substring(e,Se):t);return e}())!==p&&(De=e,t=s(t));return e=t}())===p&&(e=function(){var e,t,r,n,o;He++,e=Se,123===f.charCodeAt(Se)?(t=h,Se++):(t=p,0===He&&qe(m));e=t!==p?(r=rt(),r!==p?(n=Ve())!==p?rt()!==p?(125===f.charCodeAt(Se)?(o=v,Se++):(o=p,0===He&&qe(d)),o!==p?(De=e,t=y(n)):(Se=e,p)):(Se=e,p):(Se=e,p):(Se=e,p)):(Se=e,p);He--,e===p&&(t=p,0===He&&qe(l));return e}())===p&&(e=function(){var e,t,r,n,o,u,a,i,s,c;e=Se,123===f.charCodeAt(Se)?(t=h,Se++):(t=p,0===He&&qe(m));e=t!==p?(r=rt(),r!==p?(n=Ve())!==p?rt()!==p?(44===f.charCodeAt(Se)?(o=g,Se++):(o=p,0===He&&qe(b)),o!==p?rt()!==p?(f.substr(Se,6)===A?(u=A,Se+=6):(u=p,0===He&&qe(w)),u===p&&(f.substr(Se,4)===C?(u=C,Se+=4):(u=p,0===He&&qe(O)),u===p&&(f.substr(Se,4)===x?(u=x,Se+=4):(u=p,0===He&&qe(_)))),u!==p?rt()!==p?(a=Se,44===f.charCodeAt(Se)?(i=g,Se++):(i=p,0===He&&qe(b)),(a=i!==p?(s=rt())!==p?(c=ct())!==p?i=[i,s,c]:(Se=a,p):(Se=a,p):(Se=a,p))===p&&(a=null),a!==p?(i=rt())!==p?(125===f.charCodeAt(Se)?(s=v,Se++):(s=p,0===He&&qe(d)),s!==p?(De=e,t=j(n,u,a)):(Se=e,p)):(Se=e,p):(Se=e,p)):(Se=e,p):(Se=e,p)):(Se=e,p):(Se=e,p)):(Se=e,p):(Se=e,p):(Se=e,p)):(Se=e,p);return e}())===p&&(e=function(){var e,t,r,n,o,u,a,i,s,c,l;e=Se,123===f.charCodeAt(Se)?(t=h,Se++):(t=p,0===He&&qe(m));if(t!==p)if(rt()!==p)if((r=Ve())!==p)if(rt()!==p)if(44===f.charCodeAt(Se)?(n=g,Se++):(n=p,0===He&&qe(b)),n!==p)if(rt()!==p)if(f.substr(Se,6)===F?(o=F,Se+=6):(o=p,0===He&&qe(T)),o===p&&(f.substr(Se,13)===M?(o=M,Se+=13):(o=p,0===He&&qe(E))),o!==p)if(rt()!==p)if(44===f.charCodeAt(Se)?(u=g,Se++):(u=p,0===He&&qe(b)),u!==p)if(rt()!==p)if(a=Se,f.substr(Se,7)===P?(i=P,Se+=7):(i=p,0===He&&qe(N)),(a=i!==p?(s=rt())!==p?(c=ut())!==p?i=[i,s,c]:(Se=a,p):(Se=a,p):(Se=a,p))===p&&(a=null),a!==p)if((i=rt())!==p){if(s=[],(c=et())!==p)for(;c!==p;)s.push(c),c=et();else s=p;e=s!==p?(c=rt())!==p?(125===f.charCodeAt(Se)?(l=v,Se++):(l=p,0===He&&qe(d)),l!==p?(De=e,t=k(r,o,a,s)):(Se=e,p)):(Se=e,p):(Se=e,p)}else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;return e}())===p&&(e=function(){var e,t,r,n,o,u,a,i,s;e=Se,123===f.charCodeAt(Se)?(t=h,Se++):(t=p,0===He&&qe(m));if(t!==p)if(rt()!==p)if((r=Ve())!==p)if(rt()!==p)if(44===f.charCodeAt(Se)?(n=g,Se++):(n=p,0===He&&qe(b)),n!==p)if(rt()!==p)if(f.substr(Se,6)===I?(o=I,Se+=6):(o=p,0===He&&qe(R)),o!==p)if(rt()!==p)if(44===f.charCodeAt(Se)?(u=g,Se++):(u=p,0===He&&qe(b)),u!==p)if(rt()!==p){if(a=[],(i=Ye())!==p)for(;i!==p;)a.push(i),i=Ye();else a=p;e=a!==p?(i=rt())!==p?(125===f.charCodeAt(Se)?(s=v,Se++):(s=p,0===He&&qe(d)),s!==p?(De=e,t=L(r,a)):(Se=e,p)):(Se=e,p):(Se=e,p)}else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;else Se=e,e=p;return e}()),e}function Ve(){var e,t,r;if((e=ut())===p){for(e=Se,t=[],r=at();r!==p;)t.push(r),r=at();t!==p&&(De=e,t=c(t)),e=t}return e}function Ye(){var e,t,r,n,o;return e=Se,e=rt()!==p&&(t=ct())!==p&&rt()!==p?(123===f.charCodeAt(Se)?(r=h,Se++):(r=p,0===He&&qe(m)),r!==p&&(n=Ke())!==p?(125===f.charCodeAt(Se)?(o=v,Se++):(o=p,0===He&&qe(d)),o!==p?(De=e,te(t,n)):(Se=e,p)):(Se=e,p)):(Se=e,p)}function et(){var e,t,r,n,o;return e=Se,e=rt()!==p&&(t=function(){var e;return f.substr(Se,2)===S?(e=S,Se+=2):(e=p,0===He&&qe(D)),e===p&&(f.substr(Se,2)===X?(e=X,Se+=2):(e=p,0===He&&qe(z)),e===p&&(f.substr(Se,2)===B?(e=B,Se+=2):(e=p,0===He&&qe(H)),e===p&&(f.substr(Se,4)===Z?(e=Z,Se+=4):(e=p,0===He&&qe(J)),e===p&&(f.substr(Se,3)===U?(e=U,Se+=3):(e=p,0===He&&qe(W)),e===p&&(f.substr(Se,3)===$?(e=$,Se+=3):(e=p,0===He&&qe(q)),e===p&&(f.substr(Se,3)===G?(e=G,Se+=3):(e=p,0===He&&qe(K)),e===p&&(f.substr(Se,4)===Q?(e=Q,Se+=4):(e=p,0===He&&qe(V)),e===p&&(f.substr(Se,5)===Y?(e=Y,Se+=5):(e=p,0===He&&qe(ee)))))))))),e}())!==p&&rt()!==p?(123===f.charCodeAt(Se)?(r=h,Se++):(r=p,0===He&&qe(m)),r!==p&&(n=Ke())!==p?(125===f.charCodeAt(Se)?(o=v,Se++):(o=p,0===He&&qe(d)),o!==p?(De=e,re(t,n)):(Se=e,p)):(Se=e,p)):(Se=e,p)}function tt(){var e,t;if(He++,e=[],oe.test(f.charAt(Se))?(t=f.charAt(Se),Se++):(t=p,0===He&&qe(ue)),t!==p)for(;t!==p;)e.push(t),oe.test(f.charAt(Se))?(t=f.charAt(Se),Se++):(t=p,0===He&&qe(ue));else e=p;return He--,e===p&&(t=p,0===He&&qe(ne)),e}function rt(){var e,t,r;for(He++,e=Se,t=[],r=tt();r!==p;)t.push(r),r=tt();return e=t!==p?f.substring(e,Se):t,He--,e===p&&(t=p,0===He&&qe(ae)),e}function nt(){var e;return ie.test(f.charAt(Se))?(e=f.charAt(Se),Se++):(e=p,0===He&&qe(se)),e}function ot(){var e;return ce.test(f.charAt(Se))?(e=f.charAt(Se),Se++):(e=p,0===He&&qe(le)),e}function ut(){var e,t,r;if(e=Se,t=[],(r=nt())!==p)for(;r!==p;)t.push(r),r=nt();else t=p;return t!==p&&(De=e,t=fe(t)),e=t}function at(){var e,t,r;return t=e=Se,He++,39===f.charCodeAt(Se)?(r=pe,Se++):(r=p,0===He&&qe(he)),r===p&&(me.test(f.charAt(Se))?(r=f.charAt(Se),Se++):(r=p,0===He&&qe(ve))),He--,(e=(t=r===p?void 0:(Se=t,p))!==p?(f.length>Se?(r=f.charAt(Se),Se++):(r=p,0===He&&qe(de)),r!==p?(De=e,t=ye(r)):(Se=e,p)):(Se=e,p))===p&&(e=Se,39===f.charCodeAt(Se)?(t=pe,Se++):(t=p,0===He&&qe(he)),e=t!==p&&(r=function(){var e;me.test(f.charAt(Se))?(e=f.charAt(Se),Se++):(e=p,0===He&&qe(ve));e===p&&(e=it());return e}())!==p?(De=e,t=ge(r)):(Se=e,p)),e}function it(){var e;return He++,39===f.charCodeAt(Se)?(e=pe,Se++):(e=p,0===He&&qe(he)),He--,e===p&&0===He&&qe(be),e}function st(){var e,t,r,n,o,u,a,i;return e=Se,39===f.charCodeAt(Se)?(t=pe,Se++):(t=p,0===He&&qe(he)),(e=t!==p&&(r=it())!==p?(De=e,t=ge(r)):(Se=e,p))===p&&(Ae.test(f.charAt(Se))?(e=f.charAt(Se),Se++):(e=p,0===He&&qe(we)),e===p&&(e=Se,f.substr(Se,2)===Ce?(t=Ce,Se+=2):(t=p,0===He&&qe(Oe)),t!==p&&(De=e,t=xe()),(e=t)===p&&(e=Se,f.substr(Se,2)===_e?(t=_e,Se+=2):(t=p,0===He&&qe(je)),t!==p&&(De=e,t=Fe()),(e=t)===p&&(e=Se,f.substr(Se,2)===Te?(t=Te,Se+=2):(t=p,0===He&&qe(Me)),t!==p&&(De=e,t=Ee()),(e=t)===p&&(e=Se,f.substr(Se,2)===Pe?(t=Pe,Se+=2):(t=p,0===He&&qe(Ne)),t!==p&&(De=e,t=ke()),(e=t)===p&&(e=Se,f.substr(Se,2)===Ie?(t=Ie,Se+=2):(t=p,0===He&&qe(Re)),e=t!==p?(n=r=Se,(r=(n=(o=ot())!==p&&(u=ot())!==p&&(a=ot())!==p&&(i=ot())!==p?o=[o,u,a,i]:(Se=n,p))!==p?f.substring(r,Se):n)!==p?(De=e,t=Le(r)):(Se=e,p)):(Se=e,p))))))),e}function ct(){var e,t,r;if(e=Se,t=[],(r=st())!==p)for(;r!==p;)t.push(r),r=st();else t=p;return t!==p&&(De=e,t=c(t)),e=t}function lt(){return e&&e.captureLocation?{location:$e(De,Se)}:{}}if((t=a())!==p&&Se===f.length)return t;throw t!==p&&Se<f.length&&qe({type:"end"}),r=Be,n=ze<f.length?f.charAt(ze):null,o=ze<f.length?$e(ze,ze+1):$e(ze,ze),new ht(ht.buildMessage(r,n),r,n,o)},p=/(^|[^\\])#/g;function i(e){return JSON.stringify(e.map(function(e){return e&&"object"==typeof e?function(r){return Object.keys(r).sort().map(function(e){var t;return(t={})[e]=r[e],t})}(e):e}))}var o,s,m,c=function(u,a){return void 0===a&&(a={}),function(){for(var e,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=i(t),o=n&&a[n];return o||(o=new((e=u).bind.apply(e,[void 0].concat(t))),n&&(a[n]=o)),o}},l=(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),C=/\\#/g,O=(s=Error,l(h,s),h);function h(e,t){var r=s.call(this,e)||this;return r.variableId=t,r}function x(e,t,r,n,o,u){if(1===e.length&&v(e[0]))return[{type:0,value:e[0].value.replace(C,"#")}];for(var a=[],i=0,s=e;i<s.length;i++){var c=s[i];if(v(c))a.push({type:0,value:c.value.replace(C,"#")});else{var l=c.value;if(!(o&&l in o))throw new O("The intl string context variable '"+l+"' was not provided to the string '"+u+"'");var f=o[l];if(d(c))f&&"string"!=typeof f&&"number"!=typeof f?a.push({type:1,value:f}):a.push({type:0,value:"string"==typeof f||"number"==typeof f?String(f):""});else if(g(c)){var p=c.style?n.date[c.style]:void 0;a.push({type:0,value:r.getDateTimeFormat(t,p).format(f)})}else if(b(c)){p=c.style?n.time[c.style]:void 0;a.push({type:0,value:r.getDateTimeFormat(t,p).format(f)})}else if(y(c)){p=c.style?n.number[c.style]:void 0;a.push({type:0,value:r.getNumberFormat(t,p).format(f)})}else if(A(c)){if(!(h=c.options[f]||c.options.other))throw new RangeError('Invalid values for "'+c.value+'": "'+f+'". Options are "'+Object.keys(c.options).join('", "')+'"');a.push.apply(a,x(h.value,t,r,n,o))}else if(w(c)){var h;if(!(h=c.options["="+f])){var m=r.getPluralRules(t,{type:c.pluralType}).select(f-(c.offset||0));h=c.options[m]||c.options.other}if(!h)throw new RangeError('Invalid values for "'+c.value+'": "'+f+'". Options are "'+Object.keys(c.options).join('", "')+'"');a.push.apply(a,x(h.value,t,r,n,o))}else;}}return function(e){return e.length<2?e:e.reduce(function(e,t){var r=e[e.length-1];return r&&0===r.type&&0===t.type?r.value+=t.value:e.push(t),e},[])}(a)}function _(e,t,r,n,o,u){var a=x(e,t,r,n,o,u);return 1===a.length?a[0].value:a.reduce(function(e,t){return e+t.value},"")}function j(e,t,r,n,o,u){var a=x(e,t,r,n,o,u).reduce(function(e,t){return e+t.value},"");if(!~a.indexOf("<"))return[a];if(!o)throw new O("Message has placeholders but no values was given");if("undefined"==typeof DOMParser)throw new O("Cannot format XML message without DOMParser");var i=(m=m||new DOMParser).parseFromString("<template>"+a+"</template>","application/xml");if(i.getElementsByTagName("parsererror").length)throw new O("Malformed XML message "+i.getElementsByTagName("parsererror")[0].innerHTML);var s=i.firstChild;if(!s)throw new O("Malformed XML message "+a);if(!Object.keys(o).filter(function(e){return!!i.getElementsByTagName(e).length}).length)return[a];for(var c=[],l=0;l<s.childNodes.length;l++){var f=s.childNodes[l],p=f.tagName;if(p)if(o[p]){var h=o[p];"function"==typeof h?c.push(h(f.textContent||void 0)):c.push(h)}else c.push(f.outerHTML);else c.push(f.textContent||"")}return c}var F=function(){return(F=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function T(r,n){return n?Object.keys(r).reduce(function(e,t){return e[t]=function(r,n){return n?F({},r||{},n||{},Object.keys(r).reduce(function(e,t){return e[t]=F({},r[t],n[t]||{}),e},{})):r}(r[t],n[t]),e},F({},r)):r}function M(e){return void 0===e&&(e={number:{},dateTime:{},pluralRules:{}}),{getNumberFormat:c(Intl.NumberFormat,e.number),getDateTimeFormat:c(Intl.DateTimeFormat,e.dateTime),getPluralRules:c(Intl.PluralRules,e.pluralRules)}}var E=(P.defaultLocale="en",P.__parse=void 0,P.formats={number:{currency:{style:"currency"},percent:{style:"percent"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},P);function P(e,t,r,n){var o=this;if(void 0===t&&(t=P.defaultLocale),this.formatterCache={number:{},dateTime:{},pluralRules:{}},this.format=function(e){return _(o.ast,o.locale,o.formatters,o.formats,e,o.message)},this.formatToParts=function(e){return x(o.ast,o.locale,o.formatters,o.formats,e,o.message)},this.formatXMLMessage=function(e){return j(o.ast,o.locale,o.formatters,o.formats,e,o.message)},this.resolvedOptions=function(){return{locale:o.locale}},this.getAst=function(){return o.ast},"string"==typeof e){if(this.message=e,!P.__parse)throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");this.ast=P.__parse(e)}else this.ast=e;if(!Array.isArray(this.ast))throw new TypeError("A message must be provided as a String or AST.");this.formats=T(P.formats,r),this.locale=function(e){"string"==typeof e&&(e=[e]);try{return Intl.NumberFormat.supportedLocalesOf(e,{localeMatcher:"best fit"})[0]}catch(e){return E.defaultLocale}}(t||[]),this.formatters=n&&n.formatters||M(this.formatterCache),function r(e,n,o,u){e.filter(function(e){return!d(e)&&!v(e)}).forEach(function(t){if(g(t)){var e=t.style?u.date[t.style]:void 0;return o.getDateTimeFormat(n,e)}return b(t)?(e=t.style?u.time[t.style]:void 0,o.getDateTimeFormat(n,e)):y(t)?(e=t.style?u.number[t.style]:void 0,o.getNumberFormat(n,e)):A(t)?Object.keys(t.options).forEach(function(e){return r(t.options[e].value,n,o,u)}):w(t)?(o.getPluralRules(n,{type:t.pluralType}),Object.keys(t.options).forEach(function(e){return r(t.options[e].value,n,o,u)})):void 0})}(this.ast,this.locale,this.formatters,this.formats)}E.__parse=function(e,t){var r=f(e,t);return t&&!1===t.normalizeHashtagInPlural||function l(e){e.forEach(function(c){w(c)&&Object.keys(c.options).forEach(function(e){for(var t,r=c.options[e],n=-1,o=void 0,u=0;u<r.value.length;u++){var a=r.value[u];if(v(a)&&p.test(a.value)){n=u,o=a;break}}if(o){var i=o.value.replace(p,"$1{"+c.value+", number}"),s=f(i);(t=r.value).splice.apply(t,[n,1].concat(s))}l(r.value)})})}(r),r},e.IntlMessageFormat=E,e.createDefaultFormatters=M,e.default=E,e.formatToParts=x,e.formatToString=_,e.formatXMLMessage=j,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).IntlMessageFormat={})}(this,function(e){"use strict";var ft,t;function v(e){return e.type===ft.literal}function d(e){return e.type===ft.argument}function y(e){return e.type===ft.number}function g(e){return e.type===ft.date}function b(e){return e.type===ft.time}function A(e){return e.type===ft.select}function w(e){return e.type===ft.plural}(t=ft=ft||{})[t.literal=0]="literal",t[t.argument=1]="argument",t[t.number=2]="number",t[t.date=3]="date",t[t.time=4]="time",t[t.select=5]="select",t[t.plural=6]="plural";var n,a,r=(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),pt=function(){return(pt=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},mt=(a=Error,r(u,a),u.buildMessage=function(e,t){function r(e){return e.charCodeAt(0).toString(16).toUpperCase()}function n(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function o(e){return e.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(e){return"\\x0"+r(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+r(e)})}function a(e){switch(e.type){case"literal":return'"'+n(e.text)+'"';case"class":var t=e.parts.map(function(e){return Array.isArray(e)?o(e[0])+"-"+o(e[1]):o(e)});return"["+(e.inverted?"^":"")+t+"]";case"any":return"any character";case"end":return"end of input";case"other":return e.description}}return"Expected "+function(e){var t,r,n=e.map(a);if(n.sort(),0<n.length){for(r=t=1;t<n.length;t++)n[t-1]!==n[t]&&(n[r]=n[t],r++);n.length=r}switch(n.length){case 1:return n[0];case 2:return n[0]+" or "+n[1];default:return n.slice(0,-1).join(", ")+", or "+n[n.length-1]}}(e)+" but "+((u=t)?'"'+n(u)+'"':"end of input")+" found.";var u},u);function u(e,t,r,n){var o=a.call(this)||this;return o.message=e,o.expected=t,o.found=r,o.location=n,o.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(o,u),o}var f=function(f,e){e=void 0!==e?e:{};var t,r,n,o,p={},a={start:Ge},u=Ge,i=function(e){return e.reduce(function(e,t){return e.concat(t)},[]).join("")},s=function(e){return pt({type:ft.literal,value:e},lt())},c=function(e){return e.join("")},l=Ue("argumentElement"),m="{",h=Ze("{",!1),v="}",d=Ze("}",!1),y=function(e){return pt({type:ft.argument,value:e},lt())},g=",",b=Ze(",",!1),A="number",w=Ze("number",!1),C="date",O=Ze("date",!1),x="time",_=Ze("time",!1),j=function(e,t,r){return pt({type:"number"===t?ft.number:"date"===t?ft.date:ft.time,style:r&&r[2],value:e},lt())},F="plural",T=Ze("plural",!1),M="selectordinal",E=Ze("selectordinal",!1),P="offset:",k=Ze("offset:",!1),I=function(e,t,r,n){return pt({type:ft.plural,pluralType:"plural"===t?"cardinal":"ordinal",value:e,offset:r?r[2]:0,options:n.reduce(function(e,t){var r=t.id,n=t.value,o=t.location;return e[r]={value:n,location:o},e},{})},lt())},N="select",R=Ze("select",!1),L=function(e,t){return pt({type:ft.select,value:e,options:t.reduce(function(e,t){var r=t.id,n=t.value,o=t.location;return e[r]={value:n,location:o},e},{})},lt())},D="=0",S=Ze("=0",!1),B="=1",X=Ze("=1",!1),z="=2",H=Ze("=2",!1),Z="zero",J=Ze("zero",!1),U="one",W=Ze("one",!1),$="two",q=Ze("two",!1),G="few",K=Ze("few",!1),Q="many",V=Ze("many",!1),Y="other",ee=Ze("other",!1),te=function(e,t){return pt({id:e,value:t},lt())},re=function(e,t){return pt({id:e,value:t},lt())},ne=Ue("whitespace"),oe=/^[ \t\n\r]/,ae=Je([" ","\t","\n","\r"],!1,!1),ue=Ue("optionalWhitespace"),ie=/^[0-9]/,se=Je([["0","9"]],!1,!1),ce=/^[0-9a-f]/i,le=Je([["0","9"],["a","f"]],!1,!0),fe=function(e){return parseInt(e.join(""),10)},pe="'",me=Ze("'",!1),he=/^[ \t\n\r,.+={}#]/,ve=Je([" ","\t","\n","\r",",",".","+","=","{","}","#"],!1,!1),de={type:"any"},ye=function(e){return e},ge=function(e){return e},be=Ue("apostrophe"),Ae=/^[^{}\\\0-\x1F\x7F \t\n\r]/,we=Je(["{","}","\\",["\0",""],""," ","\t","\n","\r"],!0,!1),Ce="\\\\",Oe=Ze("\\\\",!1),xe=function(){return"\\"},_e="\\#",je=Ze("\\#",!1),Fe=function(){return"\\#"},Te="\\{",Me=Ze("\\{",!1),Ee=function(){return"{"},Pe="\\}",ke=Ze("\\}",!1),Ie=function(){return"}"},Ne="\\u",Re=Ze("\\u",!1),Le=function(e){return String.fromCharCode(parseInt(e,16))},De=0,Se=0,Be=[{line:1,column:1}],Xe=0,ze=[],He=0;if(void 0!==e.startRule){if(!(e.startRule in a))throw new Error("Can't start parsing from rule \""+e.startRule+'".');u=a[e.startRule]}function Ze(e,t){return{type:"literal",text:e,ignoreCase:t}}function Je(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function Ue(e){return{type:"other",description:e}}function We(e){var t,r=Be[e];if(r)return r;for(t=e-1;!Be[t];)t--;for(r={line:(r=Be[t]).line,column:r.column};t<e;)10===f.charCodeAt(t)?(r.line++,r.column=1):r.column++,t++;return Be[e]=r}function $e(e,t){var r=We(e),n=We(t);return{start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function qe(e){De<Xe||(Xe<De&&(Xe=De,ze=[]),ze.push(e))}function Ge(){return Ke()}function Ke(){var e,t;for(e=[],t=Qe();t!==p;)e.push(t),t=Qe();return e}function Qe(){var e;return(e=function(){var e,t;e=De,(t=function(){var e,t,r,n,o,a;t=[],r=e=De,r=(n=rt())!==p?(o=ct(),o!==p?(a=rt())!==p?n=[n,o,a]:(De=r,p):(De=r,p)):(De=r,p);if(r!==p)for(;r!==p;)t.push(r),r=De,n=rt(),r=n!==p?(o=ct())!==p?(a=rt())!==p?n=[n,o,a]:(De=r,p):(De=r,p):(De=r,p);else t=p;t!==p&&(Se=e,t=i(t));(e=t)===p&&(e=De,t=tt(),e=t!==p?f.substring(e,De):t);return e}())!==p&&(Se=e,t=s(t));return e=t}())===p&&(e=function(){var e,t,r,n,o;He++,e=De,123===f.charCodeAt(De)?(t=m,De++):(t=p,0===He&&qe(h));e=t!==p?(r=rt(),r!==p?(n=Ve())!==p?rt()!==p?(125===f.charCodeAt(De)?(o=v,De++):(o=p,0===He&&qe(d)),o!==p?(Se=e,t=y(n)):(De=e,p)):(De=e,p):(De=e,p):(De=e,p)):(De=e,p);He--,e===p&&(t=p,0===He&&qe(l));return e}())===p&&(e=function(){var e,t,r,n,o,a,u,i,s,c;e=De,123===f.charCodeAt(De)?(t=m,De++):(t=p,0===He&&qe(h));e=t!==p?(r=rt(),r!==p?(n=Ve())!==p?rt()!==p?(44===f.charCodeAt(De)?(o=g,De++):(o=p,0===He&&qe(b)),o!==p?rt()!==p?(f.substr(De,6)===A?(a=A,De+=6):(a=p,0===He&&qe(w)),a===p&&(f.substr(De,4)===C?(a=C,De+=4):(a=p,0===He&&qe(O)),a===p&&(f.substr(De,4)===x?(a=x,De+=4):(a=p,0===He&&qe(_)))),a!==p?rt()!==p?(u=De,44===f.charCodeAt(De)?(i=g,De++):(i=p,0===He&&qe(b)),(u=i!==p?(s=rt())!==p?(c=ct())!==p?i=[i,s,c]:(De=u,p):(De=u,p):(De=u,p))===p&&(u=null),u!==p?(i=rt())!==p?(125===f.charCodeAt(De)?(s=v,De++):(s=p,0===He&&qe(d)),s!==p?(Se=e,t=j(n,a,u)):(De=e,p)):(De=e,p):(De=e,p)):(De=e,p):(De=e,p)):(De=e,p):(De=e,p)):(De=e,p):(De=e,p):(De=e,p)):(De=e,p);return e}())===p&&(e=function(){var e,t,r,n,o,a,u,i,s,c,l;e=De,123===f.charCodeAt(De)?(t=m,De++):(t=p,0===He&&qe(h));if(t!==p)if(rt()!==p)if((r=Ve())!==p)if(rt()!==p)if(44===f.charCodeAt(De)?(n=g,De++):(n=p,0===He&&qe(b)),n!==p)if(rt()!==p)if(f.substr(De,6)===F?(o=F,De+=6):(o=p,0===He&&qe(T)),o===p&&(f.substr(De,13)===M?(o=M,De+=13):(o=p,0===He&&qe(E))),o!==p)if(rt()!==p)if(44===f.charCodeAt(De)?(a=g,De++):(a=p,0===He&&qe(b)),a!==p)if(rt()!==p)if(u=De,f.substr(De,7)===P?(i=P,De+=7):(i=p,0===He&&qe(k)),(u=i!==p?(s=rt())!==p?(c=at())!==p?i=[i,s,c]:(De=u,p):(De=u,p):(De=u,p))===p&&(u=null),u!==p)if((i=rt())!==p){if(s=[],(c=et())!==p)for(;c!==p;)s.push(c),c=et();else s=p;e=s!==p?(c=rt())!==p?(125===f.charCodeAt(De)?(l=v,De++):(l=p,0===He&&qe(d)),l!==p?(Se=e,t=I(r,o,u,s)):(De=e,p)):(De=e,p):(De=e,p)}else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;return e}())===p&&(e=function(){var e,t,r,n,o,a,u,i,s;e=De,123===f.charCodeAt(De)?(t=m,De++):(t=p,0===He&&qe(h));if(t!==p)if(rt()!==p)if((r=Ve())!==p)if(rt()!==p)if(44===f.charCodeAt(De)?(n=g,De++):(n=p,0===He&&qe(b)),n!==p)if(rt()!==p)if(f.substr(De,6)===N?(o=N,De+=6):(o=p,0===He&&qe(R)),o!==p)if(rt()!==p)if(44===f.charCodeAt(De)?(a=g,De++):(a=p,0===He&&qe(b)),a!==p)if(rt()!==p){if(u=[],(i=Ye())!==p)for(;i!==p;)u.push(i),i=Ye();else u=p;e=u!==p?(i=rt())!==p?(125===f.charCodeAt(De)?(s=v,De++):(s=p,0===He&&qe(d)),s!==p?(Se=e,t=L(r,u)):(De=e,p)):(De=e,p):(De=e,p)}else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;else De=e,e=p;return e}()),e}function Ve(){var e,t,r;if((e=at())===p){for(e=De,t=[],r=ut();r!==p;)t.push(r),r=ut();t!==p&&(Se=e,t=c(t)),e=t}return e}function Ye(){var e,t,r,n,o;return e=De,e=rt()!==p&&(t=ct())!==p&&rt()!==p?(123===f.charCodeAt(De)?(r=m,De++):(r=p,0===He&&qe(h)),r!==p&&(n=Ke())!==p?(125===f.charCodeAt(De)?(o=v,De++):(o=p,0===He&&qe(d)),o!==p?(Se=e,te(t,n)):(De=e,p)):(De=e,p)):(De=e,p)}function et(){var e,t,r,n,o;return e=De,e=rt()!==p&&(t=function(){var e;return f.substr(De,2)===D?(e=D,De+=2):(e=p,0===He&&qe(S)),e===p&&(f.substr(De,2)===B?(e=B,De+=2):(e=p,0===He&&qe(X)),e===p&&(f.substr(De,2)===z?(e=z,De+=2):(e=p,0===He&&qe(H)),e===p&&(f.substr(De,4)===Z?(e=Z,De+=4):(e=p,0===He&&qe(J)),e===p&&(f.substr(De,3)===U?(e=U,De+=3):(e=p,0===He&&qe(W)),e===p&&(f.substr(De,3)===$?(e=$,De+=3):(e=p,0===He&&qe(q)),e===p&&(f.substr(De,3)===G?(e=G,De+=3):(e=p,0===He&&qe(K)),e===p&&(f.substr(De,4)===Q?(e=Q,De+=4):(e=p,0===He&&qe(V)),e===p&&(f.substr(De,5)===Y?(e=Y,De+=5):(e=p,0===He&&qe(ee)))))))))),e}())!==p&&rt()!==p?(123===f.charCodeAt(De)?(r=m,De++):(r=p,0===He&&qe(h)),r!==p&&(n=Ke())!==p?(125===f.charCodeAt(De)?(o=v,De++):(o=p,0===He&&qe(d)),o!==p?(Se=e,re(t,n)):(De=e,p)):(De=e,p)):(De=e,p)}function tt(){var e,t;if(He++,e=[],oe.test(f.charAt(De))?(t=f.charAt(De),De++):(t=p,0===He&&qe(ae)),t!==p)for(;t!==p;)e.push(t),oe.test(f.charAt(De))?(t=f.charAt(De),De++):(t=p,0===He&&qe(ae));else e=p;return He--,e===p&&(t=p,0===He&&qe(ne)),e}function rt(){var e,t,r;for(He++,e=De,t=[],r=tt();r!==p;)t.push(r),r=tt();return e=t!==p?f.substring(e,De):t,He--,e===p&&(t=p,0===He&&qe(ue)),e}function nt(){var e;return ie.test(f.charAt(De))?(e=f.charAt(De),De++):(e=p,0===He&&qe(se)),e}function ot(){var e;return ce.test(f.charAt(De))?(e=f.charAt(De),De++):(e=p,0===He&&qe(le)),e}function at(){var e,t,r;if(e=De,t=[],(r=nt())!==p)for(;r!==p;)t.push(r),r=nt();else t=p;return t!==p&&(Se=e,t=fe(t)),e=t}function ut(){var e,t,r;return t=e=De,He++,39===f.charCodeAt(De)?(r=pe,De++):(r=p,0===He&&qe(me)),r===p&&(he.test(f.charAt(De))?(r=f.charAt(De),De++):(r=p,0===He&&qe(ve))),He--,(e=(t=r===p?void 0:(De=t,p))!==p?(f.length>De?(r=f.charAt(De),De++):(r=p,0===He&&qe(de)),r!==p?(Se=e,t=ye(r)):(De=e,p)):(De=e,p))===p&&(e=De,39===f.charCodeAt(De)?(t=pe,De++):(t=p,0===He&&qe(me)),e=t!==p&&(r=function(){var e;he.test(f.charAt(De))?(e=f.charAt(De),De++):(e=p,0===He&&qe(ve));e===p&&(e=it());return e}())!==p?(Se=e,t=ge(r)):(De=e,p)),e}function it(){var e;return He++,39===f.charCodeAt(De)?(e=pe,De++):(e=p,0===He&&qe(me)),He--,e===p&&0===He&&qe(be),e}function st(){var e,t,r,n,o,a,u,i;return e=De,39===f.charCodeAt(De)?(t=pe,De++):(t=p,0===He&&qe(me)),(e=t!==p&&(r=it())!==p?(Se=e,t=ge(r)):(De=e,p))===p&&(Ae.test(f.charAt(De))?(e=f.charAt(De),De++):(e=p,0===He&&qe(we)),e===p&&(e=De,f.substr(De,2)===Ce?(t=Ce,De+=2):(t=p,0===He&&qe(Oe)),t!==p&&(Se=e,t=xe()),(e=t)===p&&(e=De,f.substr(De,2)===_e?(t=_e,De+=2):(t=p,0===He&&qe(je)),t!==p&&(Se=e,t=Fe()),(e=t)===p&&(e=De,f.substr(De,2)===Te?(t=Te,De+=2):(t=p,0===He&&qe(Me)),t!==p&&(Se=e,t=Ee()),(e=t)===p&&(e=De,f.substr(De,2)===Pe?(t=Pe,De+=2):(t=p,0===He&&qe(ke)),t!==p&&(Se=e,t=Ie()),(e=t)===p&&(e=De,f.substr(De,2)===Ne?(t=Ne,De+=2):(t=p,0===He&&qe(Re)),e=t!==p?(n=r=De,(r=(n=(o=ot())!==p&&(a=ot())!==p&&(u=ot())!==p&&(i=ot())!==p?o=[o,a,u,i]:(De=n,p))!==p?f.substring(r,De):n)!==p?(Se=e,t=Le(r)):(De=e,p)):(De=e,p))))))),e}function ct(){var e,t,r;if(e=De,t=[],(r=st())!==p)for(;r!==p;)t.push(r),r=st();else t=p;return t!==p&&(Se=e,t=c(t)),e=t}function lt(){return e&&e.captureLocation?{location:$e(Se,De)}:{}}if((t=u())!==p&&De===f.length)return t;throw t!==p&&De<f.length&&qe({type:"end"}),r=ze,n=Xe<f.length?f.charAt(Xe):null,o=Xe<f.length?$e(Xe,Xe+1):$e(Xe,Xe),new mt(mt.buildMessage(r,n),r,n,o)},p=/(^|[^\\])#/g;function i(e){return JSON.stringify(e.map(function(e){return e&&"object"==typeof e?function(r){return Object.keys(r).sort().map(function(e){var t;return(t={})[e]=r[e],t})}(e):e}))}var o,s,m,c=function(a,u){return void 0===u&&(u={}),function(){for(var e,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];var n=i(t),o=n&&u[n];return o||(o=new((e=a).bind.apply(e,[void 0].concat(t))),n&&(u[n]=o)),o}},l=(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)},function(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),C=/\\#/g,O=(s=Error,l(h,s),h);function h(e,t){var r=s.call(this,e)||this;return r.variableId=t,r}function x(e,t,r,n,o,a){if(1===e.length&&v(e[0]))return[{type:0,value:e[0].value.replace(C,"#")}];for(var u=[],i=0,s=e;i<s.length;i++){var c=s[i];if(v(c))u.push({type:0,value:c.value.replace(C,"#")});else{var l=c.value;if(!(o&&l in o))throw new O("The intl string context variable '"+l+"' was not provided to the string '"+a+"'");var f=o[l];if(d(c))f&&"string"!=typeof f&&"number"!=typeof f?u.push({type:1,value:f}):u.push({type:0,value:"string"==typeof f||"number"==typeof f?String(f):""});else if(g(c)){var p=c.style?n.date[c.style]:void 0;u.push({type:0,value:r.getDateTimeFormat(t,p).format(f)})}else if(b(c)){p=c.style?n.time[c.style]:void 0;u.push({type:0,value:r.getDateTimeFormat(t,p).format(f)})}else if(y(c)){p=c.style?n.number[c.style]:void 0;u.push({type:0,value:r.getNumberFormat(t,p).format(f)})}else if(A(c)){if(!(m=c.options[f]||c.options.other))throw new RangeError('Invalid values for "'+c.value+'": "'+f+'". Options are "'+Object.keys(c.options).join('", "')+'"');u.push.apply(u,x(m.value,t,r,n,o))}else if(w(c)){var m;if(!(m=c.options["="+f])){var h=r.getPluralRules(t,{type:c.pluralType}).select(f-(c.offset||0));m=c.options[h]||c.options.other}if(!m)throw new RangeError('Invalid values for "'+c.value+'": "'+f+'". Options are "'+Object.keys(c.options).join('", "')+'"');u.push.apply(u,x(m.value,t,r,n,o))}else;}}return function(e){return e.length<2?e:e.reduce(function(e,t){var r=e[e.length-1];return r&&0===r.type&&0===t.type?r.value+=t.value:e.push(t),e},[])}(u)}function _(e,t,r,n,o,a){var u=x(e,t,r,n,o,a);return 1===u.length?u[0].value:u.reduce(function(e,t){return e+t.value},"")}var j="@@",F=/@@(.*)@@/,T=0;function M(e,t,r,n,i,o){var a=x(e,t,r,n,i,o),s={},u=a.reduce(function(e,t){if("string"==typeof t.value||0===t.type)return e+t.value;var r=Date.now()+"_"+ ++T;return s[r]=t.value,e+(j+r)+j},"");if(!~u.indexOf("<"))return[u];if(!i)throw new O("Message has placeholders but no values was given");if("undefined"==typeof DOMParser)throw new O("Cannot format XML message without DOMParser");var c=(m=m||new DOMParser).parseFromString("<template>"+u+"</template>","application/xml");if(c.getElementsByTagName("parsererror").length)throw new O("Malformed XML message "+c.getElementsByTagName("parsererror")[0].innerHTML);var l=c.firstChild;if(!l)throw new O("Malformed XML message "+u);return Object.keys(i).filter(function(e){return!!c.getElementsByTagName(e).length}).length?Array.prototype.slice.call(l.childNodes).reduce(function(e,t){var r=t.tagName,n=t.outerHTML,o=t.textContent;if(!r){var a=(o||"").split(F).filter(Boolean);return e.concat.apply(e,a.map(function(e){return s[e]||e}))}if(!i[r])return 1===(a=n.split(F).filter(Boolean)).length?e.concat([a[0]]):e.concat.apply(e,a.map(function(e){return s[e]||e}));var u=i[r];if("function"!=typeof u)return e.concat([u]);if(null==o)return e.concat([u(o||void 0)]);a=o.split(F).filter(Boolean);return e.concat([u.apply(void 0,a.map(function(e){return s[e]||e}))])},[]):[u]}var E=function(){return(E=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function P(r,n){return n?Object.keys(r).reduce(function(e,t){return e[t]=function(r,n){return n?E({},r||{},n||{},Object.keys(r).reduce(function(e,t){return e[t]=E({},r[t],n[t]||{}),e},{})):r}(r[t],n[t]),e},E({},r)):r}function k(e){return void 0===e&&(e={number:{},dateTime:{},pluralRules:{}}),{getNumberFormat:c(Intl.NumberFormat,e.number),getDateTimeFormat:c(Intl.DateTimeFormat,e.dateTime),getPluralRules:c(Intl.PluralRules,e.pluralRules)}}var I=(N.defaultLocale="en",N.__parse=void 0,N.formats={number:{currency:{style:"currency"},percent:{style:"percent"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},N);function N(e,t,r,n){var o=this;if(void 0===t&&(t=N.defaultLocale),this.formatterCache={number:{},dateTime:{},pluralRules:{}},this.format=function(e){return _(o.ast,o.locale,o.formatters,o.formats,e,o.message)},this.formatToParts=function(e){return x(o.ast,o.locale,o.formatters,o.formats,e,o.message)},this.formatXMLMessage=function(e){return M(o.ast,o.locale,o.formatters,o.formats,e,o.message)},this.resolvedOptions=function(){return{locale:o.locale}},this.getAst=function(){return o.ast},"string"==typeof e){if(this.message=e,!N.__parse)throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");this.ast=N.__parse(e)}else this.ast=e;if(!Array.isArray(this.ast))throw new TypeError("A message must be provided as a String or AST.");this.formats=P(N.formats,r),this.locale=function(e){"string"==typeof e&&(e=[e]);try{return Intl.NumberFormat.supportedLocalesOf(e,{localeMatcher:"best fit"})[0]}catch(e){return I.defaultLocale}}(t||[]),this.formatters=n&&n.formatters||k(this.formatterCache),function r(e,n,o,a){e.filter(function(e){return!d(e)&&!v(e)}).forEach(function(t){if(g(t)){var e=t.style?a.date[t.style]:void 0;return o.getDateTimeFormat(n,e)}return b(t)?(e=t.style?a.time[t.style]:void 0,o.getDateTimeFormat(n,e)):y(t)?(e=t.style?a.number[t.style]:void 0,o.getNumberFormat(n,e)):A(t)?Object.keys(t.options).forEach(function(e){return r(t.options[e].value,n,o,a)}):w(t)?(o.getPluralRules(n,{type:t.pluralType}),Object.keys(t.options).forEach(function(e){return r(t.options[e].value,n,o,a)})):void 0})}(this.ast,this.locale,this.formatters,this.formats)}I.__parse=function(e,t){var r=f(e,t);return t&&!1===t.normalizeHashtagInPlural||function l(e){e.forEach(function(c){w(c)&&Object.keys(c.options).forEach(function(e){for(var t,r=c.options[e],n=-1,o=void 0,a=0;a<r.value.length;a++){var u=r.value[a];if(v(u)&&p.test(u.value)){n=a,o=u;break}}if(o){var i=o.value.replace(p,"$1{"+c.value+", number}"),s=f(i);(t=r.value).splice.apply(t,[n,1].concat(s))}l(r.value)})})}(r),r},e.IntlMessageFormat=I,e.createDefaultFormatters=k,e.default=I,e.formatToParts=x,e.formatToString=_,e.formatXMLMessage=M,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=intl-messageformat.min.js.map |
@@ -33,3 +33,3 @@ import { MessageFormatElement } from 'intl-messageformat-parser'; | ||
export declare function formatToString(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType>, originalMessage?: string): string; | ||
export declare type FormatXMLElementFn = (str?: string) => string | object; | ||
export declare type FormatXMLElementFn = (...args: any[]) => string | object; | ||
export declare function formatXMLMessage(els: MessageFormatElement[], locales: string | string[], formatters: Formatters, formats: Formats, values?: Record<string, PrimitiveType | object | FormatXMLElementFn>, originalMessage?: string): Array<string | object>; |
@@ -158,2 +158,8 @@ var __extends = (this && this.__extends) || (function () { | ||
var domParser; | ||
var TOKEN_DELIMITER = '@@'; | ||
var TOKEN_REGEX = /@@(.*)@@/; | ||
var counter = 0; | ||
function generateId() { | ||
return Date.now() + "_" + ++counter; | ||
} | ||
export function formatXMLMessage(els, locales, formatters, formats, values, | ||
@@ -163,3 +169,11 @@ // For debugging | ||
var parts = formatToParts(els, locales, formatters, formats, values, originalMessage); | ||
var formattedMessage = parts.reduce(function (all, part) { return (all += part.value); }, ''); | ||
var objectParts = {}; | ||
var formattedMessage = parts.reduce(function (all, part) { | ||
if (typeof part.value === 'string' || part.type === 0 /* literal */) { | ||
return (all += part.value); | ||
} | ||
var id = generateId(); | ||
objectParts[id] = part.value; | ||
return (all += "" + TOKEN_DELIMITER + id + TOKEN_DELIMITER); | ||
}, ''); | ||
// Not designed to filter out aggressively | ||
@@ -192,25 +206,33 @@ if (!~formattedMessage.indexOf('<')) { | ||
} | ||
var reconstructedChunks = []; | ||
for (var i = 0; i < content.childNodes.length; i++) { | ||
var node = content.childNodes[i]; | ||
var tagName = node.tagName; | ||
var childNodes = Array.prototype.slice.call(content.childNodes); | ||
return childNodes.reduce(function (reconstructedChunks, _a) { | ||
var tagName = _a.tagName, outerHTML = _a.outerHTML, textContent = _a.textContent; | ||
// Regular text | ||
if (!tagName) { | ||
// Regular text | ||
reconstructedChunks.push(node.textContent || ''); | ||
var chunks = (textContent || '').split(TOKEN_REGEX).filter(Boolean); | ||
return reconstructedChunks.concat.apply(reconstructedChunks, chunks.map(function (c) { return objectParts[c] || c; })); | ||
} | ||
else if (!values[tagName]) { | ||
// Legacy HTML | ||
reconstructedChunks.push(node.outerHTML); | ||
// Legacy HTML | ||
if (!values[tagName]) { | ||
var chunks = outerHTML.split(TOKEN_REGEX).filter(Boolean); | ||
if (chunks.length === 1) { | ||
return reconstructedChunks.concat([chunks[0]]); | ||
} | ||
return reconstructedChunks.concat.apply(reconstructedChunks, chunks.map(function (c) { return objectParts[c] || c; })); | ||
} | ||
else { | ||
var formatFnOrValue = values[tagName]; | ||
if (typeof formatFnOrValue === 'function') { | ||
reconstructedChunks.push(formatFnOrValue(node.textContent || undefined)); | ||
// XML Tag replacement | ||
var formatFnOrValue = values[tagName]; | ||
if (typeof formatFnOrValue === 'function') { | ||
if (textContent == null) { | ||
return reconstructedChunks.concat([ | ||
formatFnOrValue(textContent || undefined) | ||
]); | ||
} | ||
else { | ||
reconstructedChunks.push(formatFnOrValue); | ||
} | ||
var chunks = textContent.split(TOKEN_REGEX).filter(Boolean); | ||
return reconstructedChunks.concat([ | ||
formatFnOrValue.apply(void 0, chunks.map(function (c) { return objectParts[c] || c; })) | ||
]); | ||
} | ||
} | ||
return reconstructedChunks; | ||
return reconstructedChunks.concat([formatFnOrValue]); | ||
}, []); | ||
} |
{ | ||
"name": "intl-messageformat", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "Formats ICU Message strings with number, date, plural, and select placeholders to create localized messages.", | ||
@@ -53,3 +53,3 @@ "keywords": [ | ||
"license": "BSD-3-Clause", | ||
"gitHead": "5c28b462ac096859747dfd24ad4fbfda406a844b" | ||
"gitHead": "84ec48b28f7ce7d3520c629e1519cfe8afd4050b" | ||
} |
@@ -238,6 +238,12 @@ import { | ||
export type FormatXMLElementFn = (str?: string) => string | object; | ||
export type FormatXMLElementFn = (...args: any[]) => string | object; | ||
// Singleton | ||
let domParser: DOMParser; | ||
const TOKEN_DELIMITER = '@@'; | ||
const TOKEN_REGEX = /@@(.*)@@/; | ||
let counter = 0; | ||
function generateId() { | ||
return `${Date.now()}_${++counter}`; | ||
} | ||
@@ -261,3 +267,11 @@ export function formatXMLMessage( | ||
); | ||
const formattedMessage = parts.reduce((all, part) => (all += part.value), ''); | ||
const objectParts: Record<string, ArgumentPart['value']> = {}; | ||
const formattedMessage = parts.reduce((all, part) => { | ||
if (typeof part.value === 'string' || part.type === PART_TYPE.literal) { | ||
return (all += part.value); | ||
} | ||
const id = generateId(); | ||
objectParts[id] = part.value; | ||
return (all += `${TOKEN_DELIMITER}${id}${TOKEN_DELIMITER}`); | ||
}, ''); | ||
@@ -302,24 +316,42 @@ // Not designed to filter out aggressively | ||
const reconstructedChunks: Array<string | object> = []; | ||
for (let i = 0; i < content.childNodes.length; i++) { | ||
const node = content.childNodes[i] as Element; | ||
const { tagName } = node; | ||
if (!tagName) { | ||
const childNodes = Array.prototype.slice.call(content.childNodes); | ||
return childNodes.reduce( | ||
(reconstructedChunks, { tagName, outerHTML, textContent }: Element) => { | ||
// Regular text | ||
reconstructedChunks.push(node.textContent || ''); | ||
} else if (!values[tagName]) { | ||
if (!tagName) { | ||
const chunks = (textContent || '').split(TOKEN_REGEX).filter(Boolean); | ||
return reconstructedChunks.concat( | ||
...chunks.map(c => objectParts[c] || c) | ||
); | ||
} | ||
// Legacy HTML | ||
reconstructedChunks.push(node.outerHTML); | ||
} else { | ||
if (!values[tagName]) { | ||
const chunks = outerHTML.split(TOKEN_REGEX).filter(Boolean); | ||
if (chunks.length === 1) { | ||
return reconstructedChunks.concat([chunks[0]]); | ||
} | ||
return reconstructedChunks.concat( | ||
...chunks.map(c => objectParts[c] || c) | ||
); | ||
} | ||
// XML Tag replacement | ||
const formatFnOrValue = values[tagName]; | ||
if (typeof formatFnOrValue === 'function') { | ||
reconstructedChunks.push( | ||
formatFnOrValue(node.textContent || undefined) | ||
); | ||
} else { | ||
reconstructedChunks.push(formatFnOrValue as object); | ||
if (textContent == null) { | ||
return reconstructedChunks.concat([ | ||
formatFnOrValue(textContent || undefined) | ||
]); | ||
} | ||
const chunks = textContent.split(TOKEN_REGEX).filter(Boolean); | ||
return reconstructedChunks.concat([ | ||
formatFnOrValue(...chunks.map(c => objectParts[c] || c)) | ||
]); | ||
} | ||
} | ||
} | ||
return reconstructedChunks; | ||
return reconstructedChunks.concat([formatFnOrValue as object]); | ||
}, | ||
[] | ||
); | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
516974
4247