Skip to content

Commit

Permalink
Merge pull request #173 from andersk/remove-punycode
Browse files Browse the repository at this point in the history
Replace punycode dependency with string iteration
  • Loading branch information
nfroidure authored Nov 7, 2024
2 parents 6fcbc1e + 78595b4 commit 9bb1cff
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"commander": "^12.1.0",
"debug": "^4.3.6",
"glob": "^11.0.0",
"punycode": "^2.3.1",
"sax": "^1.4.1",
"svg-pathdata": "^7.0.0",
"transformation-matrix-js": "^2.7.6",
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import punycode from 'punycode/punycode.js';
import { Transform } from 'stream';
import Sax from 'sax';
import { SVGPathData } from 'svg-pathdata';
Expand Down Expand Up @@ -562,9 +561,11 @@ export class SVGIcons2SVGFontStream extends Transform {
delete glyph.paths;
const d = glyphPath.round(this._options.round).encode();
glyph.unicode.forEach((unicode, i) => {
const unicodeStr = punycode.ucs2
.decode(unicode)
.map((point) => '&#x' + point.toString(16).toUpperCase() + ';')
const unicodeStr = [...unicode]
.map(
(char) =>
'&#x' + char.codePointAt(0)!.toString(16).toUpperCase() + ';',
)
.join('');

this.push(
Expand Down
3 changes: 1 addition & 2 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Readable } from 'node:stream';
import fs from 'node:fs';
import { mkdir } from 'node:fs/promises';
import { join } from 'node:path';
import punycode from 'punycode/punycode.js';

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

svgIconStream.metadata = {
name: 'account',
unicode: [punycode.ucs2.encode([0x1f63a])],
unicode: ['\u{1f63a}'],
};

const promise = bufferStream(svgFontStream);
Expand Down

0 comments on commit 9bb1cff

Please sign in to comment.