# @nelts/utils

> utils for nelts

Latest version **1.0.20** (published 2019-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nelts/utils
pnpm add @nelts/utils
yarn add @nelts/utils
bun add @nelts/utils
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.20 |
| Published | 2019-08-21 |
| First published | 2019-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 44.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | cevio |
| Maintainers | evio |
| Keywords | template, nelts |

## Links

- npm: https://www.npmjs.com/package/@nelts/utils
- Repository: https://github.com/nelts/utils
- Homepage: https://github.com/nelts/utils#readme
- Issues: https://github.com/nelts/utils/issues
- npm.io page: https://npm.io/package/@nelts/utils

## Dependencies (6)

- [ajv](https://npm.io/package/ajv.md) ^6.10.2
- [merge](https://npm.io/package/merge.md) ^1.2.1
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.24
- [findup-sync](https://npm.io/package/findup-sync.md) ^4.0.0
- [@types/mime-types](https://npm.io/package/@types/mime-types.md) ^2.1.0
- [@types/findup-sync](https://npm.io/package/@types/findup-sync.md) ^2.0.2

## Recent versions

- 1.0.20 (latest) — 2019-08-21
- 1.0.19 — 2019-08-09
- 1.0.18 — 2019-08-05
- 1.0.17 — 2019-08-04
- 1.0.16 — 2019-08-04
- 1.0.15 — 2019-08-04
- 1.0.14 — 2019-08-04
- 1.0.9 — 2019-08-04
- 1.0.8 — 2019-08-04
- 1.0.7 — 2019-08-02
- 1.0.6 — 2019-08-02
- 1.0.5 — 2019-08-02
- 1.0.4 — 2019-08-02
- 1.0.3 — 2019-08-02
- 1.0.2 — 2019-08-01
- … 2 more at https://npm.io/package/@nelts/utils/versions

## README

# @nelts/utils

utils for nelts

# Usage

```bash
npm i @nelts/utils
```

by ts:

```ts
import * as utils from '@nelts/utils';
```

## utils.LRU

```ts
import { LRU, LRU_OPTIONS, LRU_VALUE } from '@nelts/utils';
const lru = new LRU<string>(1000);
lru.set('abc', 123, { maxAge: 10000 });
lru.get('abc', { maxAge: 10000 });
lru.keys();
```

## utils.IsJson

```ts
import { IsJson } from '@nelts/utils';
IsJson('abc'); // false
IsJson({ a: 1 }); // true
```

## utils.Compose

```ts
import { Context } from '@nelts/netls';
import { Compose, ComposeNextCallback, ComposeMiddleware, ComposedMiddleware } from '@nelts/utils';
const ctx = new Context();
const stacks: ComposeMiddleware<Context>[] = [];
stacks.push(async (ctx: Context, next: ComposeNextCallback) => await next());
stacks.push(async (ctx: Context, next: ComposeNextCallback) => await next());
stacks.push(async (ctx: Context, next: ComposeNextCallback) => await next());
const fnMiddleware = Compose<Context>(stacks);
fnMiddleware(ctx[, fn: ComposeMiddleware]).then(() => {}).catch(e => {});
```

## utils.Require

abc.ts

```ts
export const a = 1;
export default () => {}
```

```ts
import { Require, RequireDefault } from '@nelts/utils';
const { a, default } = Require<{ a: number, default: () => {} }>('abc.ts');
const fn = RequireDefault<() => {}>('abc.ts'); // fn == () => {}
```

## utils.Collect

```ts
import { Collect, COLLECT_OPTIONS, DEFINE_PLUGIN_OPTIONS, PLUGIN_COLLECT_RESULT, NELTS_PACKAGE_JSON_INTERFACE } from '@nelts/utils';
Collect(cwd: string, node_module_path: string, options: COLLECT_OPTIONS): PLUGIN_COLLECT_RESULT;
```

## utils.AjvChecker

```ts
import { AjvChecker } from '@nelts/utils';
AjvChecker({
  type: 'object',
  properties: {
    a: {
      type: 'integer',
      default: 1
    }
  }
}, { a: 2 });
```

## utils.ErrorInject

```ts
import { ErrorInject } from '@nelts/utils';
ErrorInject(stream: Stream, error: (err: Error) => void): Stream;
```

## utils.EventEmitter

```ts
import { EventEmitter } from '@nelts/utils';
const e = new EventEmitter();
e.on('abc', async (c: string) => console.log(c));
e.emit('abc', 'x').then(() => {}).catch(e => {});
```

# License

[MIT](http://opensource.org/licenses/MIT)

Copyright (c) 2019-present, yunjie (Evio) shen

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