File tree Expand file tree Collapse file tree 5 files changed +86
-2
lines changed Expand file tree Collapse file tree 5 files changed +86
-2
lines changed Original file line number Diff line number Diff line change
1
+ // TypeScript Version: 3.5
2
+
3
+ import { Node , Parent } from 'unist'
4
+ import { Test } from 'unist-util-is'
5
+
6
+ export = findAllBefore
7
+
8
+ /**
9
+ * Unist utility to get all children of a parent before a node or index
10
+ *
11
+ * @param parent Parent to search in
12
+ * @param index or Node to start from
13
+ * @param test that Nodes must pass to be included
14
+ * @returns Array of found Nodes
15
+ */
16
+ declare function findAllBefore < T extends Node > (
17
+ parent : Parent ,
18
+ index : number | Node ,
19
+ test ?: Test < T > | Array < Test < T > >
20
+ ) : Node [ ]
Original file line number Diff line number Diff line change 22
22
"contributors" : [
23
23
" Titus Wormer <[email protected] > (https://wooorm.com)"
24
24
],
25
+ "files" : [
26
+ " index.js" ,
27
+ " index.d.ts"
28
+ ],
29
+ "types" : " index.d.ts" ,
25
30
"dependencies" : {
26
31
"unist-util-is" : " ^4.0.0"
27
32
},
28
33
"devDependencies" : {
29
34
"browserify" : " ^16.0.0" ,
35
+ "dtslint" : " ^3.6.14" ,
30
36
"nyc" : " ^15.0.0" ,
31
37
"prettier" : " ^2.0.0" ,
32
38
"remark" : " ^12.0.0" ,
43
49
"build" : " npm run build-bundle && npm run build-mangle" ,
44
50
"test-api" : " node test" ,
45
51
"test-coverage" : " nyc --reporter lcov tape test.js" ,
46
- "test" : " npm run format && npm run build && npm run test-coverage"
52
+ "test-types" : " dtslint ." ,
53
+ "test" : " npm run format && npm run build && npm run test-coverage && npm run test-types"
47
54
},
48
55
"nyc" : {
49
56
"check-coverage" : true ,
66
73
"unicorn/prefer-number-properties" : " off"
67
74
},
68
75
"ignore" : [
69
- " unist-util-find-all-before.js"
76
+ " unist-util-find-all-before.js" ,
77
+ " *.ts"
70
78
]
71
79
},
72
80
"remarkConfig" : {
Original file line number Diff line number Diff line change
1
+ {
2
+ "compilerOptions" : {
3
+ "lib" : [" es2015" ],
4
+ "strict" : true ,
5
+ "baseUrl" : " ." ,
6
+ "paths" : {
7
+ "unist-util-find-all-before" : [" index.d.ts" ]
8
+ }
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "extends" : " dtslint/dtslint.json" ,
3
+ "rules" : {
4
+ "semicolon" : false ,
5
+ "whitespace" : false ,
6
+ "strict-export-declare-modifiers" : false
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ import { Node , Parent } from 'unist'
2
+ import findAllBefore = require( 'unist-util-find-all-before' )
3
+
4
+ const heading : Node = {
5
+ type : 'heading' ,
6
+ depth : 2 ,
7
+ children : [ ]
8
+ }
9
+
10
+ const parent : Parent = {
11
+ type : 'root' ,
12
+ children : [ heading ]
13
+ }
14
+
15
+ // Missing params
16
+ // $ExpectError
17
+ findAllBefore ( )
18
+
19
+ // $ExpectError
20
+ findAllBefore ( parent )
21
+
22
+ // Find by index or node
23
+ findAllBefore ( parent , 1 )
24
+ findAllBefore ( parent , heading )
25
+
26
+ // Invalid test type
27
+ // $ExpectError
28
+ findAllBefore ( parent , 1 , false )
29
+
30
+ // Valid test type
31
+ findAllBefore ( parent , 1 , 'paragraph' )
32
+
33
+ // Invalid retrurn type
34
+ // $ExpectError
35
+ const returnsString : string = findAllBefore ( parent , 1 )
36
+
37
+ // Valid return type
38
+ const nodes : Node [ ] = findAllBefore ( parent , 1 )
You can’t perform that action at this time.
0 commit comments