@nelts/utils
utils for nelts
Last updated 8 months ago by evio .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @nelts/utils 
SYNC missed versions from official npm registry.

@nelts/utils

utils for nelts

Usage

npm i @nelts/utils

by ts:

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

utils.LRU

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

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

utils.Compose

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

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

utils.Collect

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

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

utils.ErrorInject

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

utils.EventEmitter

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

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

Current Tags

  • 1.0.20                                ...           latest (8 months ago)

17 Versions

  • 1.0.20                                ...           8 months ago
  • 1.0.19                                ...           8 months ago
  • 1.0.18                                ...           8 months ago
  • 1.0.17                                ...           8 months ago
  • 1.0.16                                ...           8 months ago
  • 1.0.15                                ...           8 months ago
  • 1.0.14                                ...           8 months ago
  • 1.0.9                                ...           8 months ago
  • 1.0.8                                ...           8 months ago
  • 1.0.7                                ...           8 months ago
  • 1.0.6                                ...           8 months ago
  • 1.0.5                                ...           8 months ago
  • 1.0.4                                ...           8 months ago
  • 1.0.3                                ...           8 months ago
  • 1.0.2                                ...           8 months ago
  • 1.0.1                                ...           8 months ago
  • 1.0.0                                ...           8 months ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 23
Dependencies (6)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |