Skip to content

Commit 27f3f85

Browse files
authored
feat: add TypeScript definition (#92)
1 parent ef3995d commit 27f3f85

File tree

4 files changed

+81
-5
lines changed

4 files changed

+81
-5
lines changed

.eslintrc.typescript.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { eslintConfig } = require('./package.json')
2+
3+
eslintConfig.parser = '@typescript-eslint/parser'
4+
eslintConfig.extends.push(
5+
'plugin:@typescript-eslint/eslint-recommended',
6+
'plugin:@typescript-eslint/recommended'
7+
)
8+
9+
eslintConfig.rules = {
10+
'node/no-unsupported-features/es-syntax': 'off',
11+
'comma-dangle': ['error', 'only-multiline'],
12+
semi: ['error', 'always'],
13+
'space-before-function-paren': ['error', 'never']
14+
}
15+
16+
module.exports = eslintConfig

index.d.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Based on the type definitions for extract-zip 1.6
2+
// Definitions by: Mizunashi Mana <https://github.com/mizunashi-mana>
3+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e69b58e/types/extract-zip/index.d.ts
4+
5+
import { Entry, ZipFile } from 'yauzl';
6+
7+
declare namespace extract {
8+
interface Options {
9+
dir: string;
10+
defaultDirMode?: number;
11+
defaultFileMode?: number;
12+
onEntry?: (entry: Entry, zipfile: ZipFile) => void;
13+
}
14+
}
15+
16+
declare function extract(
17+
zipPath: string,
18+
opts: extract.Options,
19+
): Promise<void>;
20+
21+
export = extract;

index.test-d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Entry, ZipFile } from 'yauzl';
2+
import * as extract from '.';
3+
4+
const zip = '/path/to/zip';
5+
const dir = '/path/to/dir';
6+
const defaultFileMode = 0o600;
7+
8+
let options: extract.Options = {
9+
dir,
10+
};
11+
options = {
12+
dir,
13+
defaultDirMode: 0o700,
14+
defaultFileMode,
15+
onEntry: (entry: Entry, zipfile: ZipFile): void => {
16+
console.log(entry);
17+
console.log(zipfile);
18+
}
19+
};
20+
21+
try {
22+
await extract(zip, options);
23+
console.log('done');
24+
} catch (err) {
25+
console.error(err);
26+
}

package.json

+18-5
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
"version": "1.7.0",
44
"description": "unzip a zip file into a directory using 100% javascript",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"bin": {
78
"extract-zip": "cli.js"
89
},
910
"scripts": {
1011
"ava": "ava",
1112
"coverage": "nyc ava",
12-
"lint": "eslint .",
13-
"test": "npm run lint && ava"
13+
"lint": "yarn lint:js && yarn lint:ts && yarn tsd",
14+
"lint:js": "eslint .",
15+
"lint:ts": "eslint --config .eslintrc.typescript.js --ext .ts .",
16+
"test": "yarn lint && ava",
17+
"tsd": "tsd"
1418
},
1519
"files": [
16-
"*.js"
20+
"*.js",
21+
"index.d.ts"
1722
],
1823
"author": "max ogden",
1924
"license": "BSD-2-Clause",
@@ -31,7 +36,12 @@
3136
"get-stream": "^5.1.0",
3237
"yauzl": "^2.10.0"
3338
},
39+
"optionalDependencies": {
40+
"@types/yauzl": "^2.9.1"
41+
},
3442
"devDependencies": {
43+
"@typescript-eslint/eslint-plugin": "^2.25.0",
44+
"@typescript-eslint/parser": "^2.25.0",
3545
"ava": "^3.5.1",
3646
"eslint": "^6.8.0",
3747
"eslint-config-standard": "^14.1.1",
@@ -43,7 +53,9 @@
4353
"fs-extra": "^9.0.0",
4454
"husky": "^4.2.3",
4555
"lint-staged": "^10.0.9",
46-
"nyc": "^15.0.0"
56+
"nyc": "^15.0.0",
57+
"tsd": "^0.11.0",
58+
"typescript": "^3.8.3"
4759
},
4860
"eslintConfig": {
4961
"extends": [
@@ -62,6 +74,7 @@
6274
}
6375
},
6476
"lint-staged": {
65-
"*.js": "eslint --fix"
77+
"*.js": "yarn lint:js --fix",
78+
"*.ts": "yarn lint:ts --fix"
6679
}
6780
}

0 commit comments

Comments
 (0)