-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes GH-1. Reviewed-by: Titus Wormer <[email protected]>
- Loading branch information
1 parent
dc85434
commit 66e36ea
Showing
5 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,28 +15,35 @@ | |
"author": "azu <[email protected]>", | ||
"contributors": [ | ||
"azu <[email protected]>", | ||
"Titus Wormer <[email protected]> (https://wooorm.com)" | ||
"Titus Wormer <[email protected]> (https://wooorm.com)", | ||
"Christian Murphy <[email protected]>" | ||
], | ||
"files": [ | ||
"index.js" | ||
"index.js", | ||
"types/index.d.ts" | ||
], | ||
"types": "types/index.d.ts", | ||
"dependencies": { | ||
"@types/mdast": "^3.0.3", | ||
"object-assign": "^4.0.1" | ||
}, | ||
"devDependencies": { | ||
"dtslint": "^0.9.9", | ||
"nyc": "^14.0.0", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"tape": "^4.10.1", | ||
"unist-builder": "^1.0.3", | ||
"unist-util-is": "^4.0.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run test-coverage" | ||
"test-types": "dtslint types", | ||
"test": "npm run format && npm run test-coverage && npm run test-types" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// TypeScript Version: 3.5 | ||
|
||
import {Node} from 'unist' | ||
|
||
declare namespace unistUtilMap { | ||
type MapFunction = (node: Node, index: number | null, parent: Node | null) => Node | ||
} | ||
|
||
/** | ||
* unist utility to create a new tree by mapping all nodes with the given function. | ||
* | ||
* @param tree Tree to map | ||
* @param callback Function that returns a new node | ||
* @returns Node to be used in the new tree. | ||
* Its children are not used: if the original node has children, those are mapped. | ||
*/ | ||
declare function unistUtilMap(tree: Node, callback: unistUtilMap.MapFunction): Node | ||
|
||
export = unistUtilMap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015"], | ||
"strict": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"unist-util-map": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"whitespace": false, | ||
"semicolon": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as map from 'unist-util-map' | ||
import * as is from 'unist-util-is' | ||
import {Node} from 'unist' | ||
import {Heading, Paragraph} from 'mdast' | ||
|
||
// $ExpectType Node | ||
map({type: 'root'}, (node: Node) => ({type: node.type + 'test'})) | ||
// $ExpectType Node | ||
map({type: 'root'}, (node: Node, index: number | null) => ({ | ||
type: node.type + 'test' | ||
})) | ||
// $ExpectType Node | ||
map( | ||
{type: 'root'}, | ||
(node: Node, index: number | null, parent: Node | null) => ({ | ||
type: node.type + 'test' | ||
}) | ||
) | ||
// $ExpectType Node | ||
map({type: 'root'}, (node: Node) => { | ||
if (is<Heading>(node, 'heading')) { | ||
const depth = node.depth < 5 ? node.depth + 1 : 6 | ||
return { | ||
...node, | ||
depth | ||
} | ||
} | ||
|
||
if (is<Paragraph>(node, 'paragraph')) { | ||
return { | ||
type: 'strong', | ||
children: node.children | ||
} | ||
} | ||
|
||
return node | ||
}) |