Socket
Socket
Sign inDemoInstall

@formatjs/intl-listformat

Package Overview
Dependencies
Maintainers
2
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl-listformat - npm Package Compare versions

Comparing version 1.2.7 to 1.3.0

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [1.3.0](https://github.com/formatjs/formatjs/compare/@formatjs/intl-listformat@1.2.7...@formatjs/intl-listformat@1.3.0) (2019-12-01)
### Features
* **@formatjs/intl-utils:** add PartitionPattern abstract operation ([#317](https://github.com/formatjs/formatjs/issues/317)) ([5731fcf](https://github.com/formatjs/formatjs/commit/5731fcfeaaba65322f904e863faead8d1f177a98))
## [1.2.7](https://github.com/formatjs/formatjs/compare/@formatjs/intl-listformat@1.2.6...@formatjs/intl-listformat@1.2.7) (2019-11-26)

@@ -8,0 +19,0 @@

6

dist-es6/core.d.ts

@@ -1,2 +0,2 @@

import { ListPatternLocaleData, ListPatternFieldsData } from '@formatjs/intl-utils';
import { ListPatternLocaleData, ListPatternFieldsData, LiteralPart } from '@formatjs/intl-utils';
export interface IntlListFormatOptions {

@@ -54,6 +54,2 @@ /**

export declare type Part = LiteralPart | ElementPart;
export interface LiteralPart {
type: 'literal';
value: string;
}
export interface ElementPart {

@@ -60,0 +56,0 @@ type: 'element';

@@ -1,2 +0,2 @@

import { toObject, getOption, unpackData, setInternalSlot, getCanonicalLocales, supportedLocales, createResolveLocale, getInternalSlot, } from '@formatjs/intl-utils';
import { toObject, getOption, unpackData, setInternalSlot, getCanonicalLocales, supportedLocales, createResolveLocale, getInternalSlot, partitionPattern, invariant, isLiteralPart, } from '@formatjs/intl-utils';
function validateInstance(instance, method) {

@@ -59,36 +59,23 @@ if (!(instance instanceof ListFormat)) {

function deconstructPattern(pattern, placeables) {
const patternParts = partitionPattern(pattern);
const result = [];
let beginIndex = pattern.indexOf('{', 0);
let nextIndex = 0;
while (beginIndex > -1 && beginIndex < pattern.length) {
const endIndex = pattern.indexOf('}', beginIndex);
if (endIndex <= beginIndex) {
throw new Error(`endIndex ${endIndex} should be bigger than beginIndex ${beginIndex}`);
}
if (beginIndex > nextIndex) {
for (const patternPart of patternParts) {
const { type: part } = patternPart;
if (isLiteralPart(patternPart)) {
result.push({
type: 'literal',
value: pattern.slice(nextIndex, beginIndex),
value: patternPart.value,
});
}
const part = pattern.slice(beginIndex + 1, endIndex);
if (!(part in placeables)) {
throw new Error(`Missing key ${part} from placeables`);
}
const subst = placeables[part];
if (Array.isArray(subst)) {
for (const s of subst) {
result.push(s);
else {
invariant(part in placeables, `${part} is missing from placables`);
const subst = placeables[part];
if (Array.isArray(subst)) {
result.push(...subst);
}
else {
result.push(subst);
}
}
else {
result.push(subst);
}
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < pattern.length) {
const literal = pattern.slice(nextIndex, pattern.length);
result.push({ type: 'literal', value: literal });
}
return result;

@@ -95,0 +82,0 @@ }

@@ -1,2 +0,2 @@

import { ListPatternLocaleData, ListPatternFieldsData } from '@formatjs/intl-utils';
import { ListPatternLocaleData, ListPatternFieldsData, LiteralPart } from '@formatjs/intl-utils';
export interface IntlListFormatOptions {

@@ -54,6 +54,2 @@ /**

export declare type Part = LiteralPart | ElementPart;
export interface LiteralPart {
type: 'literal';
value: string;
}
export interface ElementPart {

@@ -60,0 +56,0 @@ type: 'element';

@@ -80,37 +80,24 @@ "use strict";

function deconstructPattern(pattern, placeables) {
var patternParts = intl_utils_1.partitionPattern(pattern);
var result = [];
var beginIndex = pattern.indexOf('{', 0);
var nextIndex = 0;
while (beginIndex > -1 && beginIndex < pattern.length) {
var endIndex = pattern.indexOf('}', beginIndex);
if (endIndex <= beginIndex) {
throw new Error("endIndex " + endIndex + " should be bigger than beginIndex " + beginIndex);
}
if (beginIndex > nextIndex) {
for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
var patternPart = patternParts_1[_i];
var part = patternPart.type;
if (intl_utils_1.isLiteralPart(patternPart)) {
result.push({
type: 'literal',
value: pattern.slice(nextIndex, beginIndex),
value: patternPart.value,
});
}
var part = pattern.slice(beginIndex + 1, endIndex);
if (!(part in placeables)) {
throw new Error("Missing key " + part + " from placeables");
}
var subst = placeables[part];
if (Array.isArray(subst)) {
for (var _i = 0, subst_1 = subst; _i < subst_1.length; _i++) {
var s = subst_1[_i];
result.push(s);
else {
intl_utils_1.invariant(part in placeables, part + " is missing from placables");
var subst = placeables[part];
if (Array.isArray(subst)) {
result.push.apply(result, subst);
}
else {
result.push(subst);
}
}
else {
result.push(subst);
}
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < pattern.length) {
var literal = pattern.slice(nextIndex, pattern.length);
result.push({ type: 'literal', value: literal });
}
return result;

@@ -117,0 +104,0 @@ }

@@ -7,2 +7,9 @@ (function (global, factory) {

function invariant(condition, message, Err) {
if (Err === void 0) { Err = Error; }
if (!condition) {
throw new Err(message);
}
}
/**

@@ -60,2 +67,35 @@ * https://tc39.es/ecma262/#sec-toobject

}
function isLiteralPart(patternPart) {
return patternPart.type === 'literal';
}
function partitionPattern(pattern) {
var result = [];
var beginIndex = pattern.indexOf('{');
var endIndex = 0;
var nextIndex = 0;
var length = pattern.length;
while (beginIndex < pattern.length && beginIndex > -1) {
endIndex = pattern.indexOf('}', beginIndex);
invariant(endIndex > beginIndex, "Invalid pattern " + pattern);
if (beginIndex > nextIndex) {
result.push({
type: 'literal',
value: pattern.substring(nextIndex, beginIndex),
});
}
result.push({
type: pattern.substring(beginIndex + 1, endIndex),
value: undefined,
});
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < length) {
result.push({
type: 'literal',
value: pattern.substring(nextIndex, length),
});
}
return result;
}

@@ -75,9 +115,2 @@ /**

function invariant(condition, message, Err) {
if (Err === void 0) { Err = Error; }
if (!condition) {
throw new Err(message);
}
}
var __extends = (undefined && undefined.__extends) || (function () {

@@ -424,37 +457,24 @@ var extendStatics = function (d, b) {

function deconstructPattern(pattern, placeables) {
var patternParts = partitionPattern(pattern);
var result = [];
var beginIndex = pattern.indexOf('{', 0);
var nextIndex = 0;
while (beginIndex > -1 && beginIndex < pattern.length) {
var endIndex = pattern.indexOf('}', beginIndex);
if (endIndex <= beginIndex) {
throw new Error("endIndex " + endIndex + " should be bigger than beginIndex " + beginIndex);
}
if (beginIndex > nextIndex) {
for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
var patternPart = patternParts_1[_i];
var part = patternPart.type;
if (isLiteralPart(patternPart)) {
result.push({
type: 'literal',
value: pattern.slice(nextIndex, beginIndex),
value: patternPart.value,
});
}
var part = pattern.slice(beginIndex + 1, endIndex);
if (!(part in placeables)) {
throw new Error("Missing key " + part + " from placeables");
}
var subst = placeables[part];
if (Array.isArray(subst)) {
for (var _i = 0, subst_1 = subst; _i < subst_1.length; _i++) {
var s = subst_1[_i];
result.push(s);
else {
invariant(part in placeables, part + " is missing from placables");
var subst = placeables[part];
if (Array.isArray(subst)) {
result.push.apply(result, subst);
}
else {
result.push(subst);
}
}
else {
result.push(subst);
}
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < pattern.length) {
var literal = pattern.slice(nextIndex, pattern.length);
result.push({ type: 'literal', value: literal });
}
return result;

@@ -461,0 +481,0 @@ }

@@ -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).IntlRelativeTimeFormat={})}(this,function(e){"use strict";function s(e){if(null==e)throw new TypeError("undefined/null cannot be converted to object");return Object(e)}function p(e,t,r,n,a){var o=e[t];if(void 0===o)return a;if("boolean"!==r&&"string"!==r)throw new TypeError("invalid type");if("boolean"===r&&(o=Boolean(o)),"string"===r&&(o=String(o)),void 0!==n&&!n.filter(function(e){return e==o}).length)throw new RangeError(o+" in not within "+n);return o}function _(e,t,r,n){e.get(t)||e.set(t,Object.create(null)),e.get(t)[r]=n}function l(e,t,r){var n=e.get(t);if(!n)throw new TypeError(t+" InternalSlot has not been initialized");return n[r]}function O(e){var t=Intl.getCanonicalLocales;return"function"==typeof t?t(e):Intl.NumberFormat.supportedLocalesOf(e||"")}function m(e,t,r){if(void 0===r&&(r=Error),!e)throw new r(t)}var n,t=(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)}),o=function(){return(o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function v(e){var b=function(u){return function(e,t){for(var r={locale:""},n=0,a=t;n<a.length;n++){var o=a[n],l=o.replace(c,""),i=f(e,l);if(i)return r.locale=i,o!==l&&(r.extension=o.slice(l.length+1,o.length)),r}return r.locale=u(),r}}(e),L=function(u){return function(e,t){for(var r={locale:""},n=0,a=t;n<a.length;n++){var o=a[n],l=o.replace(c,""),i=f(e,l);if(i)return r.locale=i,o!==l&&(r.extension=o.slice(l.length+1,o.length)),r}return r.locale=u(),r}}(e);return function(e,t,r,n,a){for(var o,l=(o="lookup"===r.localeMatcher?b(e,t):L(e,t)).locale,i={locale:"",dataLocale:l},u="-u",c=0,f=n;c<f.length;c++){var s=f[c],p=a[l];m("object"==typeof p&&null!==p,"locale data "+s+" must be an object");var _=p[s];m(Array.isArray(_),"keyLocaleData must be an array");var v=_[0];m("string"==typeof v||null===v,"value must be string or null");var h="";if(o.extension){var y=A(o.extension,s);void 0!==y&&(""!==y?~_.indexOf(y)&&(h="-"+s+"-"+(v=y)):~y.indexOf("true")&&(v="true",h="-"+s))}if(s in r){var d=r[s];m("string"==typeof d||null==d,"optionsValue must be String, Undefined or Null"),~_.indexOf(d)&&d!==v&&(v=d,h="")}i[s]=v,u+=h}if(2<u.length){var g=l.indexOf("-x-");if(-1===g)l+=u;else l=l.slice(0,g)+u+l.slice(g,l.length);l=O(l)[0]}return i.locale=l,i}}function A(e,t){m(2===t.length,"key must have 2 elements");var r=e.length,n="-"+t+"-",a=e.indexOf(n);if(-1!==a){for(var o=a+4,l=o,i=o,u=!1;!u;){var c=e.indexOf("-",i);2===(-1===c?r-i:c-i)?u=!0:-1===c?(l=r,u=!0):i=(l=c)+1}return e.slice(o,l)}if(n="-"+t,-1!==(a=e.indexOf(n))&&a+3===r)return""}var c=/-u(?:-[0-9a-z]{2,8})+/gi;function f(e,t){for(var r=t;;){if(~e.indexOf(r))return r;var n=r.lastIndexOf("-");if(!~n)return;2<=n&&"-"===r[n-2]&&(n-=2),r=r.slice(0,n)}}function a(e,t){for(var r=[],n=0,a=t;n<a.length;n++){var o=f(e,a[n].replace(c,""));o&&r.push(o)}return r}var r,i=(r=Error,t(u,r),u);function u(){var e=null!==r&&r.apply(this,arguments)||this;return e.type="MISSING_LOCALE_DATA",e}var h=function(){return(h=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},y=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),a=0;for(t=0;t<r;t++)for(var o=arguments[t],l=0,i=o.length;l<i;l++,a++)n[a]=o[l];return n};function d(e,t){if(!(e instanceof T))throw new TypeError("Method Intl.ListFormat.prototype."+t+" called on incompatible receiver "+String(e))}function g(e){if(void 0===e)return[];for(var t=[],r=0,n=e;r<n.length;r++){var a=n[r];if("string"!=typeof a)throw new TypeError("array list["+e.indexOf(a)+"] is not type String");t.push(a)}return t}function b(e,t,r){var n=r.length;if(0===n)return[];if(2===n)return L(l(e,t,"templatePair"),{0:{type:"element",value:r[0]},1:{type:"element",value:r[1]}});for(var a={type:"element",value:r[n-1]},o=n-2;0<=o;){a=L(l(e,t,0===o?"templateStart":o<n-2?"templateMiddle":"templateEnd"),{0:{type:"element",value:r[o]},1:a}),o--}return a}function L(e,t){for(var r=[],n=e.indexOf("{",0),a=0;-1<n&&n<e.length;){var o=e.indexOf("}",n);if(o<=n)throw new Error("endIndex "+o+" should be bigger than beginIndex "+n);a<n&&r.push({type:"literal",value:e.slice(a,n)});var l=e.slice(n+1,o);if(!(l in t))throw new Error("Missing key "+l+" from placeables");var i=t[l];if(Array.isArray(i))for(var u=0,c=i;u<c.length;u++){var f=c[u];r.push(f)}else r.push(i);a=o+1,n=e.indexOf("{",a)}if(a<e.length){var s=e.slice(a,e.length);r.push({type:"literal",value:s})}return r}var T=(w.prototype.format=function(e){d(this,"format");var t="",r=b(w.__INTERNAL_SLOT_MAP__,this,g(e));if(!Array.isArray(r))return r.value;for(var n=0,a=r;n<a.length;n++)t+=a[n].value;return t},w.prototype.formatToParts=function(e){d(this,"format");var t=b(w.__INTERNAL_SLOT_MAP__,this,g(e));if(!Array.isArray(t))return[t];for(var r=[],n=0,a=t;n<a.length;n++){var o=a[n];r.push(h({},o))}return r},w.prototype.resolvedOptions=function(){return d(this,"resolvedOptions"),{locale:l(w.__INTERNAL_SLOT_MAP__,this,"locale"),type:l(w.__INTERNAL_SLOT_MAP__,this,"type"),style:l(w.__INTERNAL_SLOT_MAP__,this,"style")}},w.supportedLocalesOf=function(e,t){return function(e,t,r){return void 0!==r&&p(r=s(r),"localeMatcher","string",["lookup","best fit"],"best fit"),a(e,t)}(w.availableLocales,O(e),t)},w.__addLocaleData=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var r=function(t){Object.keys(y(t.availableLocales,Object.keys(t.aliases),Object.keys(t.parentLocales)).reduce(function(e,t){return e[t]=!0,e},{})).forEach(function(e){try{w.localeData[e]=function(e,t){var r=function(e,t,r){var n=[e];t[e]&&(e=t[e],n.push(e));var a=r[e];a&&n.push(a);for(var o=e.split("-"),l=o.length;1<l;l--)n.push(o.slice(0,l-1).join("-"));return n}(e,t.aliases,t.parentLocales),n=r.map(function(e){return t.data[e]}).filter(Boolean);if(!n.length)throw new i('Missing locale data for "'+e+'", lookup hierarchy: '+r.join(", "));return n.reverse(),n.reduce(function(e,t){return o(o({},e),t)},{})}(e,t)}catch(e){}})},n=0,a=e;n<a.length;n++)r(a[n]);w.availableLocales=Object.keys(w.localeData),w.__defaultLocale||(w.__defaultLocale=w.availableLocales[0])},w.getDefaultLocale=function(){return w.__defaultLocale},w.localeData={},w.availableLocales=[],w.__defaultLocale="en",w.relevantExtensionKeys=[],w.polyfilled=!0,w.__INTERNAL_SLOT_MAP__=new WeakMap,w);function w(e,t){if(!(this&&this instanceof w?this.constructor:void 0))throw new TypeError("Intl.ListFormat must be called with 'new'");_(w.__INTERNAL_SLOT_MAP__,this,"initializedListFormat",!0);var r=O(e),n=Object.create(null),a=void 0===t?Object.create(null):s(t),o=p(a,"localeMatcher","string",["best fit","lookup"],"best fit");n.localeMatcher=o;var l=w.localeData,i=v(w.getDefaultLocale)(w.availableLocales,r,n,w.relevantExtensionKeys,l);_(w.__INTERNAL_SLOT_MAP__,this,"locale",i.locale);var u=p(a,"type","string",["conjunction","disjunction","unit"],"conjunction");_(w.__INTERNAL_SLOT_MAP__,this,"type",u);var c=p(a,"style","string",["long","short","narrow"],"long");_(w.__INTERNAL_SLOT_MAP__,this,"style",c);var f=l[i.dataLocale][u][c];_(w.__INTERNAL_SLOT_MAP__,this,"templatePair",f.pair),_(w.__INTERNAL_SLOT_MAP__,this,"templateStart",f.start),_(w.__INTERNAL_SLOT_MAP__,this,"templateMiddle",f.middle),_(w.__INTERNAL_SLOT_MAP__,this,"templateEnd",f.end)}try{"undefined"!=typeof Symbol&&Object.defineProperty(T.prototype,Symbol.toStringTag,{value:"Intl.ListFormat",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype.constructor,"length",{value:0,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(T.supportedLocalesOf,"length",{value:1,writable:!1,enumerable:!1,configurable:!0})}catch(e){}e.default=T,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).IntlRelativeTimeFormat={})}(this,function(e){"use strict";function O(e,t,r){if(void 0===r&&(r=Error),!e)throw new r(t)}function s(e){if(null==e)throw new TypeError("undefined/null cannot be converted to object");return Object(e)}function p(e,t,r,n,a){var o=e[t];if(void 0===o)return a;if("boolean"!==r&&"string"!==r)throw new TypeError("invalid type");if("boolean"===r&&(o=Boolean(o)),"string"===r&&(o=String(o)),void 0!==n&&!n.filter(function(e){return e==o}).length)throw new RangeError(o+" in not within "+n);return o}function _(e,t,r,n){e.get(t)||e.set(t,Object.create(null)),e.get(t)[r]=n}function l(e,t,r){var n=e.get(t);if(!n)throw new TypeError(t+" InternalSlot has not been initialized");return n[r]}function m(e){var t=Intl.getCanonicalLocales;return"function"==typeof t?t(e):Intl.NumberFormat.supportedLocalesOf(e||"")}var n,t=(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)}),o=function(){return(o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)};function v(e){var b=function(u){return function(e,t){for(var r={locale:""},n=0,a=t;n<a.length;n++){var o=a[n],l=o.replace(c,""),i=f(e,l);if(i)return r.locale=i,o!==l&&(r.extension=o.slice(l.length+1,o.length)),r}return r.locale=u(),r}}(e),L=function(u){return function(e,t){for(var r={locale:""},n=0,a=t;n<a.length;n++){var o=a[n],l=o.replace(c,""),i=f(e,l);if(i)return r.locale=i,o!==l&&(r.extension=o.slice(l.length+1,o.length)),r}return r.locale=u(),r}}(e);return function(e,t,r,n,a){for(var o,l=(o="lookup"===r.localeMatcher?b(e,t):L(e,t)).locale,i={locale:"",dataLocale:l},u="-u",c=0,f=n;c<f.length;c++){var s=f[c],p=a[l];O("object"==typeof p&&null!==p,"locale data "+s+" must be an object");var _=p[s];O(Array.isArray(_),"keyLocaleData must be an array");var v=_[0];O("string"==typeof v||null===v,"value must be string or null");var h="";if(o.extension){var y=A(o.extension,s);void 0!==y&&(""!==y?~_.indexOf(y)&&(h="-"+s+"-"+(v=y)):~y.indexOf("true")&&(v="true",h="-"+s))}if(s in r){var d=r[s];O("string"==typeof d||null==d,"optionsValue must be String, Undefined or Null"),~_.indexOf(d)&&d!==v&&(v=d,h="")}i[s]=v,u+=h}if(2<u.length){var g=l.indexOf("-x-");if(-1===g)l+=u;else l=l.slice(0,g)+u+l.slice(g,l.length);l=m(l)[0]}return i.locale=l,i}}function A(e,t){O(2===t.length,"key must have 2 elements");var r=e.length,n="-"+t+"-",a=e.indexOf(n);if(-1!==a){for(var o=a+4,l=o,i=o,u=!1;!u;){var c=e.indexOf("-",i);2===(-1===c?r-i:c-i)?u=!0:-1===c?(l=r,u=!0):i=(l=c)+1}return e.slice(o,l)}if(n="-"+t,-1!==(a=e.indexOf(n))&&a+3===r)return""}var c=/-u(?:-[0-9a-z]{2,8})+/gi;function f(e,t){for(var r=t;;){if(~e.indexOf(r))return r;var n=r.lastIndexOf("-");if(!~n)return;2<=n&&"-"===r[n-2]&&(n-=2),r=r.slice(0,n)}}function a(e,t){for(var r=[],n=0,a=t;n<a.length;n++){var o=f(e,a[n].replace(c,""));o&&r.push(o)}return r}var r,i=(r=Error,t(u,r),u);function u(){var e=null!==r&&r.apply(this,arguments)||this;return e.type="MISSING_LOCALE_DATA",e}var h=function(){return(h=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var a in t=arguments[r])Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a]);return e}).apply(this,arguments)},y=function(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),a=0;for(t=0;t<r;t++)for(var o=arguments[t],l=0,i=o.length;l<i;l++,a++)n[a]=o[l];return n};function d(e,t){if(!(e instanceof T))throw new TypeError("Method Intl.ListFormat.prototype."+t+" called on incompatible receiver "+String(e))}function g(e){if(void 0===e)return[];for(var t=[],r=0,n=e;r<n.length;r++){var a=n[r];if("string"!=typeof a)throw new TypeError("array list["+e.indexOf(a)+"] is not type String");t.push(a)}return t}function b(e,t,r){var n=r.length;if(0===n)return[];if(2===n)return L(l(e,t,"templatePair"),{0:{type:"element",value:r[0]},1:{type:"element",value:r[1]}});for(var a={type:"element",value:r[n-1]},o=n-2;0<=o;){a=L(l(e,t,0===o?"templateStart":o<n-2?"templateMiddle":"templateEnd"),{0:{type:"element",value:r[o]},1:a}),o--}return a}function L(e,t){for(var r=[],n=0,a=function(e){for(var t=[],r=e.indexOf("{"),n=0,a=0,o=e.length;r<e.length&&-1<r;)O(r<(n=e.indexOf("}",r)),"Invalid pattern "+e),a<r&&t.push({type:"literal",value:e.substring(a,r)}),t.push({type:e.substring(r+1,n),value:void 0}),a=n+1,r=e.indexOf("{",a);return a<o&&t.push({type:"literal",value:e.substring(a,o)}),t}(e);n<a.length;n++){var o=a[n],l=o.type;if("literal"===o.type)r.push({type:"literal",value:o.value});else{O(l in t,l+" is missing from placables");var i=t[l];Array.isArray(i)?r.push.apply(r,i):r.push(i)}}return r}var T=(N.prototype.format=function(e){d(this,"format");var t="",r=b(N.__INTERNAL_SLOT_MAP__,this,g(e));if(!Array.isArray(r))return r.value;for(var n=0,a=r;n<a.length;n++)t+=a[n].value;return t},N.prototype.formatToParts=function(e){d(this,"format");var t=b(N.__INTERNAL_SLOT_MAP__,this,g(e));if(!Array.isArray(t))return[t];for(var r=[],n=0,a=t;n<a.length;n++){var o=a[n];r.push(h({},o))}return r},N.prototype.resolvedOptions=function(){return d(this,"resolvedOptions"),{locale:l(N.__INTERNAL_SLOT_MAP__,this,"locale"),type:l(N.__INTERNAL_SLOT_MAP__,this,"type"),style:l(N.__INTERNAL_SLOT_MAP__,this,"style")}},N.supportedLocalesOf=function(e,t){return function(e,t,r){return void 0!==r&&p(r=s(r),"localeMatcher","string",["lookup","best fit"],"best fit"),a(e,t)}(N.availableLocales,m(e),t)},N.__addLocaleData=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];for(var r=function(t){Object.keys(y(t.availableLocales,Object.keys(t.aliases),Object.keys(t.parentLocales)).reduce(function(e,t){return e[t]=!0,e},{})).forEach(function(e){try{N.localeData[e]=function(e,t){var r=function(e,t,r){var n=[e];t[e]&&(e=t[e],n.push(e));var a=r[e];a&&n.push(a);for(var o=e.split("-"),l=o.length;1<l;l--)n.push(o.slice(0,l-1).join("-"));return n}(e,t.aliases,t.parentLocales),n=r.map(function(e){return t.data[e]}).filter(Boolean);if(!n.length)throw new i('Missing locale data for "'+e+'", lookup hierarchy: '+r.join(", "));return n.reverse(),n.reduce(function(e,t){return o(o({},e),t)},{})}(e,t)}catch(e){}})},n=0,a=e;n<a.length;n++)r(a[n]);N.availableLocales=Object.keys(N.localeData),N.__defaultLocale||(N.__defaultLocale=N.availableLocales[0])},N.getDefaultLocale=function(){return N.__defaultLocale},N.localeData={},N.availableLocales=[],N.__defaultLocale="en",N.relevantExtensionKeys=[],N.polyfilled=!0,N.__INTERNAL_SLOT_MAP__=new WeakMap,N);function N(e,t){if(!(this&&this instanceof N?this.constructor:void 0))throw new TypeError("Intl.ListFormat must be called with 'new'");_(N.__INTERNAL_SLOT_MAP__,this,"initializedListFormat",!0);var r=m(e),n=Object.create(null),a=void 0===t?Object.create(null):s(t),o=p(a,"localeMatcher","string",["best fit","lookup"],"best fit");n.localeMatcher=o;var l=N.localeData,i=v(N.getDefaultLocale)(N.availableLocales,r,n,N.relevantExtensionKeys,l);_(N.__INTERNAL_SLOT_MAP__,this,"locale",i.locale);var u=p(a,"type","string",["conjunction","disjunction","unit"],"conjunction");_(N.__INTERNAL_SLOT_MAP__,this,"type",u);var c=p(a,"style","string",["long","short","narrow"],"long");_(N.__INTERNAL_SLOT_MAP__,this,"style",c);var f=l[i.dataLocale][u][c];_(N.__INTERNAL_SLOT_MAP__,this,"templatePair",f.pair),_(N.__INTERNAL_SLOT_MAP__,this,"templateStart",f.start),_(N.__INTERNAL_SLOT_MAP__,this,"templateMiddle",f.middle),_(N.__INTERNAL_SLOT_MAP__,this,"templateEnd",f.end)}try{"undefined"!=typeof Symbol&&Object.defineProperty(T.prototype,Symbol.toStringTag,{value:"Intl.ListFormat",writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(T.prototype.constructor,"length",{value:0,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(T.supportedLocalesOf,"length",{value:1,writable:!1,enumerable:!1,configurable:!0})}catch(e){}e.default=T,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=intl-listformat.min.js.map

@@ -6,2 +6,9 @@ (function (factory) {

function invariant(condition, message, Err) {
if (Err === void 0) { Err = Error; }
if (!condition) {
throw new Err(message);
}
}
/**

@@ -59,2 +66,35 @@ * https://tc39.es/ecma262/#sec-toobject

}
function isLiteralPart(patternPart) {
return patternPart.type === 'literal';
}
function partitionPattern(pattern) {
var result = [];
var beginIndex = pattern.indexOf('{');
var endIndex = 0;
var nextIndex = 0;
var length = pattern.length;
while (beginIndex < pattern.length && beginIndex > -1) {
endIndex = pattern.indexOf('}', beginIndex);
invariant(endIndex > beginIndex, "Invalid pattern " + pattern);
if (beginIndex > nextIndex) {
result.push({
type: 'literal',
value: pattern.substring(nextIndex, beginIndex),
});
}
result.push({
type: pattern.substring(beginIndex + 1, endIndex),
value: undefined,
});
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < length) {
result.push({
type: 'literal',
value: pattern.substring(nextIndex, length),
});
}
return result;
}

@@ -74,9 +114,2 @@ /**

function invariant(condition, message, Err) {
if (Err === void 0) { Err = Error; }
if (!condition) {
throw new Err(message);
}
}
var __extends = (undefined && undefined.__extends) || (function () {

@@ -423,37 +456,24 @@ var extendStatics = function (d, b) {

function deconstructPattern(pattern, placeables) {
var patternParts = partitionPattern(pattern);
var result = [];
var beginIndex = pattern.indexOf('{', 0);
var nextIndex = 0;
while (beginIndex > -1 && beginIndex < pattern.length) {
var endIndex = pattern.indexOf('}', beginIndex);
if (endIndex <= beginIndex) {
throw new Error("endIndex " + endIndex + " should be bigger than beginIndex " + beginIndex);
}
if (beginIndex > nextIndex) {
for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
var patternPart = patternParts_1[_i];
var part = patternPart.type;
if (isLiteralPart(patternPart)) {
result.push({
type: 'literal',
value: pattern.slice(nextIndex, beginIndex),
value: patternPart.value,
});
}
var part = pattern.slice(beginIndex + 1, endIndex);
if (!(part in placeables)) {
throw new Error("Missing key " + part + " from placeables");
}
var subst = placeables[part];
if (Array.isArray(subst)) {
for (var _i = 0, subst_1 = subst; _i < subst_1.length; _i++) {
var s = subst_1[_i];
result.push(s);
else {
invariant(part in placeables, part + " is missing from placables");
var subst = placeables[part];
if (Array.isArray(subst)) {
result.push.apply(result, subst);
}
else {
result.push(subst);
}
}
else {
result.push(subst);
}
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < pattern.length) {
var literal = pattern.slice(nextIndex, pattern.length);
result.push({ type: 'literal', value: literal });
}
return result;

@@ -460,0 +480,0 @@ }

@@ -1,2 +0,2 @@

import { ListPatternLocaleData, ListPatternFieldsData } from '@formatjs/intl-utils';
import { ListPatternLocaleData, ListPatternFieldsData, LiteralPart } from '@formatjs/intl-utils';
export interface IntlListFormatOptions {

@@ -54,6 +54,2 @@ /**

export declare type Part = LiteralPart | ElementPart;
export interface LiteralPart {
type: 'literal';
value: string;
}
export interface ElementPart {

@@ -60,0 +56,0 @@ type: 'element';

@@ -19,3 +19,3 @@ var __assign = (this && this.__assign) || function () {

};
import { toObject, getOption, unpackData, setInternalSlot, getCanonicalLocales, supportedLocales, createResolveLocale, getInternalSlot, } from '@formatjs/intl-utils';
import { toObject, getOption, unpackData, setInternalSlot, getCanonicalLocales, supportedLocales, createResolveLocale, getInternalSlot, partitionPattern, invariant, isLiteralPart, } from '@formatjs/intl-utils';
function validateInstance(instance, method) {

@@ -79,37 +79,24 @@ if (!(instance instanceof ListFormat)) {

function deconstructPattern(pattern, placeables) {
var patternParts = partitionPattern(pattern);
var result = [];
var beginIndex = pattern.indexOf('{', 0);
var nextIndex = 0;
while (beginIndex > -1 && beginIndex < pattern.length) {
var endIndex = pattern.indexOf('}', beginIndex);
if (endIndex <= beginIndex) {
throw new Error("endIndex " + endIndex + " should be bigger than beginIndex " + beginIndex);
}
if (beginIndex > nextIndex) {
for (var _i = 0, patternParts_1 = patternParts; _i < patternParts_1.length; _i++) {
var patternPart = patternParts_1[_i];
var part = patternPart.type;
if (isLiteralPart(patternPart)) {
result.push({
type: 'literal',
value: pattern.slice(nextIndex, beginIndex),
value: patternPart.value,
});
}
var part = pattern.slice(beginIndex + 1, endIndex);
if (!(part in placeables)) {
throw new Error("Missing key " + part + " from placeables");
}
var subst = placeables[part];
if (Array.isArray(subst)) {
for (var _i = 0, subst_1 = subst; _i < subst_1.length; _i++) {
var s = subst_1[_i];
result.push(s);
else {
invariant(part in placeables, part + " is missing from placables");
var subst = placeables[part];
if (Array.isArray(subst)) {
result.push.apply(result, subst);
}
else {
result.push(subst);
}
}
else {
result.push(subst);
}
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < pattern.length) {
var literal = pattern.slice(nextIndex, pattern.length);
result.push({ type: 'literal', value: literal });
}
return result;

@@ -116,0 +103,0 @@ }

import { ListPatternFieldsData } from '@formatjs/intl-utils';
import { ListPatternLocaleData } from '@formatjs/intl-utils';
import { LiteralPart } from '@formatjs/intl-utils';

@@ -52,7 +53,2 @@ export declare interface ElementPart {

export declare interface LiteralPart {
type: 'literal';
value: string;
}
export declare type Part = LiteralPart | ElementPart;

@@ -59,0 +55,0 @@

{
"name": "@formatjs/intl-listformat",
"version": "1.2.7",
"version": "1.3.0",
"description": "Formats JS list in a i18n-safe way",

@@ -21,6 +21,6 @@ "keywords": [

"devDependencies": {
"formatjs-extract-cldr-data": "^9.9.7"
"formatjs-extract-cldr-data": "^9.9.8"
},
"dependencies": {
"@formatjs/intl-utils": "^1.4.4"
"@formatjs/intl-utils": "^1.5.0"
},

@@ -48,3 +48,3 @@ "main": "dist/index.js",

"license": "MIT",
"gitHead": "6d6aa5ccec18f2f04be72a6e510193c0a1210725"
"gitHead": "3ea32d0792af5e0757bede58b8b6235202ea74f2"
}

@@ -13,2 +13,6 @@ import {

ListPatternData,
partitionPattern,
invariant,
isLiteralPart,
LiteralPart,
} from '@formatjs/intl-utils';

@@ -71,7 +75,2 @@

export interface LiteralPart {
type: 'literal';
value: string;
}
export interface ElementPart {

@@ -167,37 +166,21 @@ type: 'element';

) {
const patternParts = partitionPattern(pattern);
const result: Placeable[] = [];
let beginIndex = pattern.indexOf('{', 0);
let nextIndex = 0;
while (beginIndex > -1 && beginIndex < pattern.length) {
const endIndex = pattern.indexOf('}', beginIndex);
if (endIndex <= beginIndex) {
throw new Error(
`endIndex ${endIndex} should be bigger than beginIndex ${beginIndex}`
);
}
if (beginIndex > nextIndex) {
for (const patternPart of patternParts) {
const {type: part} = patternPart;
if (isLiteralPart(patternPart)) {
result.push({
type: 'literal',
value: pattern.slice(nextIndex, beginIndex),
value: patternPart.value,
});
}
const part = pattern.slice(beginIndex + 1, endIndex);
if (!(part in placeables)) {
throw new Error(`Missing key ${part} from placeables`);
}
const subst = placeables[part];
if (Array.isArray(subst)) {
for (const s of subst) {
result.push(s);
} else {
invariant(part in placeables, `${part} is missing from placables`);
const subst = placeables[part];
if (Array.isArray(subst)) {
result.push(...subst);
} else {
result.push(subst);
}
} else {
result.push(subst);
}
nextIndex = endIndex + 1;
beginIndex = pattern.indexOf('{', nextIndex);
}
if (nextIndex < pattern.length) {
const literal = pattern.slice(nextIndex, pattern.length);
result.push({type: 'literal', value: literal});
}
return result;

@@ -204,0 +187,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 too big to display

Sorry, the diff of this file is not supported yet

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc