@pbtanna17/ngx-translate-parser-plural-select
Version:
ngx-translate parser that supports pluralization and select (a la Angular's i18n module)
2 lines • 4.04 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("ngx-translate-parser-plural-select",[],e):"object"==typeof exports?exports["ngx-translate-parser-plural-select"]=e():t["ngx-translate-parser-plural-select"]=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,r){t.exports=r(1)},function(t,e,r){"use strict";var n=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),o=this&&this.__assign||Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t};Object.defineProperty(e,"__esModule",{value:!0});var i=r(2);r(3);var u=function(t){return"{"===t.charAt(0)},a=function(t,e){for(var r=1,n=1;n>0&&r<t.length;)"\\"!==t[r]?("{"===t[r]&&n++,"}"===t[r]&&n--,r++):r+=2;var o=t.substr(0,r);return e(r),o},s=i.parseStringTemplateGenerator({VARIABLE_START:/^{\s*/,VARIABLE_END:/^\s*}/,PIPE_START:/^\s*,\s*/,PIPE_PARAMETER_START:/^\s*,\s*/,QUOTED_STRING_IN_PARAMETER_TEST:u,QUOTED_STRING_IN_PARAMETER_GET_AND_ADVANCE:a}),c=i.parseStringTemplateGenerator({VARIABLE_START:/^{/,VARIABLE_END:/^}/,PIPE_START:/^$/,PIPE_PARAMETER_START:/^$/,QUOTED_STRING_TEST:u,QUOTED_STRING_GET_AND_ADVANCE:a,QUOTED_STRING_IN_PARAMETER_TEST:u,QUOTED_STRING_IN_PARAMETER_GET_AND_ADVANCE:a}),p={plural:function(t,e,r){e=e.map(function(t){return t.trim()}).slice(0,e.length-1);var n=e.reduce(function(t,e,n){var i;return o({},t,(i={},i["="===e.charAt(0)?e.slice(1).trim():e.trim()]=r[n],i))},{}),i=+t;if(n.hasOwnProperty(i.toString()))return n[t];if(i===i){var u={0:["zero"],1:["one"],2:["two","few"],3:["three","few"],4:["four","few"],5:["five","many"],6:["six","many"],7:["seven","many"],8:["eight","many"],9:["nine","many"]};return n.hasOwnProperty(t)?n[t]:(i>=10&&i<20?["many"]:u[i%10]||["many"]).concat(i>=20?["many"]:[],["other"]).filter(function(t){return n.hasOwnProperty(t)}).map(function(t){return n[t]})[0]||""}return null==n.other?"":n.other},select:function(t,e,r){e=e.map(function(t){return t.trim()}).slice(0,e.length-1);var n=e.reduce(function(t,e,n){var i;return o({},t,(i={},i[e.trim()]=r[n],i))},{});return null==n[t]?"":n[t]}},f=function(){function t(t){this.additionalPipes=t,this.pipeEntries=[],this.pipeEntries=Object.entries(o({},t||{},p))}return t.prototype.getPipes=function(t){var e=this;return this.pipeEntries.map(function(r){var n,o=r[0],i=r[1];return n={},n[o]=function(r,n){var o=n[0],u=c(o),a=u.literals,s=u.variables.map(function(r){return e.interpolate(r.name,t)});return i(r,a,s)},n}).reduce(function(t,e){return o({},t,e)},{})},t.prototype.interpolate=function(t,e){var r=this;return void 0===t?t:"function"==typeof t?t(e):i.evaluateParsedString(s(t),e,this.getPipes(e),function(t){return r.getValue(e,t)})},t.prototype.getValue=function(t,e){var r=e&&e.split(".")||[];e="";do{e+=r.shift(),null==t||null==t[e]||"object"!=typeof t[e]&&r.length?r.length?e+=".":t=void 0:(t=t[e],e="")}while(r.length);return t},t}();e.TranslateICUCustomParser=f;var l=function(t){function e(){return t.call(this,{})||this}return n(e,t),e}(f);e.TranslateICUParser=l},function(t,e){t.exports=require("string-template-parser")},function(t,e){t.exports=require("core-js/es7/object")}])});
//# sourceMappingURL=index.js.map