open-index/open-npm huggingface dataset:
npm package: @golden-tiger/clone
Description: @golden-tiger/clone
Author: Cheng ChangHu
Latest version: 0.0.4

# #golden-tiger/clone

Clone a JS Value (Undefined, Null, NaN, String, Number, BigInt, Boolean, Map, Set, Date, RegExp).

```js
import Clone from '@golden-tiger/clone'; // mjs
const { clone } = Clone;

const a = 'string';
console.log(clone(a)); // string
console.log(a === clone(a)); // true

const b = 123;
console.log(clone(b)); // 123
console.log(b === clone(b)); // true

const c = 123n;
console.log(clone(c)); // 123n
console.log(c === clone(c)); // true

const d = false;
console.log(clone(d)); // false
console.log(d === clone(d)); // true

const e = { a, b, d, e: {} };
const clone_e = clone(e);
console.log(JSON.stringify(clone_e)); // {"a":"string","b":123,"d":false,"e":{}}
console.log(e === clone_e); // false
console.log(e.a === clone_e.a); // true
console.log(e.e === clone_e.e); // false

const f = [ a, b, d, [] ];
const clone_f = clone(f);
console.log(JSON.stringify(clone_f)); // ["string",123,false,[]]
console.log(f === clone_f); // false
console.log(f[0] === clone_f[0]); // true
console.log(f[3] === clone_f[3]); // false

const ga = {};
const g = new Map([['ga', ga]]);
const clone_g = clone(g);
console.log(Array.from(clone_g)); // [ [ 'ga', {} ] ]
console.log(g === clone_g); // false
console.log(g.get('ga') === clone_g.get('ga')); // false

const ha = [ a, b, d, [] ];
const h = new Set(ha);
const clone_h = clone(h);
console.log(Array.from(clone_h)); // [ 'string', 123, false, [] ]
console.log(h === clone_h); // false
console.log(Array.from(h)[0] === Array.from(clone_h)[0]); // true
console.log(Array.from(h)[3] === Array.from(clone_h)[3]); // false

const i = new Date();
const clone_i = new Date(i.getTime());
console.log(i.getTime() === clone_i.getTime()); // true
console.log(i === clone_i); // false

const j = /^test$/;
const clone_j = clone(j);
console.log(j.source === clone_j.source); // true
console.log(j === clone_j); // false
```
npm package: @golden-tiger/custom-clean-plugin
Description: @golden-tiger/custom-clean-plugin
Author: Cheng ChangHu
Latest version: 0.0.1

# @golden-tiger/custom-clean-plugin

This webpack plugin will remove all files and directories passed from parameters before webpack bundling.

```
import CustomCleanPlugin from '@golden-tiger/custom-clean-plugin';
// ...
{
  plugins: [
    new CustomCleanPlugin([
      path.join(__dirname, 'dist'),
      path.join(__dirname, 'index.html'),
      // ...
    ]),
  ],
}
```
npm package: @golden-tiger/dom
Description: Creating and query HTML element through a easier way
Author: Cheng ChangHu
Latest version: 0.0.6

# #golden-tiger/dom

## `query(queryString)`

Query HTML element and cache queried elements.

## `createElement(option)`

Recursively create HTML element from option. A falsy option will create nothing. A HTML element option will just return it. A array option will create a HTML element array.

- `option.tag` element tag string (a falsy tag will create a template element)
- `option.text` element text string
- `option.html` element inner html string
- `option.children` element children array
- `option.attributes` element attributes object (classes is a key in option.attributes for element class, which is set in format of string or array of string)
- `option.events` element events object
- `option.lifecycle` element lifecycle

## `createHTMLString(options)`

Create HTML string from options.
npm package: @golden-tiger/fstree
Description: @golden-tiger/fstree
Author: Cheng ChangHu
Latest version: 0.0.7

# #golden-tiger/fstree

Use ASCII code to display the file system tree with stat data.

## Usage

1. `git clone git@github.com:CHENGCHANGHU/fstree.git`
2. `pnpm install` or `npm install`
3. `npm link`

## Arguments

1. `--exclude` or `-e`: this argument is used to construct RegExp which will be excluded from the file system tree.
2. `--format` or `-f`: this argument is used to format the display text of every file or directory.
  > It supports `type`(`d`, `l`, `-`), `name`, `size`, `\t` in format string now.

## Example

`fstree -e "node_modules .git" -f "(type) name\t(size)" path/to/a`

```
Display of File System Tree at path/to/a:
(d) a/  (393.00 B)
|- (d) b/       (201.00 B)
|  |- (d) d/    (64.00 B)
|  `- (-) e.txt (9.00 B)
`- (d) c/       (64.00 B)
```
npm package: @golden-tiger/group-request
Description: @golden-tiger/group-request
Author: Cheng ChangHu
Latest version: 0.0.1

