File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 11.DS_Store
2+ * .d.ts
23* .log
34coverage /
45node_modules /
Original file line number Diff line number Diff line change 1+ /**
2+ * @typedef {import('xast').Root } Root
3+ * @typedef {import('xast').Element } Element
4+ * @typedef {import('xast').RootChildMap } RootChildMap
5+ * @typedef {RootChildMap[keyof RootChildMap] } Child
6+ * @typedef {Root|Child } Node
7+ * @typedef {Root|Element } Parent
8+ */
9+
10+ /**
11+ * @param {Node } node
12+ * @returns {string }
13+ */
114export function toString ( node ) {
215 // A root or an element
16+ // @ts -ignore Looks like a parent.
317 if ( 'children' in node ) return all ( node )
18+ // @ts -ignore Looks like a literal.
419 return 'value' in node ? node . value : ''
520}
621
22+ /**
23+ * @param {Node } node
24+ * @returns {string }
25+ */
726function one ( node ) {
827 if ( node . type === 'text' ) return node . value
928 // Ignore things like comments, instruction, cdata.
29+ // @ts -ignore Looks like a parent.
1030 return node . children ? all ( node ) : ''
1131}
1232
33+ /**
34+ * @param {Parent } node
35+ * @returns {string }
36+ */
1337function all ( node ) {
1438 var children = node . children
1539 var index = - 1
40+ /** @type {Array.<string> } */
1641 var result = [ ]
1742
1843 while ( ++ index < children . length ) {
Original file line number Diff line number Diff line change 2727 "sideEffects" : false ,
2828 "type" : " module" ,
2929 "main" : " index.js" ,
30+ "types" : " index.d.ts" ,
3031 "files" : [
32+ " index.d.ts" ,
3133 " index.js"
3234 ],
35+ "dependencies" : {
36+ "@types/xast" : " ^1.0.0"
37+ },
3338 "devDependencies" : {
39+ "@types/tape" : " ^4.0.0" ,
3440 "c8" : " ^7.0.0" ,
3541 "prettier" : " ^2.0.0" ,
3642 "remark-cli" : " ^9.0.0" ,
3743 "remark-preset-wooorm" : " ^8.0.0" ,
44+ "rimraf" : " ^3.0.2" ,
3845 "tape" : " ^5.0.0" ,
46+ "type-coverage" : " ^2.17.5" ,
47+ "typescript" : " ^4.2.4" ,
3948 "unist-builder" : " ^3.0.0" ,
4049 "xo" : " ^0.39.0"
4150 },
4251 "scripts" : {
52+ "prepack" : " npm run build && npm run format" ,
53+ "build" : " rimraf \" *.d.ts\" && tsc && type-coverage" ,
4354 "format" : " remark . -qfo && prettier . --write --loglevel warn && xo --fix" ,
4455 "test-api" : " node test.js" ,
4556 "test-coverage" : " c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js" ,
46- "test" : " npm run format && npm run test-coverage"
57+ "test" : " npm run build && npm run format && npm run test-coverage"
4758 },
4859 "prettier" : {
4960 "tabWidth" : 2 ,
6475 "plugins" : [
6576 " preset-wooorm"
6677 ]
78+ },
79+ "typeCoverage" : {
80+ "atLeast" : 100 ,
81+ "detail" : true ,
82+ "strict" : true
6783 }
6884}
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