|
1 | | -# punycode |
| 1 | +# Punycode Node.js ponyfill |
2 | 2 |
|
3 | | -💔 Deprecated node:punycode module as an npm package |
| 3 | +💔 Deprecated `node:punycode` module as an npm package |
4 | 4 |
|
5 | | -TODO: |
| 5 | +<div align="center"> |
6 | 6 |
|
7 | | -- Improve readme |
8 | | -- Add GitHub Actions |
9 | | -- Add metadata to package.json |
10 | | -- Publish a v1.0.0 when all that's done |
| 7 | + |
| 8 | + |
| 9 | +</div> |
| 10 | + |
| 11 | +🏃♀️ Uses the native `node:punycode` module when using Node.js \ |
| 12 | +📋 Delegates to the [punycode.js v2.0.1] implementation everywhere else \ |
| 13 | +⏳ Still prints the deprecation warning everywhere |
| 14 | + |
| 15 | +🛑 **The `node:punycode` module is deprecated in Node.js core.** Instead, it's |
| 16 | +recommended to use a user-land implementation like [punycode.js]. This package |
| 17 | +is provided solely for parity with `node:` APIs. |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +Install this package using npm, [Yarn], [pnpm], or your other favorite npm |
| 27 | +package manager. Here's a quick copy-paste for npm users: |
| 28 | + |
| 29 | +```sh |
| 30 | +npm install @nodefill/punycode |
| 31 | +``` |
| 32 | + |
| 33 | +This package is also compatible with Deno via their compatibility layer. You can |
| 34 | +import the package directly using [the new `npm:` specifier], or a |
| 35 | +Deno-compatible ESM CDN like [esm.sh] or [jsDelivr]. |
| 36 | + |
| 37 | +```js |
| 38 | +import {} from "npm:@nodefill/punycode"; |
| 39 | +import {} from "https://esm.sh/@nodefill/punycode"; |
| 40 | +``` |
| 41 | + |
| 42 | +If you're using not using a build tool and you just want to use the package in |
| 43 | +your browser, you can use an ESM npm CDN like [esm.sh] or [jsDelivr]. |
| 44 | + |
| 45 | +```js |
| 46 | +import {} from "https://esm.sh/@nodefill/punycode"; |
| 47 | +import {} from "https://esm.run/@nodefill/punycode"; |
| 48 | +``` |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +No matter what environment you import this package in, you'll always be greeted |
| 58 | +with a warning (unless you pass `node --no-warnings`). This package is |
| 59 | +**deprecated** in Node.js core. Instead, it's recommended to use a user-land |
| 60 | +implementation like [punycode.js]. This package is provided solely for parity |
| 61 | +with `node:` APIs. |
| 62 | + |
| 63 | +Here's a quick overview of the API: |
| 64 | + |
| 65 | +```js |
| 66 | +import { toASCII, toUnicode } from "@nodefill/punycode"; |
| 67 | + |
| 68 | +console.log(toASCII("😀")); |
| 69 | +//=> 'xn--e28h' |
| 70 | + |
| 71 | +console.log(toUnicode("xn--wp8h")); |
| 72 | +//=> 👋 |
| 73 | +``` |
| 74 | + |
| 75 | +📚 You can find more docs on the [punycode.js v2.0.1 README] or the [Node.js |
| 76 | +`node:punycode` docs]! |
| 77 | + |
| 78 | +## Development |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +Special thanks to [Mathias Bynens] for the [punycode.js v2.0.1] implementation! |
| 83 | +The code for the non-`node` targets is ripped straight from there (plus a |
| 84 | +warning message and explicit exports). As for types, you can thank TypeStrong |
| 85 | +and the DefinitelyTyped community for the `@types/node` definitions which, |
| 86 | +again, are copy-pasted into the `index-types.d.ts` file. |
| 87 | + |
| 88 | +There's no tests and no TypeScript since this package is simple enough to not |
| 89 | +warrant those extra things. |
| 90 | + |
| 91 | +**This package itself should be deprecated on npm if/when the `node:punycode` |
| 92 | +module is removed from Node.js core.** Until then, don't deprecate it. Why? So |
| 93 | +that it doesn't show a warning when you install it, 😅 and so that it appears in |
| 94 | +npm search results. 😎 |
| 95 | + |
| 96 | +<!-- prettier-ignore-start --> |
| 97 | +[mathias bynens]: https://mathiasbynens.be/ |
| 98 | +[punycode.js v2.0.1]: https://github.com/mathiasbynens/punycode.js/blob/v2.0.1/punycode.js |
| 99 | +[punycode.js v2.0.1 readme]: https://github.com/mathiasbynens/punycode.js/tree/v2.0.1#api |
| 100 | +[node.js `node:punycode` docs]: https://nodejs.org/api/punycode.html |
| 101 | +<!-- prettier-ignore-end --> |
0 commit comments