Skip to content

Commit

Permalink
feat: add TypeScript definition (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Mar 27, 2020
1 parent ef3995d commit 27f3f85
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { eslintConfig } = require('./package.json')

eslintConfig.parser = '@typescript-eslint/parser'
eslintConfig.extends.push(
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended'
)

eslintConfig.rules = {
'node/no-unsupported-features/es-syntax': 'off',
'comma-dangle': ['error', 'only-multiline'],
semi: ['error', 'always'],
'space-before-function-paren': ['error', 'never']
}

module.exports = eslintConfig
21 changes: 21 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Based on the type definitions for extract-zip 1.6
// Definitions by: Mizunashi Mana <https://github.com/mizunashi-mana>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/e69b58e/types/extract-zip/index.d.ts

import { Entry, ZipFile } from 'yauzl';

declare namespace extract {
interface Options {
dir: string;
defaultDirMode?: number;
defaultFileMode?: number;
onEntry?: (entry: Entry, zipfile: ZipFile) => void;
}
}

declare function extract(
zipPath: string,
opts: extract.Options,
): Promise<void>;

export = extract;
26 changes: 26 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Entry, ZipFile } from 'yauzl';
import * as extract from '.';

const zip = '/path/to/zip';
const dir = '/path/to/dir';
const defaultFileMode = 0o600;

let options: extract.Options = {
dir,
};
options = {
dir,
defaultDirMode: 0o700,
defaultFileMode,
onEntry: (entry: Entry, zipfile: ZipFile): void => {
console.log(entry);
console.log(zipfile);
}
};

try {
await extract(zip, options);
console.log('done');
} catch (err) {
console.error(err);
}
23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
"version": "1.7.0",
"description": "unzip a zip file into a directory using 100% javascript",
"main": "index.js",
"types": "index.d.ts",
"bin": {
"extract-zip": "cli.js"
},
"scripts": {
"ava": "ava",
"coverage": "nyc ava",
"lint": "eslint .",
"test": "npm run lint && ava"
"lint": "yarn lint:js && yarn lint:ts && yarn tsd",
"lint:js": "eslint .",
"lint:ts": "eslint --config .eslintrc.typescript.js --ext .ts .",
"test": "yarn lint && ava",
"tsd": "tsd"
},
"files": [
"*.js"
"*.js",
"index.d.ts"
],
"author": "max ogden",
"license": "BSD-2-Clause",
Expand All @@ -31,7 +36,12 @@
"get-stream": "^5.1.0",
"yauzl": "^2.10.0"
},
"optionalDependencies": {
"@types/yauzl": "^2.9.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"ava": "^3.5.1",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
Expand All @@ -43,7 +53,9 @@
"fs-extra": "^9.0.0",
"husky": "^4.2.3",
"lint-staged": "^10.0.9",
"nyc": "^15.0.0"
"nyc": "^15.0.0",
"tsd": "^0.11.0",
"typescript": "^3.8.3"
},
"eslintConfig": {
"extends": [
Expand All @@ -62,6 +74,7 @@
}
},
"lint-staged": {
"*.js": "eslint --fix"
"*.js": "yarn lint:js --fix",
"*.ts": "yarn lint:ts --fix"
}
}

0 comments on commit 27f3f85

Please sign in to comment.