Skip to content

Commit 8e6dda1

Browse files
committed
feat(visit): visit
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent ea4c84b commit 8e6dda1

29 files changed

+1403
-36
lines changed

.codecov.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ ignore:
8686
- '**/interfaces/'
8787
- '**/types/'
8888
- '**/index.ts'
89+
- src/color*.ts
8990

9091
profiling:
91-
critical_files_paths: []
92+
critical_files_paths:
93+
- src/visit.ts

.eslintrc.base.cjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ const config = {
747747
'unicorn/prefer-export-from': [2, { ignoreUsedVariables: true }],
748748
'unicorn/prefer-includes': 2,
749749
'unicorn/prefer-json-parse-buffer': 0,
750-
'unicorn/prefer-math-trunc': 2,
750+
'unicorn/prefer-math-trunc': 0,
751751
'unicorn/prefer-module': 2,
752752
'unicorn/prefer-negative-index': 2,
753753
'unicorn/prefer-node-protocol': 2,

.eslintrc.cjs

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@
1010
*/
1111
const config = {
1212
extends: ['./.eslintrc.base.cjs'],
13-
overrides: [...require('./.eslintrc.base.cjs').overrides],
13+
overrides: [
14+
...require('./.eslintrc.base.cjs').overrides,
15+
{
16+
files: ['src/__tests__/visit.functional.spec.ts'],
17+
rules: {
18+
'jest-formatting/padding-around-expect-groups': 0
19+
}
20+
},
21+
{
22+
files: ['src/visit.ts'],
23+
rules: {
24+
'jsdoc/require-returns-check': 0
25+
}
26+
}
27+
],
1428
root: true
1529
}
1630

__fixtures__/.gitkeep

Whitespace-only changes.

__fixtures__/digitize.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @file Fixtures - digitize
3+
* @module fixtures/digitize
4+
* @see https://codewars.com/kata/5583090cbe83f4fd8c000051
5+
*/
6+
7+
/**
8+
* Given a random non-negative number, `n`, the function returns an array with
9+
* the digits of `n` in reverse.
10+
*
11+
* @example
12+
* digitize(0) // [0]
13+
* @example
14+
* digitize(348597) // [7, 9, 5, 8, 4, 3]
15+
*
16+
* @param {number} n - Positive integer to reverse
17+
* @return {number[]} Digits of `n` in reverse
18+
*/
19+
const digitize = (n: number): number[] => {
20+
if (n <= 9) return [n]
21+
22+
/**
23+
* Digits of {@linkcode n} reversed.
24+
*
25+
* @const {number[]} digits
26+
*/
27+
const digits: number[] = []
28+
29+
// iterate through digits starting from rightmost digit
30+
while (n > 0) digits.push(n % 10 | 0) && (n = n / 10 | 0)
31+
32+
return digits
33+
}
34+
35+
export default digitize

__fixtures__/postorder.ts

+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
/**
2+
* @file Fixtures - postorder
3+
* @module fixtures/postorder
4+
*/
5+
6+
import type { VisitedType } from '#tests/types'
7+
import type { EmptyArray } from '@flex-development/tutils'
8+
9+
/**
10+
* Object containing node types visited during postorder traversal.
11+
*/
12+
type Postorder = {
13+
/**
14+
* Ancestor node types visited during postorder traversal.
15+
*
16+
* @see {@linkcode VisitedType}
17+
*/
18+
ancestors: [...VisitedType[][], EmptyArray]
19+
20+
/**
21+
* Parent node types visited during postorder traversal.
22+
*/
23+
parents: [...VisitedType[], undefined]
24+
25+
/**
26+
* All node types visited during postorder traversal.
27+
*
28+
* @see {@linkcode VisitedType}
29+
*/
30+
types: [...Exclude<VisitedType, 'root'>[], 'root']
31+
32+
/**
33+
* All node types visited during reverse postorder traversal.
34+
*
35+
* @see {@linkcode VisitedType}
36+
*/
37+
typesReversed: [...Exclude<VisitedType, 'root'>[], 'root']
38+
}
39+
40+
/**
41+
* All node types visited during postorder traversal.
42+
*
43+
* @const {Postorder['types']} types
44+
*/
45+
const types: Postorder['types'] = [
46+
'text',
47+
'blockTag',
48+
'text',
49+
'blockTag',
50+
'text',
51+
'blockTag',
52+
'comment',
53+
'text', // siblings skipped
54+
'inlineCode',
55+
'text',
56+
'inlineCode',
57+
'text',
58+
'paragraph',
59+
'description',
60+
'code',
61+
'blockTag',
62+
'code',
63+
'blockTag',
64+
'typeExpression',
65+
'text',
66+
'blockTag',
67+
'typeExpression',
68+
'text',
69+
'inlineCode',
70+
'text',
71+
'blockTag',
72+
'comment',
73+
'text',
74+
'inlineTag',
75+
'text',
76+
'paragraph',
77+
'description',
78+
'typeExpression',
79+
'text',
80+
'blockTag',
81+
'comment',
82+
'root'
83+
]
84+
85+
/**
86+
* All node types visited during reverse postorder traversal.
87+
*
88+
* @const {Postorder['typesReversed']} typesReversed
89+
*/
90+
const typesReversed: Postorder['typesReversed'] = [
91+
'text',
92+
'typeExpression',
93+
'blockTag',
94+
'text',
95+
'inlineTag',
96+
'text',
97+
'paragraph',
98+
'description',
99+
'comment',
100+
'text',
101+
'inlineCode',
102+
'text',
103+
'typeExpression',
104+
'blockTag',
105+
'text',
106+
'typeExpression',
107+
'blockTag',
108+
'code',
109+
'blockTag',
110+
'code',
111+
'blockTag',
112+
'text',
113+
'inlineCode',
114+
'text',
115+
'inlineCode',
116+
'text',
117+
'paragraph',
118+
'description',
119+
'comment',
120+
'text',
121+
'blockTag',
122+
'text',
123+
'blockTag',
124+
'text',
125+
'blockTag',
126+
'comment',
127+
'root'
128+
]
129+
130+
/**
131+
* Parent node types visited during postorder traversal.
132+
*
133+
* @const {Postorder['parents']} parents
134+
*/
135+
const parents: Postorder['parents'] = [
136+
'blockTag',
137+
'comment',
138+
'blockTag',
139+
'comment',
140+
'blockTag',
141+
'comment',
142+
'root',
143+
'paragraph',
144+
'paragraph',
145+
'paragraph',
146+
'paragraph',
147+
'paragraph',
148+
'description',
149+
'comment',
150+
'blockTag',
151+
'comment',
152+
'blockTag',
153+
'comment',
154+
'blockTag',
155+
'blockTag',
156+
'comment',
157+
'blockTag',
158+
'blockTag',
159+
'blockTag',
160+
'blockTag',
161+
'comment',
162+
'root',
163+
'paragraph',
164+
'paragraph',
165+
'paragraph',
166+
'description',
167+
'comment',
168+
'blockTag',
169+
'blockTag',
170+
'comment',
171+
'root',
172+
undefined
173+
]
174+
175+
/**
176+
* Ancestor node types visited during postorder traversal.
177+
*
178+
* @const {Postorder['ancestors']} ancestors
179+
*/
180+
const ancestors: Postorder['ancestors'] = [
181+
['root', 'comment'],
182+
['root'],
183+
['root', 'comment'],
184+
['root'],
185+
['root', 'comment'],
186+
['root'],
187+
[],
188+
['root', 'comment', 'description'],
189+
['root', 'comment', 'description'],
190+
['root', 'comment', 'description'],
191+
['root', 'comment', 'description'],
192+
['root', 'comment', 'description'],
193+
['root', 'comment'],
194+
['root'],
195+
['root', 'comment'],
196+
['root'],
197+
['root', 'comment'],
198+
['root'],
199+
['root', 'comment'],
200+
['root', 'comment'],
201+
['root'],
202+
['root', 'comment'],
203+
['root', 'comment'],
204+
['root', 'comment'],
205+
['root', 'comment'],
206+
['root'],
207+
[],
208+
['root', 'comment', 'description'],
209+
['root', 'comment', 'description'],
210+
['root', 'comment', 'description'],
211+
['root', 'comment'],
212+
['root'],
213+
['root', 'comment'],
214+
['root', 'comment'],
215+
['root'],
216+
[],
217+
[]
218+
]
219+
220+
/**
221+
* Nodes visited during postorder traversal.
222+
*
223+
* @const {Readonly<Postorder>} postorder
224+
*/
225+
const postorder: Readonly<Postorder> = Object.freeze({
226+
ancestors,
227+
parents,
228+
types,
229+
typesReversed
230+
})
231+
232+
export default postorder

0 commit comments

Comments
 (0)