intl-messageformat-parser
Advanced tools
Comparing version 3.2.6 to 3.3.0
@@ -6,2 +6,19 @@ # Change Log | ||
# [3.3.0](https://github.com/formatjs/formatjs/compare/intl-messageformat-parser@3.2.6...intl-messageformat-parser@3.3.0) (2019-11-25) | ||
### Bug Fixes | ||
* **intl-messageformat-parser:** exclude some more unsupported pattern ([07ec1d1](https://github.com/formatjs/formatjs/commit/07ec1d119169879617f17c542d6992c31ec85856)) | ||
### Features | ||
* **eslint-plugin-formatjs:** add supported-datetime-skeleton rules ([c121a9a](https://github.com/formatjs/formatjs/commit/c121a9a9a52f21fbe1fdfc70e31c0275efbd0f8d)) | ||
* **intl-messageformat:** add limited support for date time skeleton ([07795b9](https://github.com/formatjs/formatjs/commit/07795b9e5e0116ffaf5f410c4e1c1a375f86ba8a)) | ||
## [3.2.6](https://github.com/formatjs/formatjs/compare/intl-messageformat-parser@3.2.5...intl-messageformat-parser@3.2.6) (2019-11-25) | ||
@@ -8,0 +25,0 @@ |
@@ -5,3 +5,4 @@ import { IParseOptions } from './parser'; | ||
export * from './parser'; | ||
export * from './skeleton'; | ||
export declare type ParseOptions = Options & IParseOptions; | ||
export declare function parse(input: string, opts?: ParseOptions): MessageFormatElement[]; |
@@ -10,2 +10,3 @@ "use strict"; | ||
__export(require("./parser")); | ||
__export(require("./skeleton")); | ||
function parse(input, opts) { | ||
@@ -12,0 +13,0 @@ var els = parser_1.pegParse(input, opts); |
@@ -101,4 +101,4 @@ export declare enum TYPE { | ||
export declare function isPluralElement(el: MessageFormatElement): el is PluralElement; | ||
export declare function isNumberSkeleton(el: Skeleton): el is NumberSkeleton; | ||
export declare function isDateTimeSkeleton(el: Skeleton): el is DateTimeSkeleton; | ||
export declare function isNumberSkeleton(el: NumberElement['style']): el is NumberSkeleton; | ||
export declare function isDateTimeSkeleton(el?: DateElement['style'] | TimeElement['style']): el is DateTimeSkeleton; | ||
export declare function createLiteralElement(value: string): LiteralElement; | ||
@@ -105,0 +105,0 @@ export declare function createNumberElement(value: string, style?: string | null): NumberElement; |
@@ -66,7 +66,7 @@ "use strict"; | ||
function isNumberSkeleton(el) { | ||
return el.type === 0 /* number */; | ||
return !!(el && typeof el === 'object' && el.type === 0 /* number */); | ||
} | ||
exports.isNumberSkeleton = isNumberSkeleton; | ||
function isDateTimeSkeleton(el) { | ||
return el.type === 1 /* dateTime */; | ||
return !!(el && typeof el === 'object' && el.type === 1 /* dateTime */); | ||
} | ||
@@ -73,0 +73,0 @@ exports.isDateTimeSkeleton = isDateTimeSkeleton; |
@@ -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).IntlMessageFormatParser={})}(this,function(Pt){"use strict";var e;function f(e){return e.type===Pt.TYPE.literal}function n(e){return e.type===Pt.TYPE.select}function u(e){return e.type===Pt.TYPE.plural}(e=Pt.TYPE||(Pt.TYPE={}))[e.literal=0]="literal",e[e.argument=1]="argument",e[e.number=2]="number",e[e.date=3]="date",e[e.time=4]="time",e[e.select=5]="select",e[e.plural=6]="plural";var a,o,t=(a=function(e,t){return(a=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}a(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),Tt=function(){return(Tt=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var u in t=arguments[r])Object.prototype.hasOwnProperty.call(t,u)&&(e[u]=t[u]);return e}).apply(this,arguments)},Ft=(o=Error,t(c,o),c.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 u(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)?u(e[0])+"-"+u(e[1]):u(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 "+((o=t)?'"'+n(o)+'"':"end of input")+" found.";var o},c);function c(e,t,r,n){var u=o.call(this)||this;return u.message=e,u.expected=t,u.found=r,u.location=n,u.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(u,c),u}var p=function(f,e){e=void 0!==e?e:{};var t,r,n,u,p={},a={start:rt},o=rt,c=function(e){return e.join("")},i=function(e){return Tt({type:Pt.TYPE.literal,value:e},Ct())},l=We("argumentElement"),h="{",A=Qe("{",!1),v="}",d=Qe("}",!1),s=function(e){return Tt({type:Pt.TYPE.argument,value:e},Ct())},g=We("numberSkeletonId"),m=/^['\/{}]/,y=Ve(["'","/","{","}"],!1,!1),b={type:"any"},E=We("numberSkeletonTokenOption"),x="/",C=Qe("/",!1),P=function(e){return e},T=We("numberSkeletonToken"),F=function(e,t){return{stem:e,options:t}},Y=function(e){return Tt({type:0,tokens:e},Ct())},w="::",k=Qe("::",!1),O=function(e){return e},S=function(e){return e.replace(/\s*$/,"")},j=",",_=Qe(",",!1),B="number",D=Qe("number",!1),N=function(e,t,r){return Tt({type:"number"===t?Pt.TYPE.number:"date"===t?Pt.TYPE.date:Pt.TYPE.time,style:r&&r[2],value:e},Ct())},z="'",I=Qe("'",!1),M=/^[^']/,R=Ve(["'"],!0,!1),Z=/^[^a-zA-Z'{}]/,L=Ve([["a","z"],["A","Z"],"'","{","}"],!0,!1),$=/^[a-zA-Z]/,H=Ve([["a","z"],["A","Z"]],!1,!1),U=function(e){return Tt({type:1,pattern:e},Ct())},q="date",G=Qe("date",!1),J="time",K=Qe("time",!1),Q="plural",V=Qe("plural",!1),W="selectordinal",X=Qe("selectordinal",!1),ee="offset:",te=Qe("offset:",!1),re=function(e,t,r,n){return Tt({type:Pt.TYPE.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,u=t.location;return r in e&&Ke('Duplicate option "'+r+'" in plural element: "'+Ge()+'"',Je()),e[r]={value:n,location:u},e},{})},Ct())},ne="select",ue=Qe("select",!1),ae=function(e,t){return Tt({type:Pt.TYPE.select,value:e,options:t.reduce(function(e,t){var r=t.id,n=t.value,u=t.location;return r in e&&Ke('Duplicate option "'+r+'" in select element: "'+Ge()+'"',Je()),e[r]={value:n,location:u},e},{})},Ct())},oe="=",ce=Qe("=",!1),ie=function(e,t){return Tt({id:e,value:t},Ct())},le=function(e,t){return Tt({id:e,value:t},Ct())},se=We("whitespace pattern"),fe=/^[\t-\r \x85\u200E\u200F\u2028\u2029]/,pe=Ve([["\t","\r"]," "," ","","","\u2028","\u2029"],!1,!1),he=We("syntax pattern"),Ae=/^[!-\/:-@[-\^`{-~\xA1-\xA7\xA9\xAB\xAC\xAE\xB0\xB1\xB6\xBB\xBF\xD7\xF7\u2010-\u2027\u2030-\u203E\u2041-\u2053\u2055-\u205E\u2190-\u245F\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F\u3001-\u3003\u3008-\u3020\u3030\uFD3E\uFD3F\uFE45\uFE46]/,ve=Ve([["!","/"],[":","@"],["[","^"],"`",["{","~"],["¡","§"],"©","«","¬","®","°","±","¶","»","¿","×","÷",["‐","‧"],["‰","‾"],["⁁","⁓"],["⁕","⁞"],["←",""],["─","❵"],["➔","⯿"],["⸀",""],["、","〃"],["〈","〠"],"〰","﴾","﴿","﹅","﹆"],!1,!1),de=We("optional whitespace"),ge=We("number"),me="-",ye=Qe("-",!1),be=function(e,t){return t?e?-t:t:0},Ee=We("double apostrophes"),xe="''",Ce=Qe("''",!1),Pe=function(){return"'"},Te=/^[{}]/,Fe=Ve(["{","}"],!1,!1),Ye=function(e,t){return e+t.replace("''","'")},we=/^[^{}]/,ke=Ve(["{","}"],!0,!1),Oe=We("argNameOrNumber"),Se=We("argNumber"),je="0",_e=Qe("0",!1),Be=function(){return 0},De=/^[1-9]/,Ne=Ve([["1","9"]],!1,!1),ze=/^[0-9]/,Ie=Ve([["0","9"]],!1,!1),Me=function(e){return parseInt(e.join(""),10)},Re=We("argName"),Ze=0,Le=0,$e=[{line:1,column:1}],He=0,Ue=[],qe=0;if(void 0!==e.startRule){if(!(e.startRule in a))throw new Error("Can't start parsing from rule \""+e.startRule+'".');o=a[e.startRule]}function Ge(){return f.substring(Le,Ze)}function Je(){return et(Le,Ze)}function Ke(e,t){throw function(e,t){return new Ft(e,[],"",t)}(e,t=void 0!==t?t:et(Le,Ze))}function Qe(e,t){return{type:"literal",text:e,ignoreCase:t}}function Ve(e,t,r){return{type:"class",parts:e,inverted:t,ignoreCase:r}}function We(e){return{type:"other",description:e}}function Xe(e){var t,r=$e[e];if(r)return r;for(t=e-1;!$e[t];)t--;for(r={line:(r=$e[t]).line,column:r.column};t<e;)10===f.charCodeAt(t)?(r.line++,r.column=1):r.column++,t++;return $e[e]=r}function et(e,t){var r=Xe(e),n=Xe(t);return{start:{offset:e,line:r.line,column:r.column},end:{offset:t,line:n.line,column:n.column}}}function tt(e){Ze<He||(He<Ze&&(He=Ze,Ue=[]),Ue.push(e))}function rt(){return nt()}function nt(){var e,t;for(e=[],t=ut();t!==p;)e.push(t),t=ut();return e}function ut(){var e;return(e=function(){var e,t;e=Ze,(t=at())!==p&&(Le=e,t=i(t));return e=t}())===p&&(e=function(){var e,t,r,n,u;qe++,e=Ze,123===f.charCodeAt(Ze)?(t=h,Ze++):(t=p,0===qe&&tt(A));e=t!==p?(r=vt(),r!==p?(n=bt())!==p?vt()!==p?(125===f.charCodeAt(Ze)?(u=v,Ze++):(u=p,0===qe&&tt(d)),u!==p?(Le=e,t=s(n)):(Ze=e,p)):(Ze=e,p):(Ze=e,p):(Ze=e,p)):(Ze=e,p);qe--,e===p&&(t=p,0===qe&&tt(l));return e}())===p&&(e=function(){var e;(e=function(){var e,t,r,n,u,a,o,c,i,l;e=Ze,123===f.charCodeAt(Ze)?(t=h,Ze++):(t=p,0===qe&&tt(A));e=t!==p?(r=vt(),r!==p?(n=bt())!==p?vt()!==p?(44===f.charCodeAt(Ze)?(u=j,Ze++):(u=p,0===qe&&tt(_)),u!==p?vt()!==p?(f.substr(Ze,6)===B?(a=B,Ze+=6):(a=p,0===qe&&tt(D)),a!==p?vt()!==p?(o=Ze,44===f.charCodeAt(Ze)?(c=j,Ze++):(c=p,0===qe&&tt(_)),(o=c!==p?(i=vt())!==p?(l=function(){var e,t,r;e=Ze,f.substr(Ze,2)===w?(t=w,Ze+=2):(t=p,0===qe&&tt(k));e=t!==p?(r=function(){var e,t,r;if(e=Ze,t=[],(r=it())!==p)for(;r!==p;)t.push(r),r=it();else t=p;t!==p&&(Le=e,t=Y(t));return e=t}(),r!==p?(Le=e,t=O(r)):(Ze=e,p)):(Ze=e,p);e===p&&(e=Ze,(t=at())!==p&&(Le=e,t=S(t)),e=t);return e}())!==p?c=[c,i,l]:(Ze=o,p):(Ze=o,p):(Ze=o,p))===p&&(o=null),o!==p?(c=vt())!==p?(125===f.charCodeAt(Ze)?(i=v,Ze++):(i=p,0===qe&&tt(d)),i!==p?(Le=e,t=N(n,a,o)):(Ze=e,p)):(Ze=e,p):(Ze=e,p)):(Ze=e,p):(Ze=e,p)):(Ze=e,p):(Ze=e,p)):(Ze=e,p):(Ze=e,p):(Ze=e,p)):(Ze=e,p);return e}())===p&&(e=function(){var e,t,r,n,u,a,o,c,i,l;e=Ze,123===f.charCodeAt(Ze)?(t=h,Ze++):(t=p,0===qe&&tt(A));e=t!==p?(r=vt(),r!==p?(n=bt())!==p?vt()!==p?(44===f.charCodeAt(Ze)?(u=j,Ze++):(u=p,0===qe&&tt(_)),u!==p?vt()!==p?(f.substr(Ze,4)===q?(a=q,Ze+=4):(a=p,0===qe&&tt(G)),a===p&&(f.substr(Ze,4)===J?(a=J,Ze+=4):(a=p,0===qe&&tt(K))),a!==p?vt()!==p?(o=Ze,44===f.charCodeAt(Ze)?(c=j,Ze++):(c=p,0===qe&&tt(_)),(o=c!==p?(i=vt())!==p?(l=function(){var e,t,r;e=Ze,f.substr(Ze,2)===w?(t=w,Ze+=2):(t=p,0===qe&&tt(k));e=t!==p?(r=function(){var e,t,r,n;t=e=Ze,r=[],(n=lt())===p&&(n=st());if(n!==p)for(;n!==p;)r.push(n),(n=lt())===p&&(n=st());else r=p;t=r!==p?f.substring(t,Ze):r;t!==p&&(Le=e,t=U(t));return e=t}(),r!==p?(Le=e,t=O(r)):(Ze=e,p)):(Ze=e,p);e===p&&(e=Ze,(t=at())!==p&&(Le=e,t=S(t)),e=t);return e}())!==p?c=[c,i,l]:(Ze=o,p):(Ze=o,p):(Ze=o,p))===p&&(o=null),o!==p?(c=vt())!==p?(125===f.charCodeAt(Ze)?(i=v,Ze++):(i=p,0===qe&&tt(d)),i!==p?(Le=e,t=N(n,a,o)):(Ze=e,p)):(Ze=e,p):(Ze=e,p)):(Ze=e,p):(Ze=e,p)):(Ze=e,p):(Ze=e,p)):(Ze=e,p):(Ze=e,p):(Ze=e,p)):(Ze=e,p);return e}());return e}())===p&&(e=function(){var e,t,r,n,u,a,o,c,i,l,s;e=Ze,123===f.charCodeAt(Ze)?(t=h,Ze++):(t=p,0===qe&&tt(A));if(t!==p)if(vt()!==p)if((r=bt())!==p)if(vt()!==p)if(44===f.charCodeAt(Ze)?(n=j,Ze++):(n=p,0===qe&&tt(_)),n!==p)if(vt()!==p)if(f.substr(Ze,6)===Q?(u=Q,Ze+=6):(u=p,0===qe&&tt(V)),u===p&&(f.substr(Ze,13)===W?(u=W,Ze+=13):(u=p,0===qe&&tt(X))),u!==p)if(vt()!==p)if(44===f.charCodeAt(Ze)?(a=j,Ze++):(a=p,0===qe&&tt(_)),a!==p)if(vt()!==p)if(o=Ze,f.substr(Ze,7)===ee?(c=ee,Ze+=7):(c=p,0===qe&&tt(te)),(o=c!==p?(i=vt())!==p?(l=dt())!==p?c=[c,i,l]:(Ze=o,p):(Ze=o,p):(Ze=o,p))===p&&(o=null),o!==p)if((c=vt())!==p){if(i=[],(l=pt())!==p)for(;l!==p;)i.push(l),l=pt();else i=p;e=i!==p?(l=vt())!==p?(125===f.charCodeAt(Ze)?(s=v,Ze++):(s=p,0===qe&&tt(d)),s!==p?(Le=e,t=re(r,u,o,i)):(Ze=e,p)):(Ze=e,p):(Ze=e,p)}else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;return e}())===p&&(e=function(){var e,t,r,n,u,a,o,c,i;e=Ze,123===f.charCodeAt(Ze)?(t=h,Ze++):(t=p,0===qe&&tt(A));if(t!==p)if(vt()!==p)if((r=bt())!==p)if(vt()!==p)if(44===f.charCodeAt(Ze)?(n=j,Ze++):(n=p,0===qe&&tt(_)),n!==p)if(vt()!==p)if(f.substr(Ze,6)===ne?(u=ne,Ze+=6):(u=p,0===qe&&tt(ue)),u!==p)if(vt()!==p)if(44===f.charCodeAt(Ze)?(a=j,Ze++):(a=p,0===qe&&tt(_)),a!==p)if(vt()!==p){if(o=[],(c=ft())!==p)for(;c!==p;)o.push(c),c=ft();else o=p;e=o!==p?(c=vt())!==p?(125===f.charCodeAt(Ze)?(i=v,Ze++):(i=p,0===qe&&tt(d)),i!==p?(Le=e,t=ae(r,o)):(Ze=e,p)):(Ze=e,p):(Ze=e,p)}else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;else Ze=e,e=p;return e}()),e}function at(){var e,t,r;if(e=Ze,t=[],(r=gt())===p&&(r=mt())===p&&(r=yt()),r!==p)for(;r!==p;)t.push(r),(r=gt())===p&&(r=mt())===p&&(r=yt());else t=p;return t!==p&&(Le=e,t=c(t)),e=t}function ot(){var e,t,r,n,u;if(qe++,t=[],n=r=e=Ze,qe++,(u=ht())===p&&(m.test(f.charAt(Ze))?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(y))),qe--,(r=(n=u===p?void 0:(Ze=n,p))!==p?(f.length>Ze?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(b)),u!==p?n=[n,u]:(Ze=r,p)):(Ze=r,p))!==p)for(;r!==p;)t.push(r),n=r=Ze,qe++,(u=ht())===p&&(m.test(f.charAt(Ze))?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(y))),qe--,r=(n=u===p?void 0:(Ze=n,p))!==p?(f.length>Ze?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(b)),u!==p?n=[n,u]:(Ze=r,p)):(Ze=r,p);else t=p;return e=t!==p?f.substring(e,Ze):t,qe--,e===p&&(t=p,0===qe&&tt(g)),e}function ct(){var e,t,r;return qe++,e=Ze,47===f.charCodeAt(Ze)?(t=x,Ze++):(t=p,0===qe&&tt(C)),e=t!==p&&(r=ot())!==p?(Le=e,t=P(r)):(Ze=e,p),qe--,e===p&&(t=p,0===qe&&tt(E)),e}function it(){var e,t,r,n;if(qe++,e=Ze,vt()!==p)if((t=ot())!==p){for(r=[],n=ct();n!==p;)r.push(n),n=ct();e=r!==p?(Le=e,F(t,r)):(Ze=e,p)}else Ze=e,e=p;else Ze=e,e=p;return qe--,e===p&&(p,0===qe&&tt(T)),e}function lt(){var e,t,r,n;if(e=Ze,39===f.charCodeAt(Ze)?(t=z,Ze++):(t=p,0===qe&&tt(I)),t!==p){if(r=[],(n=gt())===p&&(M.test(f.charAt(Ze))?(n=f.charAt(Ze),Ze++):(n=p,0===qe&&tt(R))),n!==p)for(;n!==p;)r.push(n),(n=gt())===p&&(M.test(f.charAt(Ze))?(n=f.charAt(Ze),Ze++):(n=p,0===qe&&tt(R)));else r=p;e=r!==p?(39===f.charCodeAt(Ze)?(n=z,Ze++):(n=p,0===qe&&tt(I)),n!==p?t=[t,r,n]:(Ze=e,p)):(Ze=e,p)}else Ze=e,e=p;if(e===p)if(e=[],(t=gt())===p&&(Z.test(f.charAt(Ze))?(t=f.charAt(Ze),Ze++):(t=p,0===qe&&tt(L))),t!==p)for(;t!==p;)e.push(t),(t=gt())===p&&(Z.test(f.charAt(Ze))?(t=f.charAt(Ze),Ze++):(t=p,0===qe&&tt(L)));else e=p;return e}function st(){var e,t;if(e=[],$.test(f.charAt(Ze))?(t=f.charAt(Ze),Ze++):(t=p,0===qe&&tt(H)),t!==p)for(;t!==p;)e.push(t),$.test(f.charAt(Ze))?(t=f.charAt(Ze),Ze++):(t=p,0===qe&&tt(H));else e=p;return e}function ft(){var e,t,r,n,u;return e=Ze,e=vt()!==p&&(t=xt())!==p&&vt()!==p?(123===f.charCodeAt(Ze)?(r=h,Ze++):(r=p,0===qe&&tt(A)),r!==p&&(n=nt())!==p?(125===f.charCodeAt(Ze)?(u=v,Ze++):(u=p,0===qe&&tt(d)),u!==p?(Le=e,ie(t,n)):(Ze=e,p)):(Ze=e,p)):(Ze=e,p)}function pt(){var e,t,r,n,u;return e=Ze,e=vt()!==p&&(t=function(){var e,t,r,n;return t=e=Ze,61===f.charCodeAt(Ze)?(r=oe,Ze++):(r=p,0===qe&&tt(ce)),(e=(t=r!==p&&(n=dt())!==p?r=[r,n]:(Ze=t,p))!==p?f.substring(e,Ze):t)===p&&(e=xt()),e}())!==p&&vt()!==p?(123===f.charCodeAt(Ze)?(r=h,Ze++):(r=p,0===qe&&tt(A)),r!==p&&(n=nt())!==p?(125===f.charCodeAt(Ze)?(u=v,Ze++):(u=p,0===qe&&tt(d)),u!==p?(Le=e,le(t,n)):(Ze=e,p)):(Ze=e,p)):(Ze=e,p)}function ht(){var e;return qe++,fe.test(f.charAt(Ze))?(e=f.charAt(Ze),Ze++):(e=p,0===qe&&tt(pe)),qe--,e===p&&0===qe&&tt(se),e}function At(){var e;return qe++,Ae.test(f.charAt(Ze))?(e=f.charAt(Ze),Ze++):(e=p,0===qe&&tt(ve)),qe--,e===p&&0===qe&&tt(he),e}function vt(){var e,t,r;for(qe++,e=Ze,t=[],r=ht();r!==p;)t.push(r),r=ht();return e=t!==p?f.substring(e,Ze):t,qe--,e===p&&(t=p,0===qe&&tt(de)),e}function dt(){var e,t,r;return qe++,e=Ze,45===f.charCodeAt(Ze)?(t=me,Ze++):(t=p,0===qe&&tt(ye)),t===p&&(t=null),e=t!==p&&(r=Et())!==p?(Le=e,t=be(t,r)):(Ze=e,p),qe--,e===p&&(t=p,0===qe&&tt(ge)),e}function gt(){var e,t;return qe++,e=Ze,f.substr(Ze,2)===xe?(t=xe,Ze+=2):(t=p,0===qe&&tt(Ce)),t!==p&&(Le=e,t=Pe()),qe--,(e=t)===p&&(t=p,0===qe&&tt(Ee)),e}function mt(){var e,t,r,n,u,a;if(e=Ze,39===f.charCodeAt(Ze)?(t=z,Ze++):(t=p,0===qe&&tt(I)),t!==p)if(Te.test(f.charAt(Ze))?(r=f.charAt(Ze),Ze++):(r=p,0===qe&&tt(Fe)),r!==p){for(n=Ze,u=[],f.substr(Ze,2)===xe?(a=xe,Ze+=2):(a=p,0===qe&&tt(Ce)),a===p&&(M.test(f.charAt(Ze))?(a=f.charAt(Ze),Ze++):(a=p,0===qe&&tt(R)));a!==p;)u.push(a),f.substr(Ze,2)===xe?(a=xe,Ze+=2):(a=p,0===qe&&tt(Ce)),a===p&&(M.test(f.charAt(Ze))?(a=f.charAt(Ze),Ze++):(a=p,0===qe&&tt(R)));e=(n=u!==p?f.substring(n,Ze):u)!==p?(39===f.charCodeAt(Ze)?(u=z,Ze++):(u=p,0===qe&&tt(I)),u!==p?(Le=e,t=Ye(r,n)):(Ze=e,p)):(Ze=e,p)}else Ze=e,e=p;else Ze=e,e=p;return e}function yt(){var e,t;return e=Ze,we.test(f.charAt(Ze))?(t=f.charAt(Ze),Ze++):(t=p,0===qe&&tt(ke)),e=t!==p?f.substring(e,Ze):t}function bt(){var e,t;return qe++,e=Ze,(t=Et())===p&&(t=xt()),e=t!==p?f.substring(e,Ze):t,qe--,e===p&&(t=p,0===qe&&tt(Oe)),e}function Et(){var e,t,r,n,u;if(qe++,e=Ze,48===f.charCodeAt(Ze)?(t=je,Ze++):(t=p,0===qe&&tt(_e)),t!==p&&(Le=e,t=Be()),(e=t)===p){if(t=e=Ze,De.test(f.charAt(Ze))?(r=f.charAt(Ze),Ze++):(r=p,0===qe&&tt(Ne)),r!==p){for(n=[],ze.test(f.charAt(Ze))?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(Ie));u!==p;)n.push(u),ze.test(f.charAt(Ze))?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(Ie));t=n!==p?r=[r,n]:(Ze=t,p)}else Ze=t,t=p;t!==p&&(Le=e,t=Me(t)),e=t}return qe--,e===p&&(t=p,0===qe&&tt(Se)),e}function xt(){var e,t,r,n,u;if(qe++,t=[],n=r=e=Ze,qe++,(u=ht())===p&&(u=At()),qe--,(r=(n=u===p?void 0:(Ze=n,p))!==p?(f.length>Ze?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(b)),u!==p?n=[n,u]:(Ze=r,p)):(Ze=r,p))!==p)for(;r!==p;)t.push(r),n=r=Ze,qe++,(u=ht())===p&&(u=At()),qe--,r=(n=u===p?void 0:(Ze=n,p))!==p?(f.length>Ze?(u=f.charAt(Ze),Ze++):(u=p,0===qe&&tt(b)),u!==p?n=[n,u]:(Ze=r,p)):(Ze=r,p);else t=p;return e=t!==p?f.substring(e,Ze):t,qe--,e===p&&(t=p,0===qe&&tt(Re)),e}function Ct(){return e&&e.captureLocation?{location:Je()}:{}}if((t=o())!==p&&Ze===f.length)return t;throw t!==p&&Ze<f.length&&tt({type:"end"}),r=Ue,n=He<f.length?f.charAt(He):null,u=He<f.length?et(He,He+1):et(He,He),new Ft(Ft.buildMessage(r,n),r,n,u)},h=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),u=0;for(t=0;t<r;t++)for(var a=arguments[t],o=0,c=a.length;o<c;o++,u++)n[u]=a[o];return n},A=/(^|[^\\])#/g;Pt.SyntaxError=Ft,Pt.createLiteralElement=function(e){return{type:Pt.TYPE.literal,value:e}},Pt.createNumberElement=function(e,t){return{type:Pt.TYPE.number,value:e,style:t}},Pt.isArgumentElement=function(e){return e.type===Pt.TYPE.argument},Pt.isDateElement=function(e){return e.type===Pt.TYPE.date},Pt.isDateTimeSkeleton=function(e){return 1===e.type},Pt.isLiteralElement=f,Pt.isNumberElement=function(e){return e.type===Pt.TYPE.number},Pt.isNumberSkeleton=function(e){return 0===e.type},Pt.isPluralElement=u,Pt.isSelectElement=n,Pt.isTimeElement=function(e){return e.type===Pt.TYPE.time},Pt.parse=function(e,t){var r=p(e,t);return t&&!1===t.normalizeHashtagInPlural||function s(e){e.forEach(function(l){(u(l)||n(l))&&Object.keys(l.options).forEach(function(e){for(var t,r=l.options[e],n=-1,u=void 0,a=0;a<r.value.length;a++){var o=r.value[a];if(f(o)&&A.test(o.value)){n=a,u=o;break}}if(u){var c=u.value.replace(A,"$1{"+l.value+", number}"),i=p(c);(t=r.value).splice.apply(t,h([n,1],i))}s(r.value)})})}(r),r},Pt.pegParse=p,Object.defineProperty(Pt,"__esModule",{value:!0})}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).IntlMessageFormatParser={})}(this,function(Cr){"use strict";var e;function f(e){return e.type===Cr.TYPE.literal}function n(e){return e.type===Cr.TYPE.select}function a(e){return e.type===Cr.TYPE.plural}(e=Cr.TYPE||(Cr.TYPE={}))[e.literal=0]="literal",e[e.argument=1]="argument",e[e.number=2]="number",e[e.date=3]="date",e[e.time=4]="time",e[e.select=5]="select",e[e.plural=6]="plural";var u,o,r=(u=function(e,r){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)r.hasOwnProperty(t)&&(e[t]=r[t])})(e,r)},function(e,r){function t(){this.constructor=e}u(e,r),e.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}),kr=function(){return(kr=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var a in r=arguments[t])Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a]);return e}).apply(this,arguments)},Pr=(o=Error,r(c,o),c.buildMessage=function(e,r){function t(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"+t(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+t(e)})}function a(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"+t(e)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(e){return"\\x"+t(e)})}function u(e){switch(e.type){case"literal":return'"'+n(e.text)+'"';case"class":var r=e.parts.map(function(e){return Array.isArray(e)?a(e[0])+"-"+a(e[1]):a(e)});return"["+(e.inverted?"^":"")+r+"]";case"any":return"any character";case"end":return"end of input";case"other":return e.description}}return"Expected "+function(e){var r,t,n=e.map(u);if(n.sort(),0<n.length){for(t=r=1;r<n.length;r++)n[r-1]!==n[r]&&(n[t]=n[r],t++);n.length=t}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 "+((o=r)?'"'+n(o)+'"':"end of input")+" found.";var o},c);function c(e,r,t,n){var a=o.call(this)||this;return a.message=e,a.expected=r,a.found=t,a.location=n,a.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,c),a}var p=function(f,e){e=void 0!==e?e:{};var r,t,n,a,p={},u={start:tr},o=tr,c=function(e){return e.join("")},i=function(e){return kr({type:Cr.TYPE.literal,value:e},xr())},s=Ge("argumentElement"),h="{",d=Xe("{",!1),g="}",v=Xe("}",!1),l=function(e){return kr({type:Cr.TYPE.argument,value:e},xr())},A=Ge("numberSkeletonId"),m=/^['\/{}]/,b=$e(["'","/","{","}"],!1,!1),y={type:"any"},E=Ge("numberSkeletonTokenOption"),w="/",x=Xe("/",!1),C=function(e){return e},k=Ge("numberSkeletonToken"),P=function(e,r){return{stem:e,options:r}},T=function(e){return kr({type:0,tokens:e},xr())},F="::",Y=Xe("::",!1),j=function(e){return e},O=function(e){return e.replace(/\s*$/,"")},R=",",S=Xe(",",!1),B="number",D=Xe("number",!1),_=function(e,r,t){return kr({type:"number"===r?Cr.TYPE.number:"date"===r?Cr.TYPE.date:Cr.TYPE.time,style:t&&t[2],value:e},xr())},Z="'",z=Xe("'",!1),N=/^[^']/,M=$e(["'"],!0,!1),L=/^[^a-zA-Z'{}]/,q=$e([["a","z"],["A","Z"],"'","{","}"],!0,!1),H=/^[a-zA-Z]/,I=$e([["a","z"],["A","Z"]],!1,!1),U=function(e){return kr({type:1,pattern:e},xr())},K="date",Q=Xe("date",!1),V="time",W=Xe("time",!1),X="plural",$=Xe("plural",!1),G="selectordinal",J=Xe("selectordinal",!1),ee="offset:",re=Xe("offset:",!1),te=function(e,r,t,n){return kr({type:Cr.TYPE.plural,pluralType:"plural"===r?"cardinal":"ordinal",value:e,offset:t?t[2]:0,options:n.reduce(function(e,r){var t=r.id,n=r.value,a=r.location;return t in e&&We('Duplicate option "'+t+'" in plural element: "'+Qe()+'"',Ve()),e[t]={value:n,location:a},e},{})},xr())},ne="select",ae=Xe("select",!1),ue=function(e,r){return kr({type:Cr.TYPE.select,value:e,options:r.reduce(function(e,r){var t=r.id,n=r.value,a=r.location;return t in e&&We('Duplicate option "'+t+'" in select element: "'+Qe()+'"',Ve()),e[t]={value:n,location:a},e},{})},xr())},oe="=",ce=Xe("=",!1),ie=function(e,r){return kr({id:e,value:r},xr())},se=function(e,r){return kr({id:e,value:r},xr())},le=Ge("whitespace pattern"),fe=/^[\t-\r \x85\u200E\u200F\u2028\u2029]/,pe=$e([["\t","\r"]," "," ","","","\u2028","\u2029"],!1,!1),he=Ge("syntax pattern"),de=/^[!-\/:-@[-\^`{-~\xA1-\xA7\xA9\xAB\xAC\xAE\xB0\xB1\xB6\xBB\xBF\xD7\xF7\u2010-\u2027\u2030-\u203E\u2041-\u2053\u2055-\u205E\u2190-\u245F\u2500-\u2775\u2794-\u2BFF\u2E00-\u2E7F\u3001-\u3003\u3008-\u3020\u3030\uFD3E\uFD3F\uFE45\uFE46]/,ge=$e([["!","/"],[":","@"],["[","^"],"`",["{","~"],["¡","§"],"©","«","¬","®","°","±","¶","»","¿","×","÷",["‐","‧"],["‰","‾"],["⁁","⁓"],["⁕","⁞"],["←",""],["─","❵"],["➔","⯿"],["⸀",""],["、","〃"],["〈","〠"],"〰","﴾","﴿","﹅","﹆"],!1,!1),ve=Ge("optional whitespace"),Ae=Ge("number"),me="-",be=Xe("-",!1),ye=function(e,r){return r?e?-r:r:0},Ee=Ge("double apostrophes"),we="''",xe=Xe("''",!1),Ce=function(){return"'"},ke=/^[{}]/,Pe=$e(["{","}"],!1,!1),Te=function(e,r){return e+r.replace("''","'")},Fe=/^[^{}]/,Ye=$e(["{","}"],!0,!1),je=Ge("argNameOrNumber"),Oe=Ge("argNumber"),Re="0",Se=Xe("0",!1),Be=function(){return 0},De=/^[1-9]/,_e=$e([["1","9"]],!1,!1),Ze=/^[0-9]/,ze=$e([["0","9"]],!1,!1),Ne=function(e){return parseInt(e.join(""),10)},Me=Ge("argName"),Le=0,qe=0,He=[{line:1,column:1}],Ie=0,Ue=[],Ke=0;if(void 0!==e.startRule){if(!(e.startRule in u))throw new Error("Can't start parsing from rule \""+e.startRule+'".');o=u[e.startRule]}function Qe(){return f.substring(qe,Le)}function Ve(){return er(qe,Le)}function We(e,r){throw function(e,r){return new Pr(e,[],"",r)}(e,r=void 0!==r?r:er(qe,Le))}function Xe(e,r){return{type:"literal",text:e,ignoreCase:r}}function $e(e,r,t){return{type:"class",parts:e,inverted:r,ignoreCase:t}}function Ge(e){return{type:"other",description:e}}function Je(e){var r,t=He[e];if(t)return t;for(r=e-1;!He[r];)r--;for(t={line:(t=He[r]).line,column:t.column};r<e;)10===f.charCodeAt(r)?(t.line++,t.column=1):t.column++,r++;return He[e]=t}function er(e,r){var t=Je(e),n=Je(r);return{start:{offset:e,line:t.line,column:t.column},end:{offset:r,line:n.line,column:n.column}}}function rr(e){Le<Ie||(Ie<Le&&(Ie=Le,Ue=[]),Ue.push(e))}function tr(){return nr()}function nr(){var e,r;for(e=[],r=ar();r!==p;)e.push(r),r=ar();return e}function ar(){var e;return(e=function(){var e,r;e=Le,(r=ur())!==p&&(qe=e,r=i(r));return e=r}())===p&&(e=function(){var e,r,t,n,a;Ke++,e=Le,123===f.charCodeAt(Le)?(r=h,Le++):(r=p,0===Ke&&rr(d));e=r!==p?(t=gr(),t!==p?(n=yr())!==p?gr()!==p?(125===f.charCodeAt(Le)?(a=g,Le++):(a=p,0===Ke&&rr(v)),a!==p?(qe=e,r=l(n)):(Le=e,p)):(Le=e,p):(Le=e,p):(Le=e,p)):(Le=e,p);Ke--,e===p&&(r=p,0===Ke&&rr(s));return e}())===p&&(e=function(){var e;(e=function(){var e,r,t,n,a,u,o,c,i,s;e=Le,123===f.charCodeAt(Le)?(r=h,Le++):(r=p,0===Ke&&rr(d));e=r!==p?(t=gr(),t!==p?(n=yr())!==p?gr()!==p?(44===f.charCodeAt(Le)?(a=R,Le++):(a=p,0===Ke&&rr(S)),a!==p?gr()!==p?(f.substr(Le,6)===B?(u=B,Le+=6):(u=p,0===Ke&&rr(D)),u!==p?gr()!==p?(o=Le,44===f.charCodeAt(Le)?(c=R,Le++):(c=p,0===Ke&&rr(S)),(o=c!==p?(i=gr())!==p?(s=function(){var e,r,t;e=Le,f.substr(Le,2)===F?(r=F,Le+=2):(r=p,0===Ke&&rr(Y));e=r!==p?(t=function(){var e,r,t;if(e=Le,r=[],(t=ir())!==p)for(;t!==p;)r.push(t),t=ir();else r=p;r!==p&&(qe=e,r=T(r));return e=r}(),t!==p?(qe=e,r=j(t)):(Le=e,p)):(Le=e,p);e===p&&(e=Le,(r=ur())!==p&&(qe=e,r=O(r)),e=r);return e}())!==p?c=[c,i,s]:(Le=o,p):(Le=o,p):(Le=o,p))===p&&(o=null),o!==p?(c=gr())!==p?(125===f.charCodeAt(Le)?(i=g,Le++):(i=p,0===Ke&&rr(v)),i!==p?(qe=e,r=_(n,u,o)):(Le=e,p)):(Le=e,p):(Le=e,p)):(Le=e,p):(Le=e,p)):(Le=e,p):(Le=e,p)):(Le=e,p):(Le=e,p):(Le=e,p)):(Le=e,p);return e}())===p&&(e=function(){var e,r,t,n,a,u,o,c,i,s;e=Le,123===f.charCodeAt(Le)?(r=h,Le++):(r=p,0===Ke&&rr(d));e=r!==p?(t=gr(),t!==p?(n=yr())!==p?gr()!==p?(44===f.charCodeAt(Le)?(a=R,Le++):(a=p,0===Ke&&rr(S)),a!==p?gr()!==p?(f.substr(Le,4)===K?(u=K,Le+=4):(u=p,0===Ke&&rr(Q)),u===p&&(f.substr(Le,4)===V?(u=V,Le+=4):(u=p,0===Ke&&rr(W))),u!==p?gr()!==p?(o=Le,44===f.charCodeAt(Le)?(c=R,Le++):(c=p,0===Ke&&rr(S)),(o=c!==p?(i=gr())!==p?(s=function(){var e,r,t;e=Le,f.substr(Le,2)===F?(r=F,Le+=2):(r=p,0===Ke&&rr(Y));e=r!==p?(t=function(){var e,r,t,n;r=e=Le,t=[],(n=sr())===p&&(n=lr());if(n!==p)for(;n!==p;)t.push(n),(n=sr())===p&&(n=lr());else t=p;r=t!==p?f.substring(r,Le):t;r!==p&&(qe=e,r=U(r));return e=r}(),t!==p?(qe=e,r=j(t)):(Le=e,p)):(Le=e,p);e===p&&(e=Le,(r=ur())!==p&&(qe=e,r=O(r)),e=r);return e}())!==p?c=[c,i,s]:(Le=o,p):(Le=o,p):(Le=o,p))===p&&(o=null),o!==p?(c=gr())!==p?(125===f.charCodeAt(Le)?(i=g,Le++):(i=p,0===Ke&&rr(v)),i!==p?(qe=e,r=_(n,u,o)):(Le=e,p)):(Le=e,p):(Le=e,p)):(Le=e,p):(Le=e,p)):(Le=e,p):(Le=e,p)):(Le=e,p):(Le=e,p):(Le=e,p)):(Le=e,p);return e}());return e}())===p&&(e=function(){var e,r,t,n,a,u,o,c,i,s,l;e=Le,123===f.charCodeAt(Le)?(r=h,Le++):(r=p,0===Ke&&rr(d));if(r!==p)if(gr()!==p)if((t=yr())!==p)if(gr()!==p)if(44===f.charCodeAt(Le)?(n=R,Le++):(n=p,0===Ke&&rr(S)),n!==p)if(gr()!==p)if(f.substr(Le,6)===X?(a=X,Le+=6):(a=p,0===Ke&&rr($)),a===p&&(f.substr(Le,13)===G?(a=G,Le+=13):(a=p,0===Ke&&rr(J))),a!==p)if(gr()!==p)if(44===f.charCodeAt(Le)?(u=R,Le++):(u=p,0===Ke&&rr(S)),u!==p)if(gr()!==p)if(o=Le,f.substr(Le,7)===ee?(c=ee,Le+=7):(c=p,0===Ke&&rr(re)),(o=c!==p?(i=gr())!==p?(s=vr())!==p?c=[c,i,s]:(Le=o,p):(Le=o,p):(Le=o,p))===p&&(o=null),o!==p)if((c=gr())!==p){if(i=[],(s=pr())!==p)for(;s!==p;)i.push(s),s=pr();else i=p;e=i!==p?(s=gr())!==p?(125===f.charCodeAt(Le)?(l=g,Le++):(l=p,0===Ke&&rr(v)),l!==p?(qe=e,r=te(t,a,o,i)):(Le=e,p)):(Le=e,p):(Le=e,p)}else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;return e}())===p&&(e=function(){var e,r,t,n,a,u,o,c,i;e=Le,123===f.charCodeAt(Le)?(r=h,Le++):(r=p,0===Ke&&rr(d));if(r!==p)if(gr()!==p)if((t=yr())!==p)if(gr()!==p)if(44===f.charCodeAt(Le)?(n=R,Le++):(n=p,0===Ke&&rr(S)),n!==p)if(gr()!==p)if(f.substr(Le,6)===ne?(a=ne,Le+=6):(a=p,0===Ke&&rr(ae)),a!==p)if(gr()!==p)if(44===f.charCodeAt(Le)?(u=R,Le++):(u=p,0===Ke&&rr(S)),u!==p)if(gr()!==p){if(o=[],(c=fr())!==p)for(;c!==p;)o.push(c),c=fr();else o=p;e=o!==p?(c=gr())!==p?(125===f.charCodeAt(Le)?(i=g,Le++):(i=p,0===Ke&&rr(v)),i!==p?(qe=e,r=ue(t,o)):(Le=e,p)):(Le=e,p):(Le=e,p)}else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;else Le=e,e=p;return e}()),e}function ur(){var e,r,t;if(e=Le,r=[],(t=Ar())===p&&(t=mr())===p&&(t=br()),t!==p)for(;t!==p;)r.push(t),(t=Ar())===p&&(t=mr())===p&&(t=br());else r=p;return r!==p&&(qe=e,r=c(r)),e=r}function or(){var e,r,t,n,a;if(Ke++,r=[],n=t=e=Le,Ke++,(a=hr())===p&&(m.test(f.charAt(Le))?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(b))),Ke--,(t=(n=a===p?void 0:(Le=n,p))!==p?(f.length>Le?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(y)),a!==p?n=[n,a]:(Le=t,p)):(Le=t,p))!==p)for(;t!==p;)r.push(t),n=t=Le,Ke++,(a=hr())===p&&(m.test(f.charAt(Le))?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(b))),Ke--,t=(n=a===p?void 0:(Le=n,p))!==p?(f.length>Le?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(y)),a!==p?n=[n,a]:(Le=t,p)):(Le=t,p);else r=p;return e=r!==p?f.substring(e,Le):r,Ke--,e===p&&(r=p,0===Ke&&rr(A)),e}function cr(){var e,r,t;return Ke++,e=Le,47===f.charCodeAt(Le)?(r=w,Le++):(r=p,0===Ke&&rr(x)),e=r!==p&&(t=or())!==p?(qe=e,r=C(t)):(Le=e,p),Ke--,e===p&&(r=p,0===Ke&&rr(E)),e}function ir(){var e,r,t,n;if(Ke++,e=Le,gr()!==p)if((r=or())!==p){for(t=[],n=cr();n!==p;)t.push(n),n=cr();e=t!==p?(qe=e,P(r,t)):(Le=e,p)}else Le=e,e=p;else Le=e,e=p;return Ke--,e===p&&(p,0===Ke&&rr(k)),e}function sr(){var e,r,t,n;if(e=Le,39===f.charCodeAt(Le)?(r=Z,Le++):(r=p,0===Ke&&rr(z)),r!==p){if(t=[],(n=Ar())===p&&(N.test(f.charAt(Le))?(n=f.charAt(Le),Le++):(n=p,0===Ke&&rr(M))),n!==p)for(;n!==p;)t.push(n),(n=Ar())===p&&(N.test(f.charAt(Le))?(n=f.charAt(Le),Le++):(n=p,0===Ke&&rr(M)));else t=p;e=t!==p?(39===f.charCodeAt(Le)?(n=Z,Le++):(n=p,0===Ke&&rr(z)),n!==p?r=[r,t,n]:(Le=e,p)):(Le=e,p)}else Le=e,e=p;if(e===p)if(e=[],(r=Ar())===p&&(L.test(f.charAt(Le))?(r=f.charAt(Le),Le++):(r=p,0===Ke&&rr(q))),r!==p)for(;r!==p;)e.push(r),(r=Ar())===p&&(L.test(f.charAt(Le))?(r=f.charAt(Le),Le++):(r=p,0===Ke&&rr(q)));else e=p;return e}function lr(){var e,r;if(e=[],H.test(f.charAt(Le))?(r=f.charAt(Le),Le++):(r=p,0===Ke&&rr(I)),r!==p)for(;r!==p;)e.push(r),H.test(f.charAt(Le))?(r=f.charAt(Le),Le++):(r=p,0===Ke&&rr(I));else e=p;return e}function fr(){var e,r,t,n,a;return e=Le,e=gr()!==p&&(r=wr())!==p&&gr()!==p?(123===f.charCodeAt(Le)?(t=h,Le++):(t=p,0===Ke&&rr(d)),t!==p&&(n=nr())!==p?(125===f.charCodeAt(Le)?(a=g,Le++):(a=p,0===Ke&&rr(v)),a!==p?(qe=e,ie(r,n)):(Le=e,p)):(Le=e,p)):(Le=e,p)}function pr(){var e,r,t,n,a;return e=Le,e=gr()!==p&&(r=function(){var e,r,t,n;return r=e=Le,61===f.charCodeAt(Le)?(t=oe,Le++):(t=p,0===Ke&&rr(ce)),(e=(r=t!==p&&(n=vr())!==p?t=[t,n]:(Le=r,p))!==p?f.substring(e,Le):r)===p&&(e=wr()),e}())!==p&&gr()!==p?(123===f.charCodeAt(Le)?(t=h,Le++):(t=p,0===Ke&&rr(d)),t!==p&&(n=nr())!==p?(125===f.charCodeAt(Le)?(a=g,Le++):(a=p,0===Ke&&rr(v)),a!==p?(qe=e,se(r,n)):(Le=e,p)):(Le=e,p)):(Le=e,p)}function hr(){var e;return Ke++,fe.test(f.charAt(Le))?(e=f.charAt(Le),Le++):(e=p,0===Ke&&rr(pe)),Ke--,e===p&&0===Ke&&rr(le),e}function dr(){var e;return Ke++,de.test(f.charAt(Le))?(e=f.charAt(Le),Le++):(e=p,0===Ke&&rr(ge)),Ke--,e===p&&0===Ke&&rr(he),e}function gr(){var e,r,t;for(Ke++,e=Le,r=[],t=hr();t!==p;)r.push(t),t=hr();return e=r!==p?f.substring(e,Le):r,Ke--,e===p&&(r=p,0===Ke&&rr(ve)),e}function vr(){var e,r,t;return Ke++,e=Le,45===f.charCodeAt(Le)?(r=me,Le++):(r=p,0===Ke&&rr(be)),r===p&&(r=null),e=r!==p&&(t=Er())!==p?(qe=e,r=ye(r,t)):(Le=e,p),Ke--,e===p&&(r=p,0===Ke&&rr(Ae)),e}function Ar(){var e,r;return Ke++,e=Le,f.substr(Le,2)===we?(r=we,Le+=2):(r=p,0===Ke&&rr(xe)),r!==p&&(qe=e,r=Ce()),Ke--,(e=r)===p&&(r=p,0===Ke&&rr(Ee)),e}function mr(){var e,r,t,n,a,u;if(e=Le,39===f.charCodeAt(Le)?(r=Z,Le++):(r=p,0===Ke&&rr(z)),r!==p)if(ke.test(f.charAt(Le))?(t=f.charAt(Le),Le++):(t=p,0===Ke&&rr(Pe)),t!==p){for(n=Le,a=[],f.substr(Le,2)===we?(u=we,Le+=2):(u=p,0===Ke&&rr(xe)),u===p&&(N.test(f.charAt(Le))?(u=f.charAt(Le),Le++):(u=p,0===Ke&&rr(M)));u!==p;)a.push(u),f.substr(Le,2)===we?(u=we,Le+=2):(u=p,0===Ke&&rr(xe)),u===p&&(N.test(f.charAt(Le))?(u=f.charAt(Le),Le++):(u=p,0===Ke&&rr(M)));e=(n=a!==p?f.substring(n,Le):a)!==p?(39===f.charCodeAt(Le)?(a=Z,Le++):(a=p,0===Ke&&rr(z)),a!==p?(qe=e,r=Te(t,n)):(Le=e,p)):(Le=e,p)}else Le=e,e=p;else Le=e,e=p;return e}function br(){var e,r;return e=Le,Fe.test(f.charAt(Le))?(r=f.charAt(Le),Le++):(r=p,0===Ke&&rr(Ye)),e=r!==p?f.substring(e,Le):r}function yr(){var e,r;return Ke++,e=Le,(r=Er())===p&&(r=wr()),e=r!==p?f.substring(e,Le):r,Ke--,e===p&&(r=p,0===Ke&&rr(je)),e}function Er(){var e,r,t,n,a;if(Ke++,e=Le,48===f.charCodeAt(Le)?(r=Re,Le++):(r=p,0===Ke&&rr(Se)),r!==p&&(qe=e,r=Be()),(e=r)===p){if(r=e=Le,De.test(f.charAt(Le))?(t=f.charAt(Le),Le++):(t=p,0===Ke&&rr(_e)),t!==p){for(n=[],Ze.test(f.charAt(Le))?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(ze));a!==p;)n.push(a),Ze.test(f.charAt(Le))?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(ze));r=n!==p?t=[t,n]:(Le=r,p)}else Le=r,r=p;r!==p&&(qe=e,r=Ne(r)),e=r}return Ke--,e===p&&(r=p,0===Ke&&rr(Oe)),e}function wr(){var e,r,t,n,a;if(Ke++,r=[],n=t=e=Le,Ke++,(a=hr())===p&&(a=dr()),Ke--,(t=(n=a===p?void 0:(Le=n,p))!==p?(f.length>Le?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(y)),a!==p?n=[n,a]:(Le=t,p)):(Le=t,p))!==p)for(;t!==p;)r.push(t),n=t=Le,Ke++,(a=hr())===p&&(a=dr()),Ke--,t=(n=a===p?void 0:(Le=n,p))!==p?(f.length>Le?(a=f.charAt(Le),Le++):(a=p,0===Ke&&rr(y)),a!==p?n=[n,a]:(Le=t,p)):(Le=t,p);else r=p;return e=r!==p?f.substring(e,Le):r,Ke--,e===p&&(r=p,0===Ke&&rr(Me)),e}function xr(){return e&&e.captureLocation?{location:Ve()}:{}}if((r=o())!==p&&Le===f.length)return r;throw r!==p&&Le<f.length&&rr({type:"end"}),t=Ue,n=Ie<f.length?f.charAt(Ie):null,a=Ie<f.length?er(Ie,Ie+1):er(Ie,Ie),new Pr(Pr.buildMessage(t,n),t,n,a)},h=function(){for(var e=0,r=0,t=arguments.length;r<t;r++)e+=arguments[r].length;var n=Array(e),a=0;for(r=0;r<t;r++)for(var u=arguments[r],o=0,c=u.length;o<c;o++,a++)n[a]=u[o];return n},d=/(^|[^\\])#/g;var i=/(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;Cr.SyntaxError=Pr,Cr.createLiteralElement=function(e){return{type:Cr.TYPE.literal,value:e}},Cr.createNumberElement=function(e,r){return{type:Cr.TYPE.number,value:e,style:r}},Cr.isArgumentElement=function(e){return e.type===Cr.TYPE.argument},Cr.isDateElement=function(e){return e.type===Cr.TYPE.date},Cr.isDateTimeSkeleton=function(e){return!(!e||"object"!=typeof e||1!==e.type)},Cr.isLiteralElement=f,Cr.isNumberElement=function(e){return e.type===Cr.TYPE.number},Cr.isNumberSkeleton=function(e){return!(!e||"object"!=typeof e||0!==e.type)},Cr.isPluralElement=a,Cr.isSelectElement=n,Cr.isTimeElement=function(e){return e.type===Cr.TYPE.time},Cr.parse=function(e,r){var t=p(e,r);return r&&!1===r.normalizeHashtagInPlural||function l(e){e.forEach(function(s){(a(s)||n(s))&&Object.keys(s.options).forEach(function(e){for(var r,t=s.options[e],n=-1,a=void 0,u=0;u<t.value.length;u++){var o=t.value[u];if(f(o)&&d.test(o.value)){n=u,a=o;break}}if(a){var c=a.value.replace(d,"$1{"+s.value+", number}"),i=p(c);(r=t.value).splice.apply(r,h([n,1],i))}l(t.value)})})}(t),t},Cr.parseDateTimeSkeleton=function(e){var t={};return e.replace(i,function(e){var r=e.length;switch(e[0]){case"G":t.era=4===r?"long":5===r?"narrow":"short";break;case"y":t.year=2===r?"2-digit":"numeric";break;case"Y":case"u":case"U":case"r":throw new RangeError("`Y/u/U/r` (year) patterns are not supported, use `y` instead");case"q":case"Q":throw new RangeError("`q/Q` (quarter) patterns are not supported");case"M":case"L":t.month=["numeric","2-digit","short","long","narrow"][r-1];break;case"w":case"W":throw new RangeError("`w/W` (week) patterns are not supported");case"d":t.day=["numeric","2-digit"][r-1];break;case"D":case"F":case"g":throw new RangeError("`D/F/g` (day) patterns are not supported, use `d` instead");case"E":t.weekday=4===r?"short":5===r?"narrow":"short";break;case"e":if(r<4)throw new RangeError("`e..eee` (weekday) patterns are not supported");t.weekday=["short","long","narrow","short"][r-4];break;case"c":if(r<4)throw new RangeError("`c..ccc` (weekday) patterns are not supported");t.weekday=["short","long","narrow","short"][r-4];break;case"a":t.hour12=!0;break;case"b":case"B":throw new RangeError("`b/B` (period) patterns are not supported, use `a` instead");case"h":t.hourCycle="h12",t.hour=["numeric","2-digit"][r-1];break;case"H":t.hourCycle="h23",t.hour=["numeric","2-digit"][r-1];break;case"K":t.hourCycle="h11",t.hour=["numeric","2-digit"][r-1];break;case"k":t.hourCycle="h24",t.hour=["numeric","2-digit"][r-1];break;case"j":case"J":case"C":throw new RangeError("`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead");case"m":t.minute=["numeric","2-digit"][r-1];break;case"s":t.second=["numeric","2-digit"][r-1];break;case"S":case"A":throw new RangeError("`S/A` (second) pattenrs are not supported, use `s` instead");case"z":t.timeZoneName=r<4?"short":"long";break;case"Z":case"O":case"v":case"V":case"X":case"x":throw new RangeError("`Z/O/v/V/X/x` (timeZone) pattenrs are not supported, use `z` instead")}return""}),t},Cr.pegParse=p,Object.defineProperty(Cr,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=intl-messageformat-parser.min.js.map |
@@ -5,3 +5,4 @@ import { IParseOptions } from './parser'; | ||
export * from './parser'; | ||
export * from './skeleton'; | ||
export declare type ParseOptions = Options & IParseOptions; | ||
export declare function parse(input: string, opts?: ParseOptions): MessageFormatElement[]; |
@@ -5,2 +5,3 @@ import { pegParse } from './parser'; | ||
export * from './parser'; | ||
export * from './skeleton'; | ||
export function parse(input, opts) { | ||
@@ -7,0 +8,0 @@ var els = pegParse(input, opts); |
@@ -24,2 +24,6 @@ | ||
export declare interface ExtendedDateTimeFormatOptions extends Intl.DateTimeFormatOptions { | ||
hourCycle?: 'h11' | 'h12' | 'h23' | 'h24'; | ||
} | ||
export declare interface IAnyExpectation { | ||
@@ -76,3 +80,3 @@ type: "any"; | ||
export declare function isDateTimeSkeleton(el: Skeleton): el is DateTimeSkeleton; | ||
export declare function isDateTimeSkeleton(el?: DateElement['style'] | TimeElement['style']): el is DateTimeSkeleton; | ||
@@ -86,3 +90,3 @@ /** | ||
export declare function isNumberSkeleton(el: Skeleton): el is NumberSkeleton; | ||
export declare function isNumberSkeleton(el: NumberElement['style']): el is NumberSkeleton; | ||
@@ -139,2 +143,10 @@ export declare function isPluralElement(el: MessageFormatElement): el is PluralElement; | ||
/** | ||
* Parse Date time skeleton into Intl.DateTimeFormatOptions | ||
* Ref: https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table | ||
* @public | ||
* @param skeleton skeleton string | ||
*/ | ||
export declare function parseDateTimeSkeleton(skeleton: string): ExtendedDateTimeFormatOptions; | ||
export declare type ParseFunction = (input: string, options?: IParseOptions) => MessageFormatElement[]; | ||
@@ -141,0 +153,0 @@ |
@@ -101,4 +101,4 @@ export declare enum TYPE { | ||
export declare function isPluralElement(el: MessageFormatElement): el is PluralElement; | ||
export declare function isNumberSkeleton(el: Skeleton): el is NumberSkeleton; | ||
export declare function isDateTimeSkeleton(el: Skeleton): el is DateTimeSkeleton; | ||
export declare function isNumberSkeleton(el: NumberElement['style']): el is NumberSkeleton; | ||
export declare function isDateTimeSkeleton(el?: DateElement['style'] | TimeElement['style']): el is DateTimeSkeleton; | ||
export declare function createLiteralElement(value: string): LiteralElement; | ||
@@ -105,0 +105,0 @@ export declare function createNumberElement(value: string, style?: string | null): NumberElement; |
@@ -57,6 +57,6 @@ export var TYPE; | ||
export function isNumberSkeleton(el) { | ||
return el.type === 0 /* number */; | ||
return !!(el && typeof el === 'object' && el.type === 0 /* number */); | ||
} | ||
export function isDateTimeSkeleton(el) { | ||
return el.type === 1 /* dateTime */; | ||
return !!(el && typeof el === 'object' && el.type === 1 /* dateTime */); | ||
} | ||
@@ -63,0 +63,0 @@ export function createLiteralElement(value) { |
{ | ||
"name": "intl-messageformat-parser", | ||
"version": "3.2.6", | ||
"version": "3.3.0", | ||
"description": "Parses ICU Message strings into an AST via JavaScript.", | ||
@@ -48,3 +48,3 @@ "main": "dist/index.js", | ||
"homepage": "https://github.com/formatjs/formatjs", | ||
"gitHead": "4e2afbd30b8bcf239a6083049a113b7b694ebb80" | ||
"gitHead": "5770a51ce0e7de1ee29d5c5096307f3767969676" | ||
} |
@@ -101,2 +101,25 @@ # Intl MessageFormat Parser | ||
## Supported DateTime Skeleton | ||
ICU provides a [wide array of pattern](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table) to customize date time format. However, not all of them are available via ECMA402's Intl API. Therefore, our parser only support the following patterns | ||
| Symbol | Meaning | Notes | | ||
| ------ | ----------------------------- | ------------------------- | | ||
| G | Era designator | | ||
| y | year | | ||
| M | month in year | | ||
| L | stand-alone month in year | | ||
| d | day in month | | ||
| E | day of week | | ||
| e | local day of week | `e..eee` is not supported | | ||
| c | stand-alone local day of week | `c..ccc` is not supported | | ||
| a | AM/PM marker | | ||
| h | Hour [1-12] | | ||
| H | Hour [0-23] | | ||
| K | Hour [0-11] | | ||
| k | Hour [1-24] | | ||
| m | Minute | | ||
| s | Second | | ||
| z | Time Zone | | ||
## Benchmarks | ||
@@ -103,0 +126,0 @@ |
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
696189
34
8897
140