Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

intl-locale-textinfo-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intl-locale-textinfo-polyfill - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

index.d.ts.map

4

CHANGES.md
# CHANGES for `intl-locale-textinfo-polyfill`
## 2.0.2
- fix: TS types
## 2.0.1

@@ -4,0 +8,0 @@

@@ -1,6 +0,59 @@

declare namespace Intl {
interface Locale {
// getTextInfo(): {direction: "ltr"|"rtl"}
textInfo: {direction: "ltr"|"rtl"}
}
declare module "lib/Locale" {
export default Locale;
class Locale {
/**
* @param {null|undefined|string} [str]
* @returns {null|undefined|string}
*/
static _escapeRegExpPattern(str?: null | undefined | string): null | undefined | string;
/**
* @param {string|null} [str]
* @param {boolean} [reserveReturnValue]
*/
static _toLowerCase(str?: string | null | undefined, reserveReturnValue?: boolean | undefined): string | false | null | undefined;
/**
* @param {string|null} [str]
* @param {boolean} [reserveReturnValue]
*/
static _toUpperCase(str?: string | null | undefined, reserveReturnValue?: boolean | undefined): string | false | null | undefined;
/**
* @param {string|null} [str]
* @param {string|null|string[]|boolean} [delimiter]
* @param {boolean} [reserveReturnValue]
*/
static _trim(str?: string | null | undefined, delimiter?: string | boolean | string[] | null | undefined, reserveReturnValue?: boolean | undefined): string | null | undefined;
/**
* @typedef {{
* lang: string,
* script: string|undefined,
* countryCode: string|undefined
* }} LocaleInfo
*/
/**
* @param {string|null} [strLocale]
* @returns {undefined|LocaleInfo}
*/
static _parseLocale(strLocale?: string | null | undefined): {
lang: string;
script: string | undefined;
countryCode: string | undefined;
} | undefined;
/**
* @param {string} locale
*/
constructor(locale: string);
_locale: string;
_isRtlLang(): boolean;
get textInfo(): {
direction: string;
};
}
namespace Locale {
let _RTL_SCRIPTS: string[];
let _BIDI_RTL_LANGS: string[];
}
}
declare module "index" {
export { default } from "./lib/Locale.js";
}
//# sourceMappingURL=index.d.ts.map

@@ -13,2 +13,5 @@ /**

/**
* @param {string} locale
*/
constructor (locale) {

@@ -25,2 +28,7 @@ if (typeof locale !== 'string') {

// Private functions - star
/**
* @param {null|undefined|string} [str]
* @returns {null|undefined|string}
*/
static _escapeRegExpPattern (str) {

@@ -33,2 +41,6 @@ if (typeof str !== 'string') {

/**
* @param {string|null} [str]
* @param {boolean} [reserveReturnValue]
*/
static _toLowerCase (str, reserveReturnValue) {

@@ -41,2 +53,6 @@ if (typeof str !== 'string') {

/**
* @param {string|null} [str]
* @param {boolean} [reserveReturnValue]
*/
static _toUpperCase (str, reserveReturnValue) {

@@ -49,5 +65,15 @@ if (typeof str !== 'string') {

/**
* @param {string|null} [str]
* @param {string|null|string[]|boolean} [delimiter]
* @param {boolean} [reserveReturnValue]
*/
static _trim (str, delimiter, reserveReturnValue) {
/** @type {string[]} */
const patterns = [];
let regexp;
/**
* @param {string|null|undefined} pattern
*/
const addPatterns = function (pattern) {

@@ -65,3 +91,3 @@ // Build trim RegExp pattern and push it to patterns array

if (typeof str !== 'string') {
return reserveReturnValue && str;
return reserveReturnValue ? str : undefined;
}

@@ -108,5 +134,20 @@

/**
* @typedef {{
* lang: string,
* script: string|undefined,
* countryCode: string|undefined
* }} LocaleInfo
*/
/**
* @param {string|null} [strLocale]
* @returns {undefined|LocaleInfo}
*/
static _parseLocale (strLocale) {
var matches = _regexParseLocale.exec(strLocale); // exec regex
let parsedLocale;
if (typeof strLocale !== 'string') {
return undefined;
}
const matches = _regexParseLocale.exec(strLocale); // exec regex
let lang;

@@ -117,17 +158,17 @@ let script;

if (!strLocale || !matches) {
return;
return undefined;
}
// fix script string by trimming '-' and '_'
matches[2] = this._trim(matches[2], ['-', '_']);
const matches2 = this._trim(matches[2], ['-', '_']);
// fix countryCode string by trimming '-' and '_'
matches[3] = this._trim(matches[3], ['-', '_']);
const matches3 = this._trim(matches[3], ['-', '_']);
lang = this._toLowerCase(matches[1]);
script = this._toLowerCase(matches[2]) || script;
countryCode = this._toUpperCase(matches[3]) || countryCode;
lang = /** @type {string} */ (this._toLowerCase(matches[1]));
script = this._toLowerCase(matches2) || script;
countryCode = this._toUpperCase(matches3) || countryCode;
// object with lang, script properties
parsedLocale = {
const parsedLocale = {
lang,

@@ -144,10 +185,12 @@ script,

_isRtlLang () {
const { lang, script } = this.constructor._parseLocale(this._locale);
const { lang, script } = /** @type {LocaleInfo} */ (
Locale._parseLocale(this._locale)
);
if (script) {
return this.constructor._RTL_SCRIPTS.indexOf(script) >= 0;
return Locale._RTL_SCRIPTS.indexOf(script) >= 0;
}
// return true if the intel string lang exists in the BID RTL LANGS array else return false
return (this.constructor._BIDI_RTL_LANGS.indexOf(lang) >= 0);
return (Locale._BIDI_RTL_LANGS.indexOf(lang) >= 0);
}

@@ -154,0 +197,0 @@

import Locale from './Locale.js';
if (typeof Intl === 'undefined') {
// @ts-expect-error Not a complete polyfill
globalThis.Intl = {};

@@ -5,0 +6,0 @@ }

31

package.json
{
"name": "intl-locale-textinfo-polyfill",
"version": "2.0.1",
"version": "2.0.2",
"description": "Library will help you to detect if the locale is right-to-left language.",
"main": "./index.js",
"type": "module",
"types": "./index.d.ts",
"scripts": {
"tsc-prod": "tsc -p tsconfig-prod.json",
"tsc": "tsc",
"open": "open http://localhost:8087/test",
"start": "static -p 8087",
"lint": "eslint .",
"pretest": "npm run lint",
"mocha": "mocha --require test/node-bootstrap.js test/**/*.js test/*.js",
"c8": "c8 npm run mocha",
"test": "npm run c8"
},
"repository": {

@@ -35,19 +45,12 @@ "type": "git",

"license": "BSD-3-Clause",
"dependencies": {},
"devDependencies": {
"@brettz9/node-static": "^0.1.1",
"@types/chai": "^4.3.9",
"@types/mocha": "^10.0.3",
"c8": "^7.12.0",
"chai": "^4.3.7",
"eslint": "^7.26.0",
"mocha": "^10.1.0"
},
"scripts": {
"open": "open http://localhost:8087/test",
"start": "static -p 8087",
"lint": "eslint .",
"pretest": "npm run lint",
"mocha": "mocha --require test/node-bootstrap.js --require chai/register-expect.js test/**/*.js test/*.js",
"c8": "c8 npm run mocha",
"test": "npm run c8"
"mocha": "^10.1.0",
"typescript": "^5.2.2"
}
}
}
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