Skip to content

Add types #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// TypeScript Version: 3.5

import {Node, Parent} from 'unist'
import {Test} from 'unist-util-is'

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<T extends Node>(
parent: Parent,
index: number | Node,
test?: Test<T> | Array<Test<T>>
): Node[]
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,40 @@
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Lucas Brandstaetter <lucas@brandstaetter.tech> (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",
"remark-cli": "^7.0.0",
"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,
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"unist-util-find-all-after": ["index.d.ts"]
}
}
}
7 changes: 7 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"whitespace": false
}
}
37 changes: 37 additions & 0 deletions unist-util-find-all-after-test.ts
Original file line number Diff line number Diff line change
@@ -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)