# ch4o

> Javascript native utils, include Stack TPL generator etc.

Latest version **3.0.1** (published 2023-08-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install ch4o
pnpm add ch4o
yarn add ch4o
bun add ch4o
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.1 |
| Published | 2023-08-07 |
| First published | 2021-04-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 124.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | chengxiao |
| Maintainers | chengxiao |
| Keywords | utils, exec, string template, stack |

## Links

- npm: https://www.npmjs.com/package/ch4o
- npm.io page: https://npm.io/package/ch4o

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 3.0.1 (latest) — 2023-08-07
- 3.0.0 (next) — 2023-05-14
- 3.0.1-0 — 2023-05-24
- 2.2.2 — 2023-01-09
- 2.2.1 — 2022-12-22
- 2.2.0 — 2022-11-27
- 2.1.0 — 2022-11-23
- 2.0.3 — 2022-11-13
- 2.0.2 — 2022-10-10
- 2.0.1 — 2022-10-10
- 2.0.0 — 2022-09-21
- 1.2.13 — 2022-08-06
- 1.2.12 — 2022-07-18
- 1.2.11 — 2022-07-05
- 1.2.10 — 2022-07-05
- … 40 more at https://npm.io/package/ch4o/versions

## README

# ch4o

Basic NATIVE js utils 

## r
**r** recursively tranverse an object. it provides hooks on each data node, let you to get or modify nodeValue you interested
there are two search algorithms: depth-first(DFS) & breadth-first(BFS), use diffrent way to get particular nodes easier.

example:

```ts
import {r, BFS, DFS} from 'ch4o';
const o = {a: [2,1]};

function watcher(prop, value) {
    console.log(prop, value);
    return value;
}
const maxDepth = 2;
r(o, watcher, DFS, maxDepth);

```

## TPL
TPL is a template generator

```ts
import {TPL, ID, IF, ENDIF, ELSE} from 'ch4o';

const tpl = TPL`Hello ${IF('name')} tpl ${ELSE} ${ID('name')} world${ENDIF}`;

const str = tpl({name: 'ch4o'});
console.log(str);
```

## TaskChain
TaskChain calls task sequence in order, passing result value from one to next, and return the final value
Task can be async, you can use either async/await or Promise

```ts
import {TaskChain, Task} from 'ch4o';

function inc(src, len = 1) {
    return new Promise((resolve, reject) => {
        setTimeout(() => resolve(src + len), 500);
        console.log(src,len);
    });
}
function toString(value, radix = 10) {
    return +value.toString(radix);
}

const tc = new TaskChain([
    inc,
    new Task(toString, 16),
    new class extends Task {
        name = 'inline'
        exec(value){
            return value + '.';
        }
    },
    new LastTask
]);
let res = await tc.exec(253);

```

## exec

Excecute a string of js expression and return its result

```ts
import {exec} from 'ch4o';
console.log(exec('1 + 1')); // 2

// With host values
console.log(exec('1 + a', {a: 2})); // 3

---
_Source: https://npm.io/package/ch4o · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
