From 99643348146546e9ba8c148b70baafbf6d4209b3 Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter Date: Sat, 16 Nov 2019 15:38:07 +0100 Subject: [PATCH 1/7] Add typings --- index.d.ts | 17 +++++++++++++++++ package.json | 16 +++++++++++++--- tsconfig.json | 11 +++++++++++ tslint.json | 7 +++++++ 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 index.d.ts create mode 100644 tsconfig.json create mode 100644 tslint.json diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..7818012 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,17 @@ +import {Node, Parent} from 'unist' +import {Test} from 'unist-util-is/index' + +export = findAllAfter +/** + * Unist utility to get all children of a parent after a node or index + * + * @param parent Parent to search in + * @param Index or Node to start from + * @param test that Nodes must pass to be included + * @returns Array of found Nodes + */ +declare function findAllAfter( + parent: Parent, + index: number | Node, + test: Test | Array> +): Node[] diff --git a/package.json b/package.json index c728996..53d4828 100644 --- a/package.json +++ b/package.json @@ -19,13 +19,21 @@ }, "author": "Titus Wormer (https://wooorm.com)", "contributors": [ - "Titus Wormer (https://wooorm.com)" + "Titus Wormer (https://wooorm.com)", + "Lucas Brandstaetter (https://github.com/Roang-zero1)" ], + "files": [ + "index.js", + "index.d.ts" + ], + "types": "index.d.ts", "dependencies": { "unist-util-is": "^4.0.0" }, "devDependencies": { + "@types/tape": "^4.2.33", "browserify": "^16.0.0", + "dtslint": "^2.0.2", "nyc": "^14.0.0", "prettier": "^1.0.0", "remark": "^11.0.0", @@ -33,16 +41,18 @@ "remark-preset-wooorm": "^6.0.0", "tape": "^4.0.0", "tinyify": "^2.0.0", + "typescript": "^3.7.2", "xo": "^0.25.0" }, "scripts": { - "format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", + "format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix", "build-bundle": "browserify . -s unistUtilFindAllAfter -o unist-util-find-all-after.js", "build-mangle": "browserify . -s unistUtilFindAllAfter -p tinyify -o unist-util-find-all-after.min.js", "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run build && npm run test-coverage" + "test-types": "dtslint .", + "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" }, "nyc": { "check-coverage": true, diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e10590b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "strict": true, + "skipLibCheck": true, + "baseUrl": ".", + "paths": { + "unist-util-find-all-after": ["index.d.ts"] + } + } +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..70c4494 --- /dev/null +++ b/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false, + "whitespace": false + } +} From 665bdd2a78de6b21db9a509cbc777db8c8417f62 Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter Date: Sat, 16 Nov 2019 16:35:05 +0100 Subject: [PATCH 2/7] Fix test is optional --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 7818012..d447643 100644 --- a/index.d.ts +++ b/index.d.ts @@ -13,5 +13,5 @@ export = findAllAfter declare function findAllAfter( parent: Parent, index: number | Node, - test: Test | Array> + test?: Test | Array> ): Node[] From b523a42c3328f9077ea544895461573acc704fe7 Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter Date: Sat, 16 Nov 2019 16:35:11 +0100 Subject: [PATCH 3/7] Add type tests --- unist-util-find-all-after-test.ts | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 unist-util-find-all-after-test.ts diff --git a/unist-util-find-all-after-test.ts b/unist-util-find-all-after-test.ts new file mode 100644 index 0000000..058b4d5 --- /dev/null +++ b/unist-util-find-all-after-test.ts @@ -0,0 +1,37 @@ +import {Node, Parent} from 'unist' +import findAllAfter = require('unist-util-find-all-after') + +const heading: Node = { + type: 'heading', + depth: 2, + children: [] +} + +const parent: Parent = { + type: 'root', + children: [heading] +} + +/*=== missing params ===*/ +// $ExpectError +findAllAfter() +// $ExpectError +findAllAfter(parent) + +/*=== find by index/node ===*/ +findAllAfter(parent, 1) +findAllAfter(parent, heading) +// $ExpectError +findAllAfter(parent, false) + +/*=== find with test ===*/ +// $ExpectError +findAllAfter(parent, 1, false) +findAllAfter(parent, 1, 'paragraph') + +/*=== invalid return ===*/ +// $ExpectError +const returnIsString: string = findAllAfter(parent, 1) + +/*=== valid return ===*/ +const nodes: Node[] = findAllAfter(parent, 1) From 240ea86fc1e23a61161654748a3faccc6c4d0668 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 26 Nov 2019 21:03:24 +0100 Subject: [PATCH 4/7] Update index.d.ts Co-Authored-By: Christian Murphy --- index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.d.ts b/index.d.ts index d447643..a30bea8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,5 @@ +// TypeScript Version: 3.5 + import {Node, Parent} from 'unist' import {Test} from 'unist-util-is/index' From e981532c73c0391324951c1ef9664aba3fee9b28 Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 26 Nov 2019 21:04:07 +0100 Subject: [PATCH 5/7] Update index.d.ts Co-Authored-By: Christian Murphy --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index a30bea8..a18e1af 100644 --- a/index.d.ts +++ b/index.d.ts @@ -8,7 +8,7 @@ export = findAllAfter * Unist utility to get all children of a parent after a node or index * * @param parent Parent to search in - * @param Index or Node to start from + * @param index or Node to start from * @param test that Nodes must pass to be included * @returns Array of found Nodes */ From e2cca839ce8cbb2cfab309f4aa7dc79b87dac4be Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 6 Dec 2019 22:04:16 +0100 Subject: [PATCH 6/7] Update tsconfig.json Co-Authored-By: Christian Murphy --- tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index e10590b..6fd80d5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,6 @@ "compilerOptions": { "lib": ["es2015"], "strict": true, - "skipLibCheck": true, "baseUrl": ".", "paths": { "unist-util-find-all-after": ["index.d.ts"] From 0a40a43d8088afd014520ace1ca1e3d128f891ec Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter Date: Fri, 6 Dec 2019 23:07:00 +0100 Subject: [PATCH 7/7] Update index.d.ts Remote unnecessary sub-import. --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index a18e1af..019bb40 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,7 +1,7 @@ // TypeScript Version: 3.5 import {Node, Parent} from 'unist' -import {Test} from 'unist-util-is/index' +import {Test} from 'unist-util-is' export = findAllAfter /**