@formatjs/intl-segmenter
Advanced tools
@@ -1,4 +0,6 @@ | ||
| import { Segmenter } from './src/segmenter'; | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var segmenter_1 = require("./src/segmenter"); | ||
| Object.defineProperty(Intl, 'Segmenter', { | ||
| value: Segmenter, | ||
| value: segmenter_1.Segmenter, | ||
| enumerable: false, | ||
@@ -5,0 +7,0 @@ writable: true, |
+6
-4
@@ -1,6 +0,8 @@ | ||
| import { Segmenter } from './src/segmenter'; | ||
| import { shouldPolyfill } from './should-polyfill'; | ||
| if (shouldPolyfill()) { | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var segmenter_1 = require("./src/segmenter"); | ||
| var should_polyfill_1 = require("./should-polyfill"); | ||
| if ((0, should_polyfill_1.shouldPolyfill)()) { | ||
| Object.defineProperty(Intl, 'Segmenter', { | ||
| value: Segmenter, | ||
| value: segmenter_1.Segmenter, | ||
| enumerable: false, | ||
@@ -7,0 +9,0 @@ writable: true, |
@@ -1,3 +0,7 @@ | ||
| export function shouldPolyfill() { | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.shouldPolyfill = void 0; | ||
| function shouldPolyfill() { | ||
| return !Intl.Segmenter; | ||
| } | ||
| exports.shouldPolyfill = shouldPolyfill; |
@@ -1,2 +0,5 @@ | ||
| export var replaceVariables = function (variables, input) { | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.isSurrogate = exports.replaceVariables = void 0; | ||
| var replaceVariables = function (variables, input) { | ||
| var findVarRegex = /\$[A-Za-z0-9_]+/gm; | ||
@@ -10,3 +13,4 @@ return input.replaceAll(findVarRegex, function (match) { | ||
| }; | ||
| export var isSurrogate = function (str, pos) { | ||
| exports.replaceVariables = replaceVariables; | ||
| var isSurrogate = function (str, pos) { | ||
| return (0xd800 <= str.charCodeAt(pos - 1) && | ||
@@ -17,2 +21,3 @@ str.charCodeAt(pos - 1) <= 0xdbff && | ||
| }; | ||
| exports.isSurrogate = isSurrogate; | ||
| // alternative surrogate check mimicking the java implementation | ||
@@ -19,0 +24,0 @@ // const TRAIL_SURROGATE_BITMASK = 0xfffffc00 |
+32
-29
@@ -1,6 +0,9 @@ | ||
| import { __assign, __spreadArray } from "tslib"; | ||
| import { SegmentationRules } from './cldr-segmentation-rules.generated'; | ||
| import { replaceVariables, isSurrogate } from './segmentation-utils'; | ||
| import { GetOption, SupportedLocales, CanonicalizeLocaleList, GetOptionsObject, getInternalSlot, setInternalSlot, getMultiInternalSlots, } from '@formatjs/ecma402-abstract'; | ||
| import { ResolveLocale } from '@formatjs/intl-localematcher'; | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.Segmenter = void 0; | ||
| var tslib_1 = require("tslib"); | ||
| var cldr_segmentation_rules_generated_1 = require("./cldr-segmentation-rules.generated"); | ||
| var segmentation_utils_1 = require("./segmentation-utils"); | ||
| var ecma402_abstract_1 = require("@formatjs/ecma402-abstract"); | ||
| var intl_localematcher_1 = require("@formatjs/intl-localematcher"); | ||
| /** | ||
@@ -17,3 +20,3 @@ * Adds $ to before rules and ^ to after rules for strickness | ||
| var generateRuleRegex = function (rule, variables, after) { | ||
| return new RegExp("".concat(after ? '^' : '').concat(replaceVariables(variables, rule)).concat(after ? '' : '$')); | ||
| return new RegExp("".concat(after ? '^' : '').concat((0, segmentation_utils_1.replaceVariables)(variables, rule)).concat(after ? '' : '$')); | ||
| }; | ||
@@ -42,3 +45,3 @@ var prepareLocaleSegmentationRules = function (segmentationTypeValue) { | ||
| }); }; | ||
| export var Segmenter = /** @class */ (function () { | ||
| var Segmenter = /** @class */ (function () { | ||
| function Segmenter(locales, options) { | ||
@@ -49,11 +52,11 @@ var _newTarget = this.constructor; | ||
| } | ||
| var requestedLocales = CanonicalizeLocaleList(locales); | ||
| options = GetOptionsObject(options); | ||
| var requestedLocales = (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales); | ||
| options = (0, ecma402_abstract_1.GetOptionsObject)(options); | ||
| var opt = Object.create(null); | ||
| var matcher = GetOption(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit'); | ||
| var matcher = (0, ecma402_abstract_1.GetOption)(options, 'localeMatcher', 'string', ['lookup', 'best fit'], 'best fit'); | ||
| opt.localeMatcher = matcher; | ||
| var granularity = GetOption(options, 'granularity', 'string', ['word', 'sentence', 'grapheme'], 'grapheme'); | ||
| var granularity = (0, ecma402_abstract_1.GetOption)(options, 'granularity', 'string', ['word', 'sentence', 'grapheme'], 'grapheme'); | ||
| setSlot(this, 'granularity', granularity); | ||
| //TODO: figure out correct availible locales | ||
| var r = ResolveLocale(Segmenter.availableLocales, //availible locales | ||
| var r = (0, intl_localematcher_1.ResolveLocale)(Segmenter.availableLocales, //availible locales | ||
| requestedLocales, opt, [], // there is no relevantExtensionKeys | ||
@@ -64,11 +67,11 @@ {}, function () { return ''; } //use only root rules | ||
| //root rules based on granularity | ||
| this.mergedSegmentationTypeValue = SegmentationRules.root[granularity]; | ||
| this.mergedSegmentationTypeValue = cldr_segmentation_rules_generated_1.SegmentationRules.root[granularity]; | ||
| //merge root rules with locale ones if locale is specified | ||
| if (r.locale.length) { | ||
| var localeOverrides = SegmentationRules[r.locale]; | ||
| var localeOverrides = cldr_segmentation_rules_generated_1.SegmentationRules[r.locale]; | ||
| if (granularity in localeOverrides) { | ||
| var localeSegmentationTypeValue = localeOverrides[granularity]; | ||
| this.mergedSegmentationTypeValue.variables = __assign(__assign({}, this.mergedSegmentationTypeValue.variables), localeSegmentationTypeValue.variables); | ||
| this.mergedSegmentationTypeValue.segmentRules = __assign(__assign({}, this.mergedSegmentationTypeValue.segmentRules), localeSegmentationTypeValue.segmentRules); | ||
| this.mergedSegmentationTypeValue.suppressions = __spreadArray(__spreadArray([], this.mergedSegmentationTypeValue.suppressions, true), localeSegmentationTypeValue.suppressions, true); | ||
| this.mergedSegmentationTypeValue.variables = tslib_1.__assign(tslib_1.__assign({}, this.mergedSegmentationTypeValue.variables), localeSegmentationTypeValue.variables); | ||
| this.mergedSegmentationTypeValue.segmentRules = tslib_1.__assign(tslib_1.__assign({}, this.mergedSegmentationTypeValue.segmentRules), localeSegmentationTypeValue.segmentRules); | ||
| this.mergedSegmentationTypeValue.suppressions = tslib_1.__spreadArray(tslib_1.__spreadArray([], this.mergedSegmentationTypeValue.suppressions, true), localeSegmentationTypeValue.suppressions, true); | ||
| } | ||
@@ -82,3 +85,2 @@ } | ||
| Segmenter.prototype.breaksAt = function (position, input) { | ||
| var _a; | ||
| var ruleSortedKeys = this.ruleSortedKeys; | ||
@@ -97,3 +99,3 @@ var rules = this.rules; | ||
| //number 0.1 chosen to mimic java implementation, but needs to execute after 0.2 and 0.3 to be inside the string bounds | ||
| if (isSurrogate(input, position)) { | ||
| if ((0, segmentation_utils_1.isSurrogate)(input, position)) { | ||
| return breaksAtResult(false, '0.1'); | ||
@@ -105,4 +107,4 @@ } | ||
| if ('suppressions' in mergedSegmentationTypeValue) { | ||
| for (var _i = 0, _b = mergedSegmentationTypeValue.suppressions; _i < _b.length; _i++) { | ||
| var suppressions = _b[_i]; | ||
| for (var _i = 0, _a = mergedSegmentationTypeValue.suppressions; _i < _a.length; _i++) { | ||
| var suppressions = _a[_i]; | ||
| if (stringBeforeBreak.trim().endsWith(suppressions)) { | ||
@@ -114,5 +116,5 @@ return breaksAtResult(false, '0.4'); | ||
| // loop through rules and find a match | ||
| for (var _c = 0, ruleSortedKeys_1 = ruleSortedKeys; _c < ruleSortedKeys_1.length; _c++) { | ||
| var ruleKey = ruleSortedKeys_1[_c]; | ||
| var before = (_a = rules[ruleKey], _a.before), after = _a.after, breaks = _a.breaks; | ||
| for (var _b = 0, ruleSortedKeys_1 = ruleSortedKeys; _b < ruleSortedKeys_1.length; _b++) { | ||
| var ruleKey = ruleSortedKeys_1[_b]; | ||
| var _c = rules[ruleKey], before = _c.before, after = _c.after, breaks = _c.breaks; | ||
| // for debugging | ||
@@ -145,11 +147,12 @@ // if (ruleKey === '16' && position === 4) { | ||
| checkReceiver(this, 'resolvedOptions'); | ||
| return __assign({}, getMultiInternalSlots(__INTERNAL_SLOT_MAP__, this, 'locale', 'granularity')); | ||
| return tslib_1.__assign({}, (0, ecma402_abstract_1.getMultiInternalSlots)(__INTERNAL_SLOT_MAP__, this, 'locale', 'granularity')); | ||
| }; | ||
| Segmenter.supportedLocalesOf = function (locales, options) { | ||
| return SupportedLocales(Segmenter.availableLocales, CanonicalizeLocaleList(locales), options); | ||
| return (0, ecma402_abstract_1.SupportedLocales)(Segmenter.availableLocales, (0, ecma402_abstract_1.CanonicalizeLocaleList)(locales), options); | ||
| }; | ||
| Segmenter.availableLocales = new Set(Object.keys(SegmentationRules).filter(function (key) { return key !== 'root'; })); | ||
| Segmenter.availableLocales = new Set(Object.keys(cldr_segmentation_rules_generated_1.SegmentationRules).filter(function (key) { return key !== 'root'; })); | ||
| Segmenter.polyfilled = true; | ||
| return Segmenter; | ||
| }()); | ||
| exports.Segmenter = Segmenter; | ||
| var createSegmentDataObject = function (segmenter, segment, index, input, matchingRule) { | ||
@@ -242,6 +245,6 @@ var returnValue = { | ||
| function getSlot(instance, key) { | ||
| return getInternalSlot(__INTERNAL_SLOT_MAP__, instance, key); | ||
| return (0, ecma402_abstract_1.getInternalSlot)(__INTERNAL_SLOT_MAP__, instance, key); | ||
| } | ||
| function setSlot(instance, key, value) { | ||
| setInternalSlot(__INTERNAL_SLOT_MAP__, instance, key, value); | ||
| (0, ecma402_abstract_1.setInternalSlot)(__INTERNAL_SLOT_MAP__, instance, key, value); | ||
| } | ||
@@ -248,0 +251,0 @@ function checkReceiver(receiver, methodName) { |
@@ -0,3 +1,5 @@ | ||
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| // @generated | ||
| // @ts-nocheck | ||
| import './polyfill-force'; | ||
| require("./polyfill-force"); |
+3
-3
| { | ||
| "name": "@formatjs/intl-segmenter", | ||
| "version": "11.5.0", | ||
| "version": "11.5.1", | ||
| "description": "Polyfill for Intl.Segmenter", | ||
@@ -23,4 +23,4 @@ "keywords": [ | ||
| "tslib": "^2.4.0", | ||
| "@formatjs/ecma402-abstract": "1.17.2", | ||
| "@formatjs/intl-localematcher": "0.4.2" | ||
| "@formatjs/intl-localematcher": "0.5.0", | ||
| "@formatjs/ecma402-abstract": "1.17.3" | ||
| }, | ||
@@ -27,0 +27,0 @@ "main": "index.js", |
+7
-7
@@ -44,3 +44,3 @@ "use strict"; | ||
| }); }; | ||
| var Segmenter = exports.Segmenter = /** @class */ (function () { | ||
| var Segmenter = /** @class */ (function () { | ||
| function Segmenter(locales, options) { | ||
@@ -82,3 +82,2 @@ var _newTarget = this.constructor; | ||
| Segmenter.prototype.breaksAt = function (position, input) { | ||
| var _a; | ||
| var ruleSortedKeys = this.ruleSortedKeys; | ||
@@ -104,4 +103,4 @@ var rules = this.rules; | ||
| if ('suppressions' in mergedSegmentationTypeValue) { | ||
| for (var _i = 0, _b = mergedSegmentationTypeValue.suppressions; _i < _b.length; _i++) { | ||
| var suppressions = _b[_i]; | ||
| for (var _i = 0, _a = mergedSegmentationTypeValue.suppressions; _i < _a.length; _i++) { | ||
| var suppressions = _a[_i]; | ||
| if (stringBeforeBreak.trim().endsWith(suppressions)) { | ||
@@ -113,5 +112,5 @@ return breaksAtResult(false, '0.4'); | ||
| // loop through rules and find a match | ||
| for (var _c = 0, ruleSortedKeys_1 = ruleSortedKeys; _c < ruleSortedKeys_1.length; _c++) { | ||
| var ruleKey = ruleSortedKeys_1[_c]; | ||
| var before = (_a = rules[ruleKey], _a.before), after = _a.after, breaks = _a.breaks; | ||
| for (var _b = 0, ruleSortedKeys_1 = ruleSortedKeys; _b < ruleSortedKeys_1.length; _b++) { | ||
| var ruleKey = ruleSortedKeys_1[_b]; | ||
| var _c = rules[ruleKey], before = _c.before, after = _c.after, breaks = _c.breaks; | ||
| // for debugging | ||
@@ -153,2 +152,3 @@ // if (ruleKey === '16' && position === 4) { | ||
| }()); | ||
| exports.Segmenter = Segmenter; | ||
| var createSegmentDataObject = function (segmenter, segment, index, input, matchingRule) { | ||
@@ -155,0 +155,0 @@ var returnValue = { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1054661
28.06%15760
85.32%103
0.98%+ Added
+ Added
- Removed
- Removed