idna-uts46-hx
Advanced tools
Comparing version 6.0.0 to 6.0.1
@@ -0,1 +1,8 @@ | ||
## [6.0.1](https://github.com/centralnicgroup-opensource/rtldev-middleware-idna-uts46/compare/v6.0.0...v6.0.1) (2024-2-23) | ||
### Bug Fixes | ||
* **build:** add missing type definitions ([4a152c8](https://github.com/centralnicgroup-opensource/rtldev-middleware-idna-uts46/commit/4a152c8984f130a252a4cb295d5b07fde874b7a7)) | ||
# [6.0.0](https://github.com/centralnicgroup-opensource/rtldev-middleware-idna-uts46/compare/v5.1.2...v6.0.0) (2024-2-22) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "idna-uts46-hx", | ||
"description": "Convert Domain Names correctly from IDN to Punycode and vice-versa and offer TR46 processing.", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"private": false, | ||
"type": "module", | ||
"main": "dist/index.mjs", | ||
"typings": "dist/index.d.ts", | ||
"license": "MIT", | ||
@@ -9,0 +10,0 @@ "sideEffects": false, |
import tr46 from 'tr46'; | ||
function getDefaultOptions(domain) { | ||
function getDefaultOptions(domainName) { | ||
return { | ||
transitionalProcessing: !domain.match( | ||
transitionalProcessing: !domainName.match( | ||
/\.(?:be|ca|de|swiss|fr|pm|re|tf|wf|yt)\.?$/, | ||
@@ -11,31 +11,37 @@ ), | ||
function toAscii(domain, opts = {}) { | ||
const pc = tr46.toASCII(domain, { ...getDefaultOptions(domain), ...opts }); | ||
function toAscii(domainName, options = {}) { | ||
const pc = tr46.toASCII(domainName, { | ||
...getDefaultOptions(domainName), | ||
...options, | ||
}); | ||
if (pc !== null) { | ||
return pc; | ||
} | ||
throw new Error(`Unable to translate ${domain} to ASCII.`); | ||
throw new Error(`Unable to translate ${domainName} to ASCII.`); | ||
} | ||
function toUnicode(domain, opts = {}) { | ||
const idn = tr46.toUnicode(domain, { ...getDefaultOptions(domain), ...opts }); | ||
function toUnicode(domainName, options = {}) { | ||
const idn = tr46.toUnicode(domainName, { | ||
...getDefaultOptions(domainName), | ||
...options, | ||
}); | ||
if (idn !== null && !idn.error) { | ||
return idn.domain; | ||
} | ||
throw new Error(`Unable to translate ${domain} to Unicode.`); | ||
throw new Error(`Unable to translate ${domainName} to Unicode.`); | ||
} | ||
function convert(domains) { | ||
const isArrayInput = Array.isArray(domains); | ||
function convert(domainNames, options = {}) { | ||
const isArrayInput = Array.isArray(domainNames); | ||
if (!isArrayInput) { | ||
domains = [domains]; | ||
domainNames = [domainNames]; | ||
} | ||
const results = { IDN: [], PC: [] }; | ||
domains.forEach((domain) => { | ||
domainNames.forEach((domainName) => { | ||
try { | ||
results.PC.push(toAscii(domain)); | ||
results.IDN.push(toUnicode(domain)); | ||
results.PC.push(toAscii(domainName, options)); | ||
results.IDN.push(toUnicode(domainName, options)); | ||
} catch (e) { | ||
results.PC.push(domain); | ||
results.IDN.push(domain); | ||
results.PC.push(domainName); | ||
results.IDN.push(domainName); | ||
} | ||
@@ -42,0 +48,0 @@ }); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
720835
25
3309