File tree 5 files changed +44
-3
lines changed
5 files changed +44
-3
lines changed Original file line number Diff line number Diff line change 1
1
.DS_Store
2
+ * .d.ts
2
3
* .log
3
4
coverage /
4
5
node_modules /
Original file line number Diff line number Diff line change @@ -2,14 +2,24 @@ import location from 'vfile-location'
2
2
3
3
var search = / \r ? \n | \r / g
4
4
5
+ /**
6
+ * @param {import('unist').Node|import('unist').Position } value Value to get
7
+ * @param {import('vfile').VFile|string } file File in which `value` exists
8
+ * @returns {string|null }
9
+ */
5
10
export function source ( value , file ) {
6
11
var doc = String ( file )
7
12
var loc = location ( file )
13
+ /** @type {import('unist').Position } */
14
+ // @ts -ignore Looks like a node.
8
15
var position = ( value && value . position ) || value || { }
9
16
var startOffset = loc . toOffset ( position . start )
10
17
var endOffset = loc . toOffset ( position . end )
18
+ /** @type {Array.<string> } */
11
19
var results = [ ]
20
+ /** @type {RegExpMatchArray } */
12
21
var match
22
+ /** @type {number } */
13
23
var end
14
24
15
25
if ( startOffset === - 1 || endOffset === - 1 ) {
Original file line number Diff line number Diff line change 25
25
"sideEffects" : false ,
26
26
"type" : " module" ,
27
27
"main" : " index.js" ,
28
+ "types" : " index.d.ts" ,
28
29
"files" : [
30
+ " index.d.ts" ,
29
31
" index.js"
30
32
],
31
33
"dependencies" : {
34
+ "@types/unist" : " ^2.0.0" ,
35
+ "vfile" : " ^4.0.0" ,
32
36
"vfile-location" : " ^3.0.0"
33
37
},
34
38
"devDependencies" : {
39
+ "@types/tape" : " ^4.0.0" ,
35
40
"c8" : " ^7.0.0" ,
36
41
"prettier" : " ^2.0.0" ,
37
42
"remark" : " ^13.0.0" ,
38
43
"remark-cli" : " ^9.0.0" ,
39
44
"remark-preset-wooorm" : " ^8.0.0" ,
45
+ "rimraf" : " ^3.0.0" ,
40
46
"tape" : " ^5.0.0" ,
47
+ "type-coverage" : " ^2.0.0" ,
48
+ "typescript" : " ^4.0.0" ,
41
49
"xo" : " ^0.39.0"
42
50
},
43
51
"scripts" : {
52
+ "prepack" : " npm run build && npm run format" ,
53
+ "build" : " rimraf \" *.d.ts\" && tsc && type-coverage" ,
44
54
"format" : " remark . -qfo && prettier . -w --loglevel warn && xo --fix" ,
45
55
"test-api" : " node test.js" ,
46
56
"test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js" ,
47
- "test" : " npm run format && npm run test-coverage"
57
+ "test" : " npm run build && npm run format && npm run test-coverage"
48
58
},
49
59
"prettier" : {
50
60
"tabWidth" : 2 ,
65
75
"plugins" : [
66
76
" preset-wooorm"
67
77
]
78
+ },
79
+ "typeCoverage" : {
80
+ "atLeast" : 100 ,
81
+ "detail" : true ,
82
+ "strict" : true
68
83
}
69
84
}
Original file line number Diff line number Diff line change @@ -55,15 +55,15 @@ Now, running `node example` yields:
55
55
56
56
## API
57
57
58
- ### ` source(value, doc ) `
58
+ ### ` source(value, file ) `
59
59
60
60
This package exports the following identifiers: ` source ` .
61
61
There is no default export.
62
62
63
63
###### Parameters
64
64
65
65
* ` value ` ([ ` Node ` ] [ node ] or [ ` Position ` ] [ position ] ) — Value to get
66
- * ` doc ` ([ ` VFile ` ] [ vfile ] or ` string ` ) — [ file] [ ] in which ` value ` exists
66
+ * ` file ` ([ ` VFile ` ] [ vfile ] or ` string ` ) — [ file] [ ] in which ` value ` exists
67
67
68
68
###### Returns
69
69
Original file line number Diff line number Diff line change
1
+ {
2
+ "include" : [" *.js" ],
3
+ "compilerOptions" : {
4
+ "target" : " ES2020" ,
5
+ "lib" : [" ES2020" ],
6
+ "module" : " ES2020" ,
7
+ "moduleResolution" : " node" ,
8
+ "allowJs" : true ,
9
+ "checkJs" : true ,
10
+ "declaration" : true ,
11
+ "emitDeclarationOnly" : true ,
12
+ "allowSyntheticDefaultImports" : true ,
13
+ "skipLibCheck" : true
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments