https://github.com/shanamaid/akua
It can solve your nested if-tree, make it become chainable if!
https://github.com/shanamaid/akua
chainable-if if if-tree nested-if
Last synced: 11 months ago
JSON representation
It can solve your nested if-tree, make it become chainable if!
- Host: GitHub
- URL: https://github.com/shanamaid/akua
- Owner: ShanaMaid
- License: mit
- Created: 2018-08-10T06:50:37.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-13T03:27:51.000Z (almost 8 years ago)
- Last Synced: 2025-06-29T14:39:44.075Z (12 months ago)
- Topics: chainable-if, if, if-tree, nested-if
- Language: TypeScript
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Akua
Chainable `if`!
`Akua` is a very useful tools! It can solve your `nested if-tree`, make it become
`chainable if`!
`Akua` can help you code maintainable if!
## Install
```
npm install akua --save
```
## Use
normal nested if-tree
```js
let normalIf = '';
const normailIfStart = new Date().getTime();
if (conditionA) {
const tempA = 'tempA';
normalIf += 'a';
if (conditionB) {
normalIf += 'b';
normalIf += tempA;
if (conditionC) {
normalIf += 'c';
if (conditionD) {
normalIf += 'd';
if (conditionE) {
normalIf += 'e';
}
}
}
} else {
normalIf += '!b';
}
if (conditionF) {
normalIf += 'f';
if (conditionG) {
normalIf += 'g';
}
}
} else {
normalIf += '!a';
}
```
akua if
```js
let akuaIf = '';
const ifTree = new akua();
ifTree
.inject(conditionA, 'a', (obj) => {
obj.tempA = 'tempA';
akuaIf += 'a';
})
.inject(!conditionA, '!a', () => {
akuaIf += '!a';
})
.inject(conditionB, 'a->b', (obj) => {
akuaIf += 'b';
akuaIf += obj.tempA;
})
.inject(!conditionB, 'a->!b', () => {
akuaIf += '!b';
})
.inject(conditionC, 'b->c', () => {
akuaIf += 'c';
})
.inject(conditionD, 'c->d', () => {
akuaIf += 'd';
})
.inject(conditionE, 'd->e', () => {
akuaIf += 'e';
})
.inject(conditionF, 'a->f', () => {
akuaIf += 'f';
})
.inject(conditionG, 'f->g', () => {
akuaIf += 'g';
})
.parse();
```
Finally, `normalIf === akuaIf`, you can git clone this project and `npm run test` if you doubt!
## Unit Test Exampls
- [unit test](./test/unit.ts)
## Perfomance
`npm run test`
```
test: 1000, success: 1000, fail: 0
normal-if cost time: 2ms
akua-if cost time: 7ms
```
```
test: 100000, success: 100000, fail: 0
normal-if cost time: 19ms
akua-if cost time: 175ms
```