Skip to content

Commit

Permalink
Add type definitions for punycode.js
Browse files Browse the repository at this point in the history
Since January 19th ([1]), the `punycode` package has also been published
under `punycode.js`. This solves the problem of needing to use
`punycode/` to use the package (as `punycode` is a built-in Node
package). However, types are missing for `punycode.js`. So this commit
adds them. Note that the interface for the package hasn't changed since
v2.1, so I didn't bump the version, just copied the existing type
definitions from `punycode`.

[1]: mathiasbynens/punycode.js#122
  • Loading branch information
mcmire committed Apr 17, 2023
1 parent d3bb77f commit c290075
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
16 changes: 16 additions & 0 deletions types/punycode.js/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Type definitions for punycode.js 2.1
// Project: https://mths.be/punycode
// Definitions by: Dmitry Guketlev <https://github.com/yavanosta>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export function decode(input: string): string;
export function encode(input: string): string;
export function toUnicode(input: string): string;
export function toASCII(input: string): string;

export namespace ucs2 {
function decode(string: string): number[];
function encode(array: ReadonlyArray<number>): string;
}

export const version: string;
11 changes: 11 additions & 0 deletions types/punycode.js/punycode.js-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import punycode = require('punycode.js');

const result1: string = punycode.decode('x');
const result2: string = punycode.encode('x');
const result3: string = punycode.toASCII('x');
const result4: string = punycode.toUnicode('x');

const ucs2result1: number[] = punycode.ucs2.decode('x');
const ucs2result2: string = punycode.ucs2.encode([1, 2, 3]);

const version: string = punycode.version;
23 changes: 23 additions & 0 deletions types/punycode.js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"punycode.js-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/punycode.js/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "@definitelytyped/dtslint/dt.json" }

0 comments on commit c290075

Please sign in to comment.