Skip to content

Commit

Permalink
feat(visit): visit
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Mar 20, 2024
1 parent ea4c84b commit 8e6dda1
Show file tree
Hide file tree
Showing 29 changed files with 1,403 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ ignore:
- '**/interfaces/'
- '**/types/'
- '**/index.ts'
- src/color*.ts

profiling:
critical_files_paths: []
critical_files_paths:
- src/visit.ts
2 changes: 1 addition & 1 deletion .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ const config = {
'unicorn/prefer-export-from': [2, { ignoreUsedVariables: true }],
'unicorn/prefer-includes': 2,
'unicorn/prefer-json-parse-buffer': 0,
'unicorn/prefer-math-trunc': 2,
'unicorn/prefer-math-trunc': 0,
'unicorn/prefer-module': 2,
'unicorn/prefer-negative-index': 2,
'unicorn/prefer-node-protocol': 2,
Expand Down
16 changes: 15 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@
*/
const config = {
extends: ['./.eslintrc.base.cjs'],
overrides: [...require('./.eslintrc.base.cjs').overrides],
overrides: [
...require('./.eslintrc.base.cjs').overrides,
{
files: ['src/__tests__/visit.functional.spec.ts'],
rules: {
'jest-formatting/padding-around-expect-groups': 0
}
},
{
files: ['src/visit.ts'],
rules: {
'jsdoc/require-returns-check': 0
}
}
],
root: true
}

Expand Down
Empty file removed __fixtures__/.gitkeep
Empty file.
35 changes: 35 additions & 0 deletions __fixtures__/digitize.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @file Fixtures - digitize
* @module fixtures/digitize
* @see https://codewars.com/kata/5583090cbe83f4fd8c000051
*/

/**
* Given a random non-negative number, `n`, the function returns an array with
* the digits of `n` in reverse.
*
* @example
* digitize(0) // [0]
* @example
* digitize(348597) // [7, 9, 5, 8, 4, 3]
*
* @param {number} n - Positive integer to reverse
* @return {number[]} Digits of `n` in reverse
*/
const digitize = (n: number): number[] => {
if (n <= 9) return [n]

/**
* Digits of {@linkcode n} reversed.
*
* @const {number[]} digits
*/
const digits: number[] = []

// iterate through digits starting from rightmost digit
while (n > 0) digits.push(n % 10 | 0) && (n = n / 10 | 0)

return digits
}

export default digitize
232 changes: 232 additions & 0 deletions __fixtures__/postorder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
/**
* @file Fixtures - postorder
* @module fixtures/postorder
*/

import type { VisitedType } from '#tests/types'
import type { EmptyArray } from '@flex-development/tutils'

/**
* Object containing node types visited during postorder traversal.
*/
type Postorder = {
/**
* Ancestor node types visited during postorder traversal.
*
* @see {@linkcode VisitedType}
*/
ancestors: [...VisitedType[][], EmptyArray]

/**
* Parent node types visited during postorder traversal.
*/
parents: [...VisitedType[], undefined]

/**
* All node types visited during postorder traversal.
*
* @see {@linkcode VisitedType}
*/
types: [...Exclude<VisitedType, 'root'>[], 'root']

/**
* All node types visited during reverse postorder traversal.
*
* @see {@linkcode VisitedType}
*/
typesReversed: [...Exclude<VisitedType, 'root'>[], 'root']
}

/**
* All node types visited during postorder traversal.
*
* @const {Postorder['types']} types
*/
const types: Postorder['types'] = [
'text',
'blockTag',
'text',
'blockTag',
'text',
'blockTag',
'comment',
'text', // siblings skipped
'inlineCode',
'text',
'inlineCode',
'text',
'paragraph',
'description',
'code',
'blockTag',
'code',
'blockTag',
'typeExpression',
'text',
'blockTag',
'typeExpression',
'text',
'inlineCode',
'text',
'blockTag',
'comment',
'text',
'inlineTag',
'text',
'paragraph',
'description',
'typeExpression',
'text',
'blockTag',
'comment',
'root'
]

/**
* All node types visited during reverse postorder traversal.
*
* @const {Postorder['typesReversed']} typesReversed
*/
const typesReversed: Postorder['typesReversed'] = [
'text',
'typeExpression',
'blockTag',
'text',
'inlineTag',
'text',
'paragraph',
'description',
'comment',
'text',
'inlineCode',
'text',
'typeExpression',
'blockTag',
'text',
'typeExpression',
'blockTag',
'code',
'blockTag',
'code',
'blockTag',
'text',
'inlineCode',
'text',
'inlineCode',
'text',
'paragraph',
'description',
'comment',
'text',
'blockTag',
'text',
'blockTag',
'text',
'blockTag',
'comment',
'root'
]

/**
* Parent node types visited during postorder traversal.
*
* @const {Postorder['parents']} parents
*/
const parents: Postorder['parents'] = [
'blockTag',
'comment',
'blockTag',
'comment',
'blockTag',
'comment',
'root',
'paragraph',
'paragraph',
'paragraph',
'paragraph',
'paragraph',
'description',
'comment',
'blockTag',
'comment',
'blockTag',
'comment',
'blockTag',
'blockTag',
'comment',
'blockTag',
'blockTag',
'blockTag',
'blockTag',
'comment',
'root',
'paragraph',
'paragraph',
'paragraph',
'description',
'comment',
'blockTag',
'blockTag',
'comment',
'root',
undefined
]

/**
* Ancestor node types visited during postorder traversal.
*
* @const {Postorder['ancestors']} ancestors
*/
const ancestors: Postorder['ancestors'] = [
['root', 'comment'],
['root'],
['root', 'comment'],
['root'],
['root', 'comment'],
['root'],
[],
['root', 'comment', 'description'],
['root', 'comment', 'description'],
['root', 'comment', 'description'],
['root', 'comment', 'description'],
['root', 'comment', 'description'],
['root', 'comment'],
['root'],
['root', 'comment'],
['root'],
['root', 'comment'],
['root'],
['root', 'comment'],
['root', 'comment'],
['root'],
['root', 'comment'],
['root', 'comment'],
['root', 'comment'],
['root', 'comment'],
['root'],
[],
['root', 'comment', 'description'],
['root', 'comment', 'description'],
['root', 'comment', 'description'],
['root', 'comment'],
['root'],
['root', 'comment'],
['root', 'comment'],
['root'],
[],
[]
]

/**
* Nodes visited during postorder traversal.
*
* @const {Readonly<Postorder>} postorder
*/
const postorder: Readonly<Postorder> = Object.freeze({
ancestors,
parents,
types,
typesReversed
})

export default postorder
Loading

0 comments on commit 8e6dda1

Please sign in to comment.