Skip to content

Commit 78595b4

Browse files
committed
Replace punycode dependency with string iteration
The spread operator has been available since Node 5.0.0, and iterates strings over their code points (not code units), as expected here. There’s no need to use the punycode library for this. Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 6fcbc1e commit 78595b4

4 files changed

Lines changed: 7 additions & 8 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"commander": "^12.1.0",
6969
"debug": "^4.3.6",
7070
"glob": "^11.0.0",
71-
"punycode": "^2.3.1",
7271
"sax": "^1.4.1",
7372
"svg-pathdata": "^7.0.0",
7473
"transformation-matrix-js": "^2.7.6",

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import punycode from 'punycode/punycode.js';
21
import { Transform } from 'stream';
32
import Sax from 'sax';
43
import { SVGPathData } from 'svg-pathdata';
@@ -562,9 +561,11 @@ export class SVGIcons2SVGFontStream extends Transform {
562561
delete glyph.paths;
563562
const d = glyphPath.round(this._options.round).encode();
564563
glyph.unicode.forEach((unicode, i) => {
565-
const unicodeStr = punycode.ucs2
566-
.decode(unicode)
567-
.map((point) => '&#x' + point.toString(16).toUpperCase() + ';')
564+
const unicodeStr = [...unicode]
565+
.map(
566+
(char) =>
567+
'&#x' + char.codePointAt(0)!.toString(16).toUpperCase() + ';',
568+
)
568569
.join('');
569570

570571
this.push(

src/tests/index.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Readable } from 'node:stream';
44
import fs from 'node:fs';
55
import { mkdir } from 'node:fs/promises';
66
import { join } from 'node:path';
7-
import punycode from 'punycode/punycode.js';
87

98
import { SVGIcons2SVGFontStream } from '../index.js';
109
import { SVGIconsDirStream, type SVGIconStream } from '../iconsdir.js';
@@ -572,7 +571,7 @@ describe('Passing code points', () => {
572571

573572
svgIconStream.metadata = {
574573
name: 'account',
575-
unicode: [punycode.ucs2.encode([0x1f63a])],
574+
unicode: ['\u{1f63a}'],
576575
};
577576

578577
const promise = bufferStream(svgFontStream);

0 commit comments

Comments
 (0)