micromark-util-decode-numeric-character-reference
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes | ||
* Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes | ||
* non-characters and control characters safe. | ||
@@ -16,5 +16,2 @@ * | ||
*/ | ||
export function decodeNumericCharacterReference( | ||
value: string, | ||
base: number | ||
): string | ||
export function decodeNumericCharacterReference(value: string, base: number): string; |
@@ -7,3 +7,3 @@ import {codes, values} from 'micromark-util-symbol' | ||
* | ||
* Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes | ||
* Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes | ||
* non-characters and control characters safe. | ||
@@ -42,3 +42,3 @@ * | ||
return String.fromCharCode(code) | ||
return String.fromCodePoint(code) | ||
} |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes | ||
* Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes | ||
* non-characters and control characters safe. | ||
@@ -16,5 +16,2 @@ * | ||
*/ | ||
export function decodeNumericCharacterReference( | ||
value: string, | ||
base: number | ||
): string | ||
export function decodeNumericCharacterReference(value: string, base: number): string; |
36
index.js
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes | ||
* Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes | ||
* non-characters and control characters safe. | ||
@@ -17,22 +17,18 @@ * | ||
export function decodeNumericCharacterReference(value, base) { | ||
const code = Number.parseInt(value, base) | ||
const code = Number.parseInt(value, base); | ||
if ( | ||
// C0 except for HT, LF, FF, CR, space. | ||
code < 9 || | ||
code === 11 || | ||
(code > 13 && code < 32) || | ||
// Control character (DEL) of C0, and C1 controls. | ||
(code > 126 && code < 160) || | ||
// Lone high surrogates and low surrogates. | ||
(code > 55_295 && code < 57_344) || | ||
// Noncharacters. | ||
(code > 64_975 && code < 65_008) /* eslint-disable no-bitwise */ || | ||
(code & 65_535) === 65_535 || | ||
(code & 65_535) === 65_534 /* eslint-enable no-bitwise */ || | ||
// Out of range | ||
code > 1_114_111 | ||
) { | ||
return '\uFFFD' | ||
// C0 except for HT, LF, FF, CR, space. | ||
code < 9 || code === 11 || code > 13 && code < 32 || | ||
// Control character (DEL) of C0, and C1 controls. | ||
code > 126 && code < 160 || | ||
// Lone high surrogates and low surrogates. | ||
code > 55_295 && code < 57_344 || | ||
// Noncharacters. | ||
code > 64_975 && code < 65_008 || /* eslint-disable no-bitwise */ | ||
(code & 65_535) === 65_535 || (code & 65_535) === 65_534 || /* eslint-enable no-bitwise */ | ||
// Out of range | ||
code > 1_114_111) { | ||
return "\uFFFD"; | ||
} | ||
return String.fromCharCode(code) | ||
} | ||
return String.fromCodePoint(code); | ||
} |
{ | ||
"name": "micromark-util-decode-numeric-character-reference", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "micromark utility to decode numeric character references", | ||
@@ -49,3 +49,11 @@ "license": "MIT", | ||
}, | ||
"xo": false | ||
"xo": { | ||
"envs": [ | ||
"shared-node-browser" | ||
], | ||
"prettier": true, | ||
"rules": { | ||
"unicorn/prefer-code-point": "off" | ||
} | ||
} | ||
} |
@@ -81,3 +81,3 @@ # micromark-util-decode-numeric-character-reference | ||
Sort of like `String.fromCharCode(Number.parseInt(value, base))`, but makes | ||
Sort of like `String.fromCodePoint(Number.parseInt(value, base))`, but makes | ||
non-characters and control characters safe. | ||
@@ -84,0 +84,0 @@ |
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
9940
100
0