1
- /**
2
- * Note: We use 'npm-punycode' alias instead of 'punycode/' to properly support dual packages in ESM.
3
- * This ensures that this third-party module is used instead of the built-in
4
- * Node.js 'punycode' module, which has been deprecated since Node.js v7.0.0.
5
- * @see https://github.com/mathiasbynens/punycode.js#installation
6
- * @see https://nodejs.org/api/punycode.html for deprecation info
7
- */
8
- import punycode from 'npm-punycode'
9
-
1
+ import { decode , encode } from './punycode'
10
2
import {
11
3
extractPathKey ,
12
4
getDynamicPaths ,
@@ -364,7 +356,7 @@ export default class NURL implements URL {
364
356
. map ( ( segment ) => {
365
357
for ( const char of segment ) {
366
358
if ( isASCIICodeChar ( char ) ) {
367
- return `${ this . punycodePrefix } ${ punycode . encode ( segment ) } `
359
+ return `${ this . punycodePrefix } ${ encode ( segment ) } `
368
360
}
369
361
}
370
362
return segment
@@ -376,7 +368,7 @@ export default class NURL implements URL {
376
368
let href = this . _href
377
369
378
370
this . _hostname . split ( '.' ) . forEach ( ( segment ) => {
379
- href = href . replace ( segment , punycode . decode ( segment . replace ( this . punycodePrefix , '' ) ) )
371
+ href = href . replace ( segment , decode ( segment . replace ( this . punycodePrefix , '' ) ) )
380
372
} )
381
373
382
374
return href
@@ -385,7 +377,7 @@ export default class NURL implements URL {
385
377
get decodedHostname ( ) : string {
386
378
return this . _hostname
387
379
. split ( '.' )
388
- . map ( ( segment ) => punycode . decode ( segment . replace ( this . punycodePrefix , '' ) ) )
380
+ . map ( ( segment ) => decode ( segment . replace ( this . punycodePrefix , '' ) ) )
389
381
. join ( '.' )
390
382
}
391
383
}
0 commit comments