# @golden-tiger/group-request

Initiate a group request and set the **retry logic and delay** when catching request errors. When a request goes wrong, you need to set the retry attribute of the rejection reason to true.

# Example

```js
import { request } from '@golden-tiger/group-request';
const testGroup = Array(10)
  .fill(0)
  .map((_, i) => ({ id: i, data: Math.random().toFixed(3) }))
  .map((data) => async () => await fakeRequest(data));

const results = await request({
  group: testGroup,
  maxRetry: 3,
  retryDelay: 1000,
});
console.log(results);
// [
//   null,
//   { retry: false, id: 1, time: 793, data: '0.706' },
//   { retry: false, id: 2, time: 525, data: '0.021' },
//   null,
//   { retry: false, id: 4, time: 383, data: '0.072' },
//   { retry: false, id: 5, time: 199, data: '0.434' },
//   { retry: false, id: 6, time: 450, data: '0.123' },
//   null,
//   null,
//   null
// ]
```

```js
// fakeRequest
async function fakeRequest({ id, data }) {
  const time = Math.floor(Math.random().toFixed(3) * 1000);
  await sleep(time);
  if (Math.random() < 0.8) {
    return Promise.reject({ retry: true, id, data, time });
  }
  return { retry: false, id, time, data };
}
```

```js
// sleep
async function sleep(ms) {
  await new Promise(resolve => setTimeout(resolve, ms));
}
```
npm package: @golden-tiger/js-runner
Description: @golden-tiger/js-runner
Author: Cheng ChangHu
Latest version: 0.0.2

# @golden-tiger/js-runner

JavaScript Runner

```
export declare function run({ code, lexicalEnvironment, executeContext, }: {
    code: string;
    lexicalEnvironment?: any;
    executeContext?: any;
}): Promise<{
    result: any;
    duration: number;
}>;
```
npm package: @golden-tiger/markdown
Description: Transform markdown to HTML
Author: Cheng ChangHu
Latest version: 0.0.25

# #golden-tiger/markdown

Transform markdown text to html element.

## How to use

```js
import { transform } from '@golden-tiger/markdown'; // mjs
const { transform } = require('@golden-tiger/markdown'); // cjs

transform('# Title\n- Content');
```

- `transform` function has 2 parameters:
  - param 1 `mdText`: To transformed markdown text content.
  - param 2 `transformOptions`: Options of output.
    - `output`: `options` or `dom`. `options` means return value of `transform` function will be an object, which describes the HTML structure of the `mdText`. `dom` means return value of `transform` function will be a DOM object, which can be inserted to HTML directly.
    - `indent`: A number, which is the pixel value of indent.

- The basic syntax of `mdText` is same as normal markdown, such as <code>#</code> indicates a header, <code>></code> indicates a quota, and so on.

- Basic tables are made by separating each cell with the pipe <code>|</code> symbol, and can be enhanced further with additional options to create advanced table layouts. This online markdown editor supports <strong>rowspan and colspan</strong> markdown table.
Use <code>|(-m)...|</code> to create a m column span table cell <code>&lt;td colspan="m"&gt;</code>.
Use <code>|(=n)...|</code> to create a n row span table cell <code>&lt;td rowspan="n"&gt;</code>.
```js
// Example:
|(=2)align center|align left|align right|
|a|b|
|:-:|:--|--:|
|c|d|e|
|(-2)f|g|
|h|(-2)(=3)i|
|j|
|k|
```
![markdown-example](./markdown-example.png)
npm package: @golden-tiger/outer-box
Description: @golden-tiger/outer-box
Author: Cheng ChangHu
Latest version: 0.0.11

# @golden-tiger/outer-box

Create outer border box for given target html element.

## Functions

### `useOuterBox(options)`

- `options.target`: wrapped html element.
- `options.boxWidth`: wrapped box width (default value: `2`).
- `options.boxStyle`: wrapped box style (default value: `'dashed'`. `'solid'`, `'dashed'` and other border style css property).
- `options.boxColor`: wrapped box color (default value: `'red'`).
- **returns**: `outerBox`, `update`, `setTarget`,

## Example

![outer-box-example](outer-box-example.png)
npm package: @golden-tiger/regexp-gene
Description: @golden-tiger/regexp-gene
Author: Cheng ChangHu
Latest version: 0.0.7

# @golden-tiger/regexp-gene

Generate random string from a JS regular expression gene.

> [Github Repository](https://github.com/CHENGCHANGHU/regexp-gene)

## Candidate Character Pool (ASCII)

|ASCII Code|characters|
|:--|--:|
|[32, 47], [58, 64], [91, 96], [123, 126]|special character|
|[48, 57]|0-9|
|[65, 90]|A-Z|
|[97, 122]|a-z|

## How To Use `gene(regExp, option)`

- `regExp`: the regular expression gene of random string

- `option.max`: max length of random string, the default max length equal 10

## Examples

- Plain String

```js
gene(/foo/);
// foo
```

- Character Set (any candidate character in the set)

```js
gene(/[abc]/);
// a, b, c
```

- Negate Set (any candidate character that is not in the set)

```js
gene(/[^abc]/);
// any candidate character that is not in the set
```

- Dot (any candidate character)

```js
gene(/./);
// any candidate character
```

- Word (any word character: alphanumeric & underscore)

```js
gene(/\w/);
// a-z, A-Z, 0-9, _
```

- Digit (any digit character: 0-9)

```js
gene(/\d/);
// 0-9
```

- Escaped Character

```js
gene(/\\/);
// \
```

- Group

```js
gene(/(foo(bar)foo)/);
// foobarfoo
```

- Plus (1 or more of the preceding token)

```js
gene(/a+/);
// aaaaaa...
```

- Star (0 or more of the preceding token)

```js
gene(/a*/);
// aaaaaa... or none
```

- Quantifier (the specified quantity of the previous token. `{1,3}` will match 1 to 3. `{3}` will match exactly 3. `{3,}` will match 3 or more.)

```js
gene(/a{1,3}/);
// a or aa or aaa
```

- Optional (0 or 1 of the preceding token)

```js
gene(/ab?/);
// a or ab
```

- Alternation (or)

```js
gene(/a(b|c)d/);
// abd or acd
```
npm package: @golden-tiger/serializer
Description: @golden-tiger/serializer
Author: Cheng ChangHu
Latest version: 0.0.3

# @golden-tiger/serializer

## parse

Parse a string to a valid JS value.

## stringify

Serialize a JS value to a JS string.

## Example

```js
import Serializer from '@golden-tiger/serializer'; // mjs
const Serializer = require('@golden-tiger/serializer'); // cjs

console.log(Serializer.parse('[true]'));
// [true]

console.log(Serializer.stringify([true]));
// [
//  true
// ]
```
npm package: @golden-tiger/watchable
Description: @golden-tiger/watchable
Author: Cheng ChangHu
Latest version: 0.0.1

# @golden-tiger/watchable

## Functions

- `watchable`: Get a watchable object.
- `watch`: Use a watcher function to watch target's specific route property.
- `unwatch`: Stop using a watcher function to watch target's specific route property.

## Examples

```js
function simpleWatcher(newValue, oldValue) {
  console.log('watcher:', newValue, oldValue);
}

const w1 = watchable(
  {
    a: 'a',
    b: { c: 'c' },
    d: [1, 2, 3],
  },
  [
    { route: 'a', watcher: simpleWatcher, },
    { route: 'b.c', watcher: simpleWatcher, },
    { route: 'd.0', watcher: simpleWatcher, },
  ]
);

w1.a = 'new-a'; // watcher: new-a a
w1.b.c = 'new-c'; // watcher: new-c c
w1.d[0] = 10; // watcher: 10 1
console.log(w1); // { a: 'new-a', b: { c: 'new-c' }, d: [ 10, 2, 3 ] }
```

```js
const value1 = watchable({ id: 1, value: true });
const value2 = watchable({ id: 2, value: true });

// and gate
const andGate = watchable({
  dependencies: [value1, value2],
  value: value1.value && value2.value,
});

andGate.dependencies.forEach((dep) => {
  watch(dep, 'value', (newValue, oldValue) => {
    andGate.value = andGate.dependencies.reduce((acc, curr) => {
      if (curr === dep) {
        return newValue && acc;
      }
      return curr.value && acc;
    }, true);
  });
});

// or gate
const orGate = watchable({
  dependencies: [value1, value2],
  value: value1.value || value2.value,
});

orGate.dependencies.forEach((dep) => {
  watch(dep, 'value', (newValue, oldValue) => {
    orGate.value = orGate.dependencies.reduce((acc, curr) => {
      if (curr === dep) {
        return newValue || acc;
      }
      return curr.value || acc;
    }, false);
  });
});

console.log(andGate.value, orGate.value); // true true

value1.value = false;
console.log(andGate.value, orGate.value); // false true

value2.value = false;
console.log(andGate.value, orGate.value); // false false

value1.value = true;
console.log(andGate.value, orGate.value); // false true

value2.value = true;
console.log(andGate.value, orGate.value); // true true
```