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

@aboutbits/internationalization

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aboutbits/internationalization - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

35

dist/index.js

@@ -27,7 +27,8 @@ "use strict";

// If the DOM isn't accessible the website may be rendered on a server
if (utilities_1.canUseDOM()) {
if ((0, utilities_1.canUseDOM)()) {
// Get browser language
var browserLanguage_1 = (navigator.languages && navigator.languages[0]) || navigator.language;
return (this.supportedLanguages.find(function (lang) { return lang === browserLanguage_1; }) ||
this.fallbackLanguage);
return (this.supportedLanguages.find(function (lang) {
return (0, utilities_1.isEqualCaseInsensitive)(lang, browserLanguage_1);
}) || this.fallbackLanguage);
}

@@ -45,6 +46,7 @@ // Return fallback language if no DOM was found

Internationalization.prototype.setLanguage = function (language) {
if (utilities_1.canUseDOM()) {
var cookieLanguage = this.supportedLanguages.find(function (lang) { return lang === language; }) ||
this.fallbackLanguage;
utilities_1.setCookie(this.cookieName, cookieLanguage);
if ((0, utilities_1.canUseDOM)()) {
var cookieLanguage = this.supportedLanguages.find(function (lang) {
return (0, utilities_1.isEqualCaseInsensitive)(lang, language);
}) || this.fallbackLanguage;
(0, utilities_1.setCookie)(this.cookieName, cookieLanguage);
}

@@ -67,3 +69,3 @@ };

// Try to get language form cookie
var cookieFromRequest = utilities_1.getCookieFromRequest(this.cookieName, request);
var cookieFromRequest = (0, utilities_1.getCookieFromRequest)(this.cookieName, request);
if (cookieFromRequest) {

@@ -86,14 +88,14 @@ return cookieFromRequest;

return locale !== '*' &&
_this.supportedLanguages.some(function (lang) { return locale === lang; });
_this.supportedLanguages.some(function (lang) {
return (0, utilities_1.isEqualCaseInsensitive)(locale, lang);
});
});
// Check if the potential locale is not undefined else return the fallback language
return (potentialLocale
? potentialLocale.locale
: this.fallbackLanguage);
return (potentialLocale ? potentialLocale.locale : this.fallbackLanguage);
}
}
// Check for DOM
if (utilities_1.canUseDOM()) {
if ((0, utilities_1.canUseDOM)()) {
// Try to get language form cookie
var language_1 = utilities_1.getCookieFromDocument(this.cookieName);
var language_1 = (0, utilities_1.getCookieFromDocument)(this.cookieName);
// If cookie is undefined get the language form the browser

@@ -104,4 +106,5 @@ if (language_1 == undefined) {

// Return found language or fallback language
return (this.supportedLanguages.find(function (lang) { return lang === language_1; }) ||
this.fallbackLanguage);
return (this.supportedLanguages.find(function (lang) {
return (0, utilities_1.isEqualCaseInsensitive)(lang, language_1);
}) || this.fallbackLanguage);
}

@@ -108,0 +111,0 @@ return this.fallbackLanguage;

@@ -29,2 +29,3 @@ /// <reference types="node" />

declare function canUseDOM(): boolean;
export { getCookieFromDocument, getCookieFromRequest, setCookie, canUseDOM };
declare function isEqualCaseInsensitive(a: string, b: string): boolean;
export { getCookieFromDocument, getCookieFromRequest, setCookie, canUseDOM, isEqualCaseInsensitive, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.canUseDOM = exports.setCookie = exports.getCookieFromRequest = exports.getCookieFromDocument = void 0;
exports.isEqualCaseInsensitive = exports.canUseDOM = exports.setCookie = exports.getCookieFromRequest = exports.getCookieFromDocument = void 0;
var getCookiePattern = function (name) { return RegExp(name + '=.[^;]*'); };

@@ -53,1 +53,5 @@ /**

exports.canUseDOM = canUseDOM;
function isEqualCaseInsensitive(a, b) {
return a.toLowerCase() === b.toLowerCase();
}
exports.isEqualCaseInsensitive = isEqualCaseInsensitive;
{
"name": "@aboutbits/internationalization",
"version": "0.2.1",
"version": "0.3.0",
"description": "Internationalization",

@@ -16,2 +16,6 @@ "keywords": [

"typings": "dist/index.d.ts",
"engines": {
"npm": "^8",
"node": "^16"
},
"scripts": {

@@ -21,2 +25,3 @@ "build": "tsc",

"lint:fix": "npm run lint -- --fix",
"typecheck": "tsc --noEmit",
"test": "jest --config jestconfig.json --passWithNoTests",

@@ -44,16 +49,17 @@ "prepare": "npm run build",

"devDependencies": {
"@types/node": "^14.11.5",
"@types/jest": "^26.0.9",
"@typescript-eslint/eslint-plugin": "^3.8.0",
"@typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jest": "^23.20.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.2.2",
"prettier": "^2.0.5",
"ts-jest": "^26.1.4",
"typescript": "^3.9.7"
"@types/jest": "^28.1.3",
"@types/node": "^16.0.0",
"@typescript-eslint/eslint-plugin": "^5.30.0",
"@typescript-eslint/parser": "^5.30.0",
"eslint": "^8.18.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"eslint-plugin-prettier": "^4.1.0",
"jest": "^28.1.2",
"jest-environment-jsdom": "^28.1.2",
"prettier": "^2.7.1",
"ts-jest": "^28.0.5",
"typescript": "^4.7.4"
}
}
Internationalization
====================
[![npm version](https://badge.fury.io/js/%40aboutbits%2Finternationalization.svg)](https://badge.fury.io/js/%40aboutbits%2Finternationalization)
[![npm package](https://badge.fury.io/js/%40aboutbits%2Finternationalization.svg)](https://badge.fury.io/js/%40aboutbits%2Finternationalization)
[![license](https://img.shields.io/github/license/aboutbits/internationalization)](https://github.com/aboutbits/internationalization/blob/master/license.md)

@@ -6,0 +7,0 @@ This package includes utilities for working with different languages in the browser.

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