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

@markuplint/i18n

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@markuplint/i18n - npm Package Compare versions

Comparing version 4.0.0-alpha.3 to 4.0.0-alpha.4

7

$schema.json

@@ -78,8 +78,8 @@ {

"element": { "type": "string" },
"empty string": { "type": "string" },
"empty": { "type": "string" },
"empty string": { "type": "string" },
"end tag": { "type": "string" },
"escape in character reference": { "type": "string" },
"extension": { "type": "string" },
"feature-identifier": { "type": "string" },
"escape in character reference": { "type": "string" },
"floating-point number": { "type": "string" },

@@ -148,5 +148,6 @@ "format": { "type": "string" },

"top level": { "type": "string" },
"transparent model": { "type": "string" },
"type": { "type": "string" },
"transparent model": { "type": "string" },
"unit": { "type": "string" },
"unknown": { "type": "string" },
"uppercase": { "type": "string" },

@@ -153,0 +154,0 @@ "url who schema is an http(s) schema": { "type": "string" },

@@ -22,3 +22,3 @@ "use strict";

}
const noTranslateIndex = Array.from(messageTmpl.matchAll(/(?<=\{)[0-9]+(?=\*\})/g)).map(m => m[0]);
const noTranslateIndex = new Set([...messageTmpl.matchAll(/(?<={)\d+(?=\*})/g)].map(m => m[0]));
const key = removeNoTranslateMark(messageTmpl).toLowerCase();

@@ -29,10 +29,10 @@ const sentence = localeSet?.sentences?.[key];

removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
message = messageTmpl.replace(/\{([0-9]+)(?::([c]))?\}/g, ($0, number, flag) => {
const num = parseInt(number);
if (isNaN(num)) {
message = messageTmpl.replaceAll(/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
const num = Number.parseInt(number);
if (Number.isNaN(num)) {
return $0;
}
const keyword = keywords[num] != null ? toString(keywords[num], localeSet?.locale) : '';
const keyword = keywords[num] == null ? '' : toString(keywords[num], localeSet?.locale);
// No translate
if (noTranslateIndex.includes(number)) {
if (noTranslateIndex.has(number)) {
return keyword;

@@ -58,3 +58,3 @@ }

const value = keys[i];
const cFlag = /^c:/.test(typeof value === 'string' ? value : '') ? ':c' : '';
const cFlag = (typeof value === 'string' ? value : '').startsWith('c:') ? ':c' : '';
return `${place}{${i++}${cFlag}}`;

@@ -70,6 +70,6 @@ })

if (/^%[^%]+%$/.test(keyword)) {
return keyword.replace(/^%|%$/g, '');
return keyword.replaceAll(/^%|%$/g, '');
}
// "%" prefix and suffix escaped
keyword = keyword.replace(/^%%|%%$/g, '%');
keyword = keyword.replaceAll(/^%%|%%$/g, '%');
const key = flag ? `${flag}:${keyword}` : keyword;

@@ -85,8 +85,11 @@ const replacedWord =

switch (typeof value) {
case 'string':
case 'string': {
return value;
case 'number':
}
case 'number': {
return toLocaleString(value, locale);
case 'boolean':
}
case 'boolean': {
return `${value}`;
}
}

@@ -98,8 +101,8 @@ }

}
catch (e) {
if (e instanceof RangeError) {
catch (error) {
if (error instanceof RangeError) {
try {
return value.toLocaleString('en');
}
catch (_) {
catch {
// void

@@ -112,3 +115,3 @@ }

function removeNoTranslateMark(message) {
return message.replace(/(?<=\{[0-9]+)\*(?=\})/g, '');
return message.replaceAll(/(?<={\d+)\*(?=})/g, '');
}

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

export { translator } from './translator.js';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.translator = void 0;
var translator_js_1 = require("./translator.js");
Object.defineProperty(exports, "translator", { enumerable: true, get: function () { return translator_js_1.translator; } });

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.taggedTemplateTranslator = exports.translator = void 0;
const defaultListFormat = {

@@ -6,3 +9,3 @@ quoteStart: '"',

};
export function translator(localeSet) {
function translator(localeSet) {
return (messageTmpl, ...keywords) => {

@@ -20,3 +23,3 @@ let message = messageTmpl;

}
const noTranslateIndex = Array.from(messageTmpl.matchAll(/(?<=\{)[0-9]+(?=\*\})/g)).map(m => m[0]);
const noTranslateIndex = new Set([...messageTmpl.matchAll(/(?<={)\d+(?=\*})/g)].map(m => m[0]));
const key = removeNoTranslateMark(messageTmpl).toLowerCase();

@@ -27,10 +30,10 @@ const sentence = localeSet?.sentences?.[key];

removeNoTranslateMark(input.toLowerCase()) === messageTmpl ? removeNoTranslateMark(input) : messageTmpl;
message = messageTmpl.replace(/\{([0-9]+)(?::([c]))?\}/g, ($0, number, flag) => {
const num = parseInt(number);
if (isNaN(num)) {
message = messageTmpl.replaceAll(/{(\d+)(?::(c))?}/g, ($0, number, flag) => {
const num = Number.parseInt(number);
if (Number.isNaN(num)) {
return $0;
}
const keyword = keywords[num] != null ? toString(keywords[num], localeSet?.locale) : '';
const keyword = keywords[num] == null ? '' : toString(keywords[num], localeSet?.locale);
// No translate
if (noTranslateIndex.includes(number)) {
if (noTranslateIndex.has(number)) {
return keyword;

@@ -43,6 +46,7 @@ }

}
exports.translator = translator;
/**
* @experimental
*/
export function taggedTemplateTranslator(localeSet) {
function taggedTemplateTranslator(localeSet) {
const t = translator(localeSet);

@@ -56,3 +60,3 @@ return (strings, ...keys) => {

const value = keys[i];
const cFlag = /^c:/.test(typeof value === 'string' ? value : '') ? ':c' : '';
const cFlag = (typeof value === 'string' ? value : '').startsWith('c:') ? ':c' : '';
return `${place}{${i++}${cFlag}}`;

@@ -64,9 +68,10 @@ })

}
exports.taggedTemplateTranslator = taggedTemplateTranslator;
function translateKeyword(keyword, flag, localeSet) {
// No translate
if (/^%[^%]+%$/.test(keyword)) {
return keyword.replace(/^%|%$/g, '');
return keyword.replaceAll(/^%|%$/g, '');
}
// "%" prefix and suffix escaped
keyword = keyword.replace(/^%%|%%$/g, '%');
keyword = keyword.replaceAll(/^%%|%%$/g, '%');
const key = flag ? `${flag}:${keyword}` : keyword;

@@ -82,8 +87,11 @@ const replacedWord =

switch (typeof value) {
case 'string':
case 'string': {
return value;
case 'number':
}
case 'number': {
return toLocaleString(value, locale);
case 'boolean':
}
case 'boolean': {
return `${value}`;
}
}

@@ -95,8 +103,8 @@ }

}
catch (e) {
if (e instanceof RangeError) {
catch (error) {
if (error instanceof RangeError) {
try {
return value.toLocaleString('en');
}
catch (_) {
catch {
// void

@@ -109,3 +117,3 @@ }

function removeNoTranslateMark(message) {
return message.replace(/(?<=\{[0-9]+)\*(?=\})/g, '');
return message.replaceAll(/(?<={\d+)\*(?=})/g, '');
}

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

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

@@ -135,5 +135,6 @@ {

"top level": "トップレベル",
"transparent model": "トランスペアレントモデル",
"type": "型",
"transparent model": "トランスペアレントモデル",
"unit": "単位",
"unknown": "不明",
"uppercase": "大文字",

@@ -140,0 +141,0 @@ "url who schema is an http(s) schema": "HTTP(S)スキーマのURL",

{
"name": "@markuplint/i18n",
"version": "4.0.0-alpha.3",
"version": "4.0.0-alpha.4",
"description": "Internationalization for markuplint",

@@ -9,7 +9,14 @@ "repository": "git@github.com:markuplint/markuplint.git",

"private": false,
"type": "module",
"main": "./lib/cjs/index.js",
"types": "./lib/cjs/index.d.ts",
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/cjs/index.js"
"import": {
"default": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"require": {
"default": "./lib/cjs/index.js",
"types": "./lib/cjs/index.d.ts"
}
},

@@ -25,3 +32,2 @@ "./locales/en.json": {

},
"types": "./lib/index.d.ts",
"publishConfig": {

@@ -37,3 +43,3 @@ "access": "public"

},
"gitHead": "380836f7adc1ff7e8eaf9d869e68d29eee8f3b7e"
"gitHead": "991b3aef77fde42c79343ee8c807257a35c589d7"
}
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