|
1 | 1 | /**
|
2 |
| - * @typedef {import('unist').Parent} UnistParent |
3 |
| - * @typedef {import('unist').Node} UnistNode |
| 2 | + * @template {import('unist').Parent} Kind |
| 3 | + * @typedef {import('./lib/index.js').Modifier<Kind>} Modifier |
4 | 4 | */
|
5 | 5 |
|
6 | 6 | /**
|
7 |
| - * @template {UnistParent} Parent |
8 |
| - * @callback Modifier |
9 |
| - * Callback called for each `child` in `parent` later given to `modify`. |
10 |
| - * @param {Parent['children'][number]} node |
11 |
| - * Child of `parent`. |
12 |
| - * @param {number} index |
13 |
| - * Position of `child` in `parent`. |
14 |
| - * @param {Parent} parent |
15 |
| - * Parent node. |
16 |
| - * @returns {number|void} |
17 |
| - * Position to move to next. |
| 7 | + * @template {import('unist').Parent} Kind |
| 8 | + * @typedef {import('./lib/index.js').Modify<Kind>} Modify |
18 | 9 | */
|
19 | 10 |
|
20 |
| -/** |
21 |
| - * @template {UnistParent} Parent |
22 |
| - * @callback Modify |
23 |
| - * Modify children of `parent`. |
24 |
| - * @param {Parent} node |
25 |
| - * Parent node. |
26 |
| - * @returns {void} |
27 |
| - * Nothing. |
28 |
| - */ |
29 |
| - |
30 |
| -import {arrayIterate} from 'array-iterate' |
31 |
| - |
32 |
| -/** |
33 |
| - * Wrap `modifier` to be called for each child in the nodes later given to |
34 |
| - * `modify`. |
35 |
| - * |
36 |
| - * @template {UnistParent} Parent |
37 |
| - * @param {Modifier<Parent>} modifier |
38 |
| - * Callback called for each `child` in `parent` later given to `modify`. |
39 |
| - * @returns {Modify<Parent>} |
40 |
| - * Modify children of `parent`. |
41 |
| - */ |
42 |
| -export function modifyChildren(modifier) { |
43 |
| - return modify |
44 |
| - |
45 |
| - /** @type {Modify<UnistParent>} */ |
46 |
| - function modify(parent) { |
47 |
| - if (!parent || !parent.children) { |
48 |
| - throw new Error('Missing children in `parent` for `modifier`') |
49 |
| - } |
50 |
| - |
51 |
| - arrayIterate(parent.children, iteratee, parent) |
52 |
| - } |
53 |
| - |
54 |
| - /** |
55 |
| - * Pass the context as the third argument to `modifier`. |
56 |
| - * |
57 |
| - * @this {Parent} |
58 |
| - * @param {UnistNode} node |
59 |
| - * @param {number} index |
60 |
| - */ |
61 |
| - function iteratee(node, index) { |
62 |
| - return modifier(node, index, this) |
63 |
| - } |
64 |
| -} |
| 11 | +export {modifyChildren} from './lib/index.js' |
0 commit comments