Skip to content

Commit dc51266

Browse files
committed
feat(init): 🎉 Initial commit
1 parent a51464c commit dc51266

File tree

52 files changed

+4437
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+4437
-0
lines changed

.eslintrc.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
extends: ['@antfu/eslint-config-ts'],
3+
rules: {
4+
'operator-linebreak': 'off',
5+
'linebreak-style': ['error', 'unix'],
6+
'eol-last': ['error', 'always'],
7+
},
8+
}

.github/workflows/publish.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish package
2+
on:
3+
release:
4+
types: [created]
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: pnpm/action-setup@v2
13+
with:
14+
version: 7
15+
- uses: actions/setup-node@v3
16+
with:
17+
node-version: "16"
18+
registry-url: "https://registry.npmjs.org"
19+
cache: "pnpm"
20+
- run: pnpm install
21+
- name: Build
22+
run: pnpm run build
23+
- name: Run tests
24+
run: pnpm run test
25+
- name: Update package.json
26+
shell: pwsh
27+
run: |
28+
$env:RELEASE_VERSION = $env:GITHUB_REF.split('/')[2]
29+
echo "RELEASE_VERSION=$env:RELEASE_VERSION" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
30+
$content = Get-Content .\package.json
31+
$content = $content | foreach-object { $_ -replace '(?<prefix>^.+"version": ")(.+)(?<suffix>",)$', "`${prefix}$env:RELEASE_VERSION`${suffix}" }
32+
$content | foreach-object { [System.Text.RegularExpressions.Regex]::Unescape($_) } | Out-File .\package.json -Force -Encoding ascii
33+
- uses: stefanzweifel/git-auto-commit-action@v4
34+
with:
35+
commit_message: "ci(package-json): :bookmark: Bumped package.json version to ${{ env.RELEASE_VERSION }}"
36+
commit_user_email: [email protected]
37+
branch: main
38+
- run: pnpm publish
39+
env:
40+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test-build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Test and build
2+
on:
3+
pull_request:
4+
types: [opened, synchronize, reopened, closed]
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Setup pnpm
14+
uses: pnpm/action-setup@v2
15+
with:
16+
version: 7
17+
- name: Set node version to 16
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: 16
21+
cache: pnpm
22+
- run: pnpm install
23+
- name: Run typecheck
24+
run: pnpm run typecheck
25+
- name: Run tests
26+
run: pnpm run test

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Dependency directories
2+
node_modules
3+
4+
# Optional eslint cache
5+
.eslintcache
6+
7+
# Build
8+
dist

.vscode/settings.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"vitest.enable": true,
3+
"prettier.enable": false,
4+
"editor.formatOnSave": false,
5+
"editor.codeActionsOnSave": {
6+
"source.fixAll.eslint": true
7+
},
8+
"typescript.format.semicolons": "remove",
9+
"typescript.format.enable": true,
10+
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
11+
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
12+
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": true,
13+
"typescript.preferences.quoteStyle": "single",
14+
}

