Socket
Socket
Sign inDemoInstall

@formatjs/intl-localematcher

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@formatjs/intl-localematcher - npm Package Compare versions

Comparing version 0.5.1 to 0.5.2

6

lib/abstract/BestAvailableLocale.js

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BestAvailableLocale = void 0;
/**

@@ -9,3 +6,3 @@ * https://tc39.es/ecma402/#sec-bestavailablelocale

*/
function BestAvailableLocale(availableLocales, locale) {
export function BestAvailableLocale(availableLocales, locale) {
var candidate = locale;

@@ -26,2 +23,1 @@ while (true) {

}
exports.BestAvailableLocale = BestAvailableLocale;

12

lib/abstract/BestFitMatcher.js

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BestFitMatcher = void 0;
var utils_1 = require("./utils");
import { UNICODE_EXTENSION_SEQUENCE_REGEX, findBestMatch } from './utils';
/**

@@ -11,3 +8,3 @@ * https://tc39.es/ecma402/#sec-bestfitmatcher

*/
function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
export function BestFitMatcher(availableLocales, requestedLocales, getDefaultLocale) {
var foundLocale;

@@ -17,3 +14,3 @@ var extension;

var noExtensionLocaleMap = requestedLocales.reduce(function (all, l) {
var noExtensionLocale = l.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, '');
var noExtensionLocale = l.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, '');
noExtensionLocales.push(noExtensionLocale);

@@ -23,3 +20,3 @@ all[noExtensionLocale] = l;

}, {});
var result = (0, utils_1.findBestMatch)(noExtensionLocales, availableLocales);
var result = findBestMatch(noExtensionLocales, availableLocales);
if (result.matchedSupportedLocale && result.matchedDesiredLocale) {

@@ -38,2 +35,1 @@ foundLocale = result.matchedSupportedLocale;

}
exports.BestFitMatcher = BestFitMatcher;

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CanonicalizeLocaleList = void 0;
/**

@@ -8,6 +5,5 @@ * http://ecma-international.org/ecma-402/7.0/index.html#sec-canonicalizelocalelist

*/
function CanonicalizeLocaleList(locales) {
export function CanonicalizeLocaleList(locales) {
// TODO
return Intl.getCanonicalLocales(locales);
}
exports.CanonicalizeLocaleList = CanonicalizeLocaleList;

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LookupMatcher = void 0;
var BestAvailableLocale_1 = require("./BestAvailableLocale");
var utils_1 = require("./utils");
import { BestAvailableLocale } from './BestAvailableLocale';
import { UNICODE_EXTENSION_SEQUENCE_REGEX } from './utils';
/**

@@ -12,8 +9,8 @@ * https://tc39.es/ecma402/#sec-lookupmatcher

*/
function LookupMatcher(availableLocales, requestedLocales, getDefaultLocale) {
export function LookupMatcher(availableLocales, requestedLocales, getDefaultLocale) {
var result = { locale: '' };
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) {
var locale = requestedLocales_1[_i];
var noExtensionLocale = locale.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, '');
var availableLocale = (0, BestAvailableLocale_1.BestAvailableLocale)(availableLocales, noExtensionLocale);
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, '');
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale);
if (availableLocale) {

@@ -30,2 +27,1 @@ result.locale = availableLocale;

}
exports.LookupMatcher = LookupMatcher;

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LookupSupportedLocales = void 0;
var BestAvailableLocale_1 = require("./BestAvailableLocale");
var utils_1 = require("./utils");
import { BestAvailableLocale } from './BestAvailableLocale';
import { UNICODE_EXTENSION_SEQUENCE_REGEX } from './utils';
/**

@@ -11,8 +8,8 @@ * https://tc39.es/ecma402/#sec-lookupsupportedlocales

*/
function LookupSupportedLocales(availableLocales, requestedLocales) {
export function LookupSupportedLocales(availableLocales, requestedLocales) {
var subset = [];
for (var _i = 0, requestedLocales_1 = requestedLocales; _i < requestedLocales_1.length; _i++) {
var locale = requestedLocales_1[_i];
var noExtensionLocale = locale.replace(utils_1.UNICODE_EXTENSION_SEQUENCE_REGEX, '');
var availableLocale = (0, BestAvailableLocale_1.BestAvailableLocale)(availableLocales, noExtensionLocale);
var noExtensionLocale = locale.replace(UNICODE_EXTENSION_SEQUENCE_REGEX, '');
var availableLocale = BestAvailableLocale(availableLocales, noExtensionLocale);
if (availableLocale) {

@@ -24,2 +21,1 @@ subset.push(availableLocale);

}
exports.LookupSupportedLocales = LookupSupportedLocales;

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.regions = void 0;
// This file is generated from regions-gen.ts
exports.regions = {
export var regions = {
"001": [

@@ -7,0 +4,0 @@ "001",

@@ -1,19 +0,16 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResolveLocale = void 0;
var BestFitMatcher_1 = require("./BestFitMatcher");
var LookupMatcher_1 = require("./LookupMatcher");
var UnicodeExtensionValue_1 = require("./UnicodeExtensionValue");
var utils_1 = require("./utils");
import { BestFitMatcher } from './BestFitMatcher';
import { LookupMatcher } from './LookupMatcher';
import { UnicodeExtensionValue } from './UnicodeExtensionValue';
import { invariant } from './utils';
/**
* https://tc39.es/ecma402/#sec-resolvelocale
*/
function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
export function ResolveLocale(availableLocales, requestedLocales, options, relevantExtensionKeys, localeData, getDefaultLocale) {
var matcher = options.localeMatcher;
var r;
if (matcher === 'lookup') {
r = (0, LookupMatcher_1.LookupMatcher)(Array.from(availableLocales), requestedLocales, getDefaultLocale);
r = LookupMatcher(Array.from(availableLocales), requestedLocales, getDefaultLocale);
}
else {
r = (0, BestFitMatcher_1.BestFitMatcher)(Array.from(availableLocales), requestedLocales, getDefaultLocale);
r = BestFitMatcher(Array.from(availableLocales), requestedLocales, getDefaultLocale);
}

@@ -25,12 +22,12 @@ var foundLocale = r.locale;

var key = relevantExtensionKeys_1[_i];
(0, utils_1.invariant)(foundLocale in localeData, "Missing locale data for ".concat(foundLocale));
invariant(foundLocale in localeData, "Missing locale data for ".concat(foundLocale));
var foundLocaleData = localeData[foundLocale];
(0, utils_1.invariant)(typeof foundLocaleData === 'object' && foundLocaleData !== null, "locale data ".concat(key, " must be an object"));
invariant(typeof foundLocaleData === 'object' && foundLocaleData !== null, "locale data ".concat(key, " must be an object"));
var keyLocaleData = foundLocaleData[key];
(0, utils_1.invariant)(Array.isArray(keyLocaleData), "keyLocaleData for ".concat(key, " must be an array"));
invariant(Array.isArray(keyLocaleData), "keyLocaleData for ".concat(key, " must be an array"));
var value = keyLocaleData[0];
(0, utils_1.invariant)(typeof value === 'string' || value === null, "value must be string or null but got ".concat(typeof value, " in key ").concat(key));
invariant(typeof value === 'string' || value === null, "value must be string or null but got ".concat(typeof value, " in key ").concat(key));
var supportedExtensionAddition = '';
if (r.extension) {
var requestedValue = (0, UnicodeExtensionValue_1.UnicodeExtensionValue)(r.extension, key);
var requestedValue = UnicodeExtensionValue(r.extension, key);
if (requestedValue !== undefined) {

@@ -51,3 +48,3 @@ if (requestedValue !== '') {

var optionsValue = options[key];
(0, utils_1.invariant)(typeof optionsValue === 'string' ||
invariant(typeof optionsValue === 'string' ||
typeof optionsValue === 'undefined' ||

@@ -80,2 +77,1 @@ optionsValue === null, 'optionsValue must be String, Undefined or Null');

}
exports.ResolveLocale = ResolveLocale;

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export {};

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UnicodeExtensionValue = void 0;
var utils_1 = require("./utils");
import { invariant } from './utils';
/**

@@ -10,4 +7,4 @@ * https://tc39.es/ecma402/#sec-unicodeextensionvalue

*/
function UnicodeExtensionValue(extension, key) {
(0, utils_1.invariant)(key.length === 2, 'key must have 2 elements');
export function UnicodeExtensionValue(extension, key) {
invariant(key.length === 2, 'key must have 2 elements');
var size = extension.length;

@@ -51,2 +48,1 @@ var searchValue = "-".concat(key, "-");

}
exports.UnicodeExtensionValue = UnicodeExtensionValue;

@@ -1,9 +0,6 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findBestMatch = exports.findMatchingDistance = exports.invariant = exports.UNICODE_EXTENSION_SEQUENCE_REGEX = void 0;
var tslib_1 = require("tslib");
var languageMatching_1 = require("./languageMatching");
var regions_generated_1 = require("./regions.generated");
exports.UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi;
function invariant(condition, message, Err) {
import { __spreadArray } from "tslib";
import { data as jsonData } from './languageMatching';
import { regions } from './regions.generated';
export var UNICODE_EXTENSION_SEQUENCE_REGEX = /-u(?:-[0-9a-z]{2,8})+/gi;
export function invariant(condition, message, Err) {
if (Err === void 0) { Err = Error; }

@@ -14,3 +11,2 @@ if (!condition) {

}
exports.invariant = invariant;
// This is effectively 2 languages in 2 different regions not even in the same cluster

@@ -22,5 +18,5 @@ var DEFAULT_MATCHING_THRESHOLD = 840;

if (!PROCESSED_DATA) {
var paradigmLocales = (_b = (_a = languageMatching_1.data.supplemental.languageMatching['written-new'][0]) === null || _a === void 0 ? void 0 : _a.paradigmLocales) === null || _b === void 0 ? void 0 : _b._locales.split(' ');
var matchVariables = languageMatching_1.data.supplemental.languageMatching['written-new'].slice(1, 5);
var data = languageMatching_1.data.supplemental.languageMatching['written-new'].slice(5);
var paradigmLocales = (_b = (_a = jsonData.supplemental.languageMatching['written-new'][0]) === null || _a === void 0 ? void 0 : _a.paradigmLocales) === null || _b === void 0 ? void 0 : _b._locales.split(' ');
var matchVariables = jsonData.supplemental.languageMatching['written-new'].slice(1, 5);
var data = jsonData.supplemental.languageMatching['written-new'].slice(5);
var matches = data.map(function (d) {

@@ -44,3 +40,3 @@ var key = Object.keys(d)[0];

}, {}),
paradigmLocales: tslib_1.__spreadArray(tslib_1.__spreadArray([], paradigmLocales, true), paradigmLocales.map(function (l) {
paradigmLocales: __spreadArray(__spreadArray([], paradigmLocales, true), paradigmLocales.map(function (l) {
return new Intl.Locale(l.replace(/_/g, '-')).maximize().toString();

@@ -61,4 +57,4 @@ }), true),

var expandedMatchedRegions = matchRegions
.map(function (r) { return regions_generated_1.regions[r] || [r]; })
.reduce(function (all, list) { return tslib_1.__spreadArray(tslib_1.__spreadArray([], all, true), list, true); }, []);
.map(function (r) { return regions[r] || [r]; })
.reduce(function (all, list) { return __spreadArray(__spreadArray([], all, true), list, true); }, []);
matches && (matches = !(expandedMatchedRegions.indexOf(locale.region || '') > 1 !=

@@ -102,3 +98,3 @@ shouldInclude));

}
function findMatchingDistance(desired, supported) {
export function findMatchingDistance(desired, supported) {
var desiredLocale = new Intl.Locale(desired).maximize();

@@ -145,4 +141,3 @@ var supportedLocale = new Intl.Locale(supported).maximize();

}
exports.findMatchingDistance = findMatchingDistance;
function findBestMatch(requestedLocales, supportedLocales, threshold) {
export function findBestMatch(requestedLocales, supportedLocales, threshold) {
if (threshold === void 0) { threshold = DEFAULT_MATCHING_THRESHOLD; }

@@ -176,2 +171,1 @@ var lowestDistance = Infinity;

}
exports.findBestMatch = findBestMatch;

@@ -1,15 +0,9 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ResolveLocale = exports.LookupSupportedLocales = exports.match = void 0;
var CanonicalizeLocaleList_1 = require("./abstract/CanonicalizeLocaleList");
var ResolveLocale_1 = require("./abstract/ResolveLocale");
function match(requestedLocales, availableLocales, defaultLocale, opts) {
return (0, ResolveLocale_1.ResolveLocale)(availableLocales, (0, CanonicalizeLocaleList_1.CanonicalizeLocaleList)(requestedLocales), {
import { CanonicalizeLocaleList } from './abstract/CanonicalizeLocaleList';
import { ResolveLocale } from './abstract/ResolveLocale';
export function match(requestedLocales, availableLocales, defaultLocale, opts) {
return ResolveLocale(availableLocales, CanonicalizeLocaleList(requestedLocales), {
localeMatcher: (opts === null || opts === void 0 ? void 0 : opts.algorithm) || 'best fit',
}, [], {}, function () { return defaultLocale; }).locale;
}
exports.match = match;
var LookupSupportedLocales_1 = require("./abstract/LookupSupportedLocales");
Object.defineProperty(exports, "LookupSupportedLocales", { enumerable: true, get: function () { return LookupSupportedLocales_1.LookupSupportedLocales; } });
var ResolveLocale_2 = require("./abstract/ResolveLocale");
Object.defineProperty(exports, "ResolveLocale", { enumerable: true, get: function () { return ResolveLocale_2.ResolveLocale; } });
export { LookupSupportedLocales } from './abstract/LookupSupportedLocales';
export { ResolveLocale } from './abstract/ResolveLocale';
MIT License
Copyright (c) 2021 FormatJS
Copyright (c) 2023 FormatJS

@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

{
"name": "@formatjs/intl-localematcher",
"version": "0.5.1",
"version": "0.5.2",
"description": "Intl.LocaleMatcher ponyfill",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is too big to display

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