CONTRIBUTING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contribution Guide
2+
3+
Thanks for your interest in contributing, all contributions are welcome and this section should help you get started.
4+
5+
## Local setup
6+
7+
- Clone this repository
8+
- Make sure you have PNPM and Node16+ installed. We recommend using VSCode.
9+
- Check out a new branch for your contribution (`git checkout -b 'feature/fantastic-new-function'`)
10+
11+
## Commit convention
12+
13+
Before contributing, you should be familiar with the following concepts:
14+
15+
- [Semantic Versioning](https://semver.org/)
16+
- [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
17+
- [gitmoji](https://gitmoji.dev/) - Usage of gitmoji is optional, but highly preferred. It's helping a lot with identifying the exact type of commit on first sight and has basically no overhead when using tools like `gacp`
18+
19+
To create valid commit messages, you have to use conventional commits. For the type, it's preferred to use emojis with optional text and to use scopes where possible. We use the following defined types with optional scopes to be able to comply with semver and make automatic CHANGELOG generation and tagging/versioning possible:
20+
21+
- build
22+
- chore
23+
- ci
24+
- docs
25+
- feat
26+
- fix
27+
- perf
28+
- refactor
29+
- revert
30+
- style
31+
- test
32+
33+
We recommend to use a tool like [gitmoji-cli](https://github.com/carloscuesta/gitmoji-cli) or [gacp](https://github.com/vivaxy/gacp) to make following these requirements easier.
34+
35+
Note that `fix:` and `feat:` are for code changes. For typo or document changes, use `docs:` or `chore:` instead.
36+
37+
## Pull request
38+
39+
If you finished your change, you can create a pull request (PR) to get them merged. If you are not familiar with the process, GitHub has a [guide on PRs](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request).
40+
41+
:warning: **Before creatign a PR, please make sure that you added tests for new features if you added some and that no tests are failing (`pnpm run test`).**
42+
43+
If you are closing issues with a PR, please reference the issues in the PR description (`fix/fixes #123` where 123 is the issue id).

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# @itpropro/tree-structure-ts
2+
3+
## Introduction
4+
5+
This module help interacting with `Tree` structures. It is optimized to work with big trees without causing overflows. Therefore it doesn't use recursion and the implementations for `preOrder` and `postOrder` traversals use `Promise.all` for concurrency to traverse multiple nodes at ones.
6+
It is fully typed and has over 95% test coverage.
7+
8+
- Zero dependency
9+
- Fully typed
10+
- Fast
11+
- No recursion -> no memory overflows
12+
13+
## Installation
14+
15+
To install the module, run the following command:
16+
17+
```bash
18+
pnpm install @itpropro/tree-structure-ts
19+
```
20+
21+
## Usage
22+
23+
To create a new `Tree` instance, use the `Tree` constructor:
24+
25+
```typescript
26+
const tree = new Tree('root')
27+
const root = tree.root
28+
```
29+
30+
To add a child node to a TreeNode, use the addChild method:
31+
32+
```typescript
33+
const child1 = root.addChild('child1')
34+
const child2 = root.addChild('child2')
35+
```
36+
37+
To get all nodes in the tree below a TreeNode, use the all method:
38+
39+
```typescript
40+
const nodes = root.all()
41+
```
42+
43+
To traverse a tree, use the traverse method:
44+
45+
```typescript
46+
root.traverse((node) => {
47+
// This function is called for each node in the tree
48+
})
49+
```
50+
51+
You can specify the traversal order by passing one of the following values to the traverse method:
52+
53+
- breadthFirst (the default): visits nodes in breadth-first order
54+
- depthFirst: visits nodes in depth-first order
55+
- preOrder: visits the current node, then traverses the left subtree, then traverses the right subtree
56+
- postOrder: traverses the left subtree, then traverses the right subtree, then visits the current node
57+
58+
for all avalaible methods and fields, please read the detailed documentation of the `Tree` and `TreeNode` class: [Class docs](modules.md).
59+
60+
## Contribution
61+
62+
See [Contributing Guide](https://github.com/itpropro/tree-structure-ts/blob/main/CONTRIBUTING.md).
63+
64+
## License
65+
66+
Made with :heart:
67+
68+
Published under [MIT License](./LICENCE).

coverage/coverage-summary.json

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"total": {
3+
"lines": {
4+
"total": 238,
5+
"covered": 233,
6+
"skipped": 0,
7+
"pct": 97.89
8+
},
9+
"statements": {
10+
"total": 238,
11+
"covered": 233,
12+
"skipped": 0,
13+
"pct": 97.89
14+
},
15+
"functions": {
16+
"total": 16,
17+
"covered": 16,
18+
"skipped": 0,
19+
"pct": 100
20+
},
21+
"branches": {
22+
"total": 48,
23+
"covered": 45,
24+
"skipped": 0,
25+
"pct": 93.75
26+
},
27+
"branchesTrue": {
28+
"total": 0,
29+
"covered": 0,
30+
"skipped": 0,
31+
"pct": "Unknown"
32+
}
33+
},
34+
"E:\\repos\\tree-structure-ts\\src\\Tree.ts": {
35+
"lines": {
36+
"total": 80,
37+
"covered": 79,
38+
"skipped": 0,
39+
"pct": 98.75
40+
},
41+
"functions": {
42+
"total": 5,
43+
"covered": 5,
44+
"skipped": 0,
45+
"pct": 100
46+
},
47+
"statements": {
48+
"total": 80,
49+
"covered": 79,
50+
"skipped": 0,
51+
"pct": 98.75
52+
},
53+
"branches": {
54+
"total": 18,
55+
"covered": 17,
56+
"skipped": 0,
57+
"pct": 94.44
58+
}
59+
},
60+
"E:\\repos\\tree-structure-ts\\src\\TreeNode.ts": {
61+
"lines": {
62+
"total": 158,
63+
"covered": 154,
64+
"skipped": 0,
65+
"pct": 97.46
66+
},
67+
"functions": {
68+
"total": 11,
69+
"covered": 11,
70+
"skipped": 0,
71+
"pct": 100
72+
},
73+
"statements": {
74+
"total": 158,
75+
"covered": 154,
76+
"skipped": 0,
77+
"pct": 97.46
78+
},
79+
"branches": {
80+
"total": 30,
81+
"covered": 28,
82+
"skipped": 0,
83+
"pct": 93.33
84+
}
85+
}
86+
}

coverage/tmp/coverage-21368-1670968005243-13.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

coverage/tmp/coverage-21368-1670968005297-17.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)