open-index/open-npm huggingface dataset:
npm package: @lvchengbin/base-convert
Description: Convert string in any base.
Author: LvChengbin
Latest version: 0.0.4

# @lvchengbin/base-convert

Convert string in any base.

## Installation

```sh
$ npm i --save @lvchengbin/base-convert
```

## Usage

```js
const convert = require( '@lvchengbin/base-convert' );
convert( 15, 10, 16 ); // f

convert( '8492340923842348230482304823', 10, 62 ) ); // b2LE4AbMjns5UHxZ
convert( 'b2LE4AbMjns5UHxZ', 62, 10 ) ); // 8492340923842348230482304823

convert.bin2hex( '1010' ); // equal to convert( '1010', 2, 16 )
```

Using as ES6 module.

```js
import convert from '@lvchengbin/base-convert';
convert( '8492340923842348230482304823', 10, 62 ) ); // b2LE4AbMjns5UHxZ
```

In web browsers, you can use [base-convert.js](https://raw.githubusercontent.com/LvChengbin/base-convert/master/dist/base-convert.js), and [base-convert.bc.js](https://raw.githubusercontent.com/LvChengbin/base-convert/master/dist/base-convert.bc.js) for browsers doesn't support ES6 syntax.

## API

**Caveat** the frist argument will be convert to string before converting to other base, this will cause that a number, such as 11001101, will be treated as a `binary` instead of a `decimalism` if the `fromBase` is set to `2`. To set the `fromBase` to `10` if you want to use 11001101 as a decimalism.

### convert( string, fromBase, toBase, characters );

```js
convert( 5, 10, 3 );
convert( 12, 3, 10 );
convert( '@^$%^', 10, 16, '!@#$%^&*()_+|-=`~' );
```

### convert.bin2dec( string );

```js
convert.bin2dec( '101011' ); // 43
convert.bin2dec( 10110101 ); // 181
```

### convert.dec2bin( string );

```js
convert.dec2bin( 43 ); // 101011
convert.dec2bin( 181 ); // 10110101
```

### convert.bin2hex( string );

```js
convert.bin2hex( 101011 ); // 2b
convert.bin2hex( 10110101 ); // b5
```

### convert.hex2bin( string );

```js
convert.hex2bin( '2b' ); // 101011
convert.hex2bin( 'b5' ); // 10110101
```

### convert.dec2hex( string );

```js
convert.dec2hex( 43 ); // 2b
convert.dec2hex( 181 ); // b5
```

### convert.hex2dec( string );

```js
convert.hex2dec( '2b' ); // 43
convert.hex2dec( 'b5' ); // 181
```
npm package: @lvchengbin/biu
Description: A library for network requesting using [LocalCache](https://github.com/LvChengbin/localcache) for browsers.
Author: LvChengbin
Latest version: 0.1.8

# Biu

A library for network requesting using [LocalCache](https://github.com/LvChengbin/localcache) for browsers.

## Start

To install the package with npm:

```js
$ npm i @lvchengbin/biu
```

Using the package in nodejs:

```js
const biu = require( '@lvchengbin/biu' );
```

For ES6 module:

```js
import biu from '@lvchengbin/biu';
```

## Usage

### biu.get

```js
biu.get( url, {
    fullResponse : true, // default false
    params : {
        x : 1,
        y : 2
    },
} ).then( response => {

} );
```
### biu.post

biu.get( url, {
    rawBody : true, // default false
    params : {
        x : 1,
        y : 2
    },
} ).then( response => {

} );

### biu.request

### biu.jsonp

### biu.ajax
npm package: @lvchengbin/cli-table
Description: Simply to render `Object`s or `Array`s as tables on the command line in node.js scripts.
Author: LvChengbin
Latest version: 0.0.1

# cli-table

Simply to render `Object`s or `Array`s as tables on the command line in node.js scripts.

## Installation

```bash
$ npm i @lvchengbin/cli-table --save
```

## Usage

If an `Object` is passed to the constructor, the table will be rendered as a `key=>value` map with the keys in the first column and the values in the second column.

```js
const random = require( 'random-world' );
const Table = require( '@lvchengbin/cli-table' );

const obj = {};

for( let i = 0; i < 10; i += 1 ) {
    obj[ random.fullname() ] = random.city();
}

const table = new Table( obj ); 

console.log( table.inspect() );
```
<img src="https://raw.githubusercontent.com/LvChengbin/cli-table/master/screenshots/map.jpg" width="500" />

To render an `Array` as table:

```js
const random = require( 'random-world' );
const Table = require( '@lvchengbin/cli-table' );

const table = new Table( [
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() )
] );

table.setHeader( [ 'Header1', 'Header2', 'Header3', 'Header4' ] );

console.log( table.inspect() );
```

<img src="https://raw.githubusercontent.com/LvChengbin/cli-table/master/screenshots/table.jpg" width="500" />

To set styles for table cells or table header:

```js
const random = require( 'random-world' );
const Table = require( '@lvchengbin/cli-table' );

const table = new Table( [
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() ),
    Array( 4 ).fill( '' ).map( () => random.city() )
], {
    style : {
        header : {
            color : 'red'
        },
        cell : {
            color : 'green'
        },
        border : {
            color : 'yellow'
        }
    }
} );

table.rows[ 3 ].cells[ 2 ].style = {
    bg : 'white',
    color : 'red',
    underline : true
};

table.setHeader( [ 'Header1', 'Header2', 'Header3', 'Header4' ] );

console.log( table.inspect() );
```

<img src="https://raw.githubusercontent.com/LvChengbin/cli-table/master/screenshots/style.png" width="500" />
npm package: @lvchengbin/config
Description: A simple library for creating and managing config object.
Author: LvChengbin
Latest version: 0.0.2

# Config

A simple library for creating and managing config object.

## Start

To install the package with `npm`.

```js
$ npm i @lvchengbin/config --save
```

To use the package in nodejs:

```js
const Config = require( '@lvchengbin/config' );
```

Or using the package as an ES6 module:

```js
import Config from '@lvchengbin/config';
```

## Usage

To create a config object by default config value;

```js
import Config from '@lvchengbin/config';

const config = new Config( {
    baseUrl : 'js/lib',
    paths : {
        app : '../app'
    }
} );

config.set( 'baseUrl', 'js/base' ); // set new value for baseUrl
config.set( 'paths.app', '../../app' ); // set new value for paths.app

// replace the whole config object
config.set( {
    baseUrl : 'js',
    paths : {
        lib : '../lib'
    }
} );

config.get(); // to get the whole config object

config.get( 'baseUrl' ); // get the value of baseUrl

config.get( 'paths.app' ); // get the value of paths.app
```
npm package: @lvchengbin/escape
Description: A simple library for escaping specical characters in strings for HTML, CSS, RegExp, String, URL.
Author: LvChengbin
Latest version: 0.0.3

# escape

A simple library for escaping specical characters in strings for HTML, CSS, RegExp, String, URL.

## Start

Installing the package with `npm`.

```js
$ npm i @lvchengbin/escape --save
```

To use the package in nodejs code.

```js
const escape = require( '@lvchengbin/escape' );
```

If you want to use the package as a ES6 module, you can import it like this:

```js
import escape from '@lvchengbin/escape';
```

Sometimes, maybe you don't want to pack all the code in the library into your project with some bundle toolkits such as rollup, you can import the function that you want to import separately.

```js
import escapeHTML from '@lvchengbin/escape/src/html';
import escapeCSS from '@lvchengbin/escape/src/css';
import escapeRegExp from '@lvchengbin/escape/src/regexp';
import escapeString from '@lvchengbin/escape/src/string';
import escapeURL from '@lvchengbin/escape/src/url';
```

We also provide files for using in browsers with `<script>` tag, you can get it here [escape.js](https://raw.githubusercontent.com/LvChengbin/escape/master/dist/escape.js), and if you want to use it in browsers not supporting ES5 syntax, please use [escape.bc.js](https://raw.githubusercontent.com/LvChengbin/escape/master/dist/escape.bc.js).

```html
<script src="https://raw.githubusercontent.com/LvChengbin/escape/master/dist/escape.js"></script>
```

```html
<script src="https://raw.githubusercontent.com/LvChengbin/escape/master/dist/escape.bc.js"></script>
```

## Usage

```js
import escape from '@lvchengbin/escape';

// escape html special chars
escape.html( '<p>content</p>' );

// escape css special chars
// https://drafts.csswg.org/cssom/#common-serializing-idioms
escape.css( '@#.abc' );

// escape regex special chars
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
escape.regexp( '[abc]' );

// escape special chars in string
escape.string( '"\n\r\'' );

// escape URL
escape.url( 'http://xxx.xxx' );
```
npm package: @lvchengbin/eslint-plugin-tiring
Description: An ESLint plugin for checking more.
Author: LvChengbin
Latest version: 0.0.2

# eslint-plugin-tiring

An ESLint plugin for checking more.

## Installation

You'll first need to install [ESLint](http://eslint.org):

```
$ npm i eslint --save-dev
```

Next, install `eslint-plugin-tiring`:

```
$ npm install eslint-plugin-tiring --save-dev
```


## Usage

Add `tiring` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
    "plugins": [
        "tiring"
    ]
}
```


Then configure the rules you want to use under the rules section.

```json
{
    "rules": {
        "tiring/rule-name": 2
    }
}
```

## Supported Rules

* Fill in provided rules here
npm package: @lvchengbin/event-emitter
Description: An event emitter for both browsers and nodejs
Author: LvChengbin
Latest version: 2.0.0

# EventEmitter

An implementation of EventEmitter for browsers which can use an Object as the event type.

## Installation

```js
$ npm i @lvchengbin/event-emitter --save
```

If you want to invoke the code to browers with `<script>` tag, please use [event-emitter.js](https://github.com/LvChengbin/event-emitter/raw/master/dist/event-emitter.js). For old browsers not support ES5 syntax, please use [event-emitter.bc.js](https://raw.githubusercontent.com/LvChengbin/event-emitter/master/dist/event-emitter.bc.js).

## Usage

```js
import EventEmitter from '@lvchengbin/event-emitter';

const em = new EventEmitter();

const handler = () => {
    // some code...
};

em.on( 'event', handler );
em.emit( 'event', ...args );
em.removeListener( 'event', handler );
```

```js
import EventEmitter from '@lvchengbin/event-emitter';

class A extends EventEmitter {
    constructor() {
        super();

        this.on( 'xxx', () => {
            // some code...
        } );
    }
}

new A().on( 'msg', () => {
} );
```

Using an `Object` as the event type.

```js
const em = new EventEmitter();

const func = {};

em.on( func, () => {
} );
```

## Methods

 - **on( evt, handler )**

    Start to listen to an event type.


 - **once( evt, handler )**

    Start to listen to an event type only once, then the listener will be removed.

 - **removeListener( evt, handler )**

    Remove lister of an event type to stop listening it.

 - **emit( evt, ...args )**
    
    To trigger an event

 - **removeAllListeners( [ evt ] )**
npm package: @lvchengbin/is
Description: Do checking...
Author: LvChengbin
Latest version: 1.0.7

# Is

Checking...

## Installing

```js
npm i @lvchengbin/is --save
```

## Methods

| Method | Desc |
| :----- | :--- |
| is.arguments | |
| is.array | |
| is.arrayBuffer | |
| is.arrayBufferView | |
| is.arrowFunction ||
| is.asyncFunction ||
| is.between ||
| is.blob ||
| is.boolean ||
| is.class ||
| is.darkMode ||
| is.dataview ||
| is.date ||
| is.elementNode ||
| is.email ||
| is.empty || 
| is.error ||
| is.formdata ||
| is.fragmentNode ||
| is.function ||
| is.generalizedFalse ||
| is.generalizedTrue ||
| is.generator ||
| is.integer ||
| is.ip ||
| is.ipv4 ||
| is.ipv6 ||
| is.iterable ||
| is.leapYear ||
| is.map ||
| is.node ||
| is.number ||
| is.object ||
| is.oneDimensionalArray ||
| is.plainObject ||
| is.privateIPv4 ||
| is.promise ||
| is.regexp ||
| is.set ||
| is.string ||
| is.textNode ||
| is.undefined ||
| is.url ||
| is.window ||
```js
yarn add @lvchengbin/is
```

## Usage

```js
const is = require( '@lvchengbin/is' );

is.function( async () => {} );
is.array( [] );
```
npm package: @lvchengbin/koa-basic-auth
Description: More flexible koa http basic auth middleware
Latest version: 0.0.4

# koa-basic-auth

A middleware for koa to add http basic authentication.

## Installation

```js
$ npm i @lvchengbin/koa-basic-auth --save
```

## Usage

```js
const Koa = require( 'koa' );
const auth = require( '@lvchengbin/koa-basic-auth' );

const app = new Koa();

// throw 401 if authentication failed
app.use( auth( 'username', 'password' ) );

app.listen( 3000 );
```

To use with a callback function:

```js
app.use( auth( 'username', 'password', ( result, ctx, next ) => {
    if( !result ) {
        ctx.body = 'Unauthorized';
    } else {
        next();
    }
} );

app.use( async ctx => {
    ctx.body = 'yep';
} );
```

To use the function as a ordinary function:

```js
const Koa = require( 'koa' );
const Router = require( '@lvchengbin/koa-router' );
const auth = require( '@lvchengbin/koa-basic-auth' );

const app = new Koa();
const router = new Router( app );

router.get( '/', async ctx => {
    if( auth( 'username', 'password', ctx ) ) {
        ctx.body = 'yes';
    } else {
        ctx.body = 'no';
    }
} );

app.listen( 3000 );
```
npm package: @lvchengbin/koa-router
Description: Koa router middleware
Author: LvChengbin
Latest version: 0.1.1

# koa-router

A simple routing middleware for koa which can match path string, and queries.

## Installation

```js
$ npm i @lvchengbin/koa-router --save
```
## Usage

A simple example:

```js
const Koa = require( 'koa' );
const Router = require( '@lvchengbin/koa-router' );

const app = new Koa();
const router = new Router( app );

router.get( '/user', async ctx => {
    ctx.body = 'User';
} );

router.get( '/user/:id', async ( ctx, next, id ) => {
    ctx.body = 'User: ' + id;
} );

router.post( '/add', async ctx => {
    ctx.body = 'Add data';
} );

app.listen( 3000 );
```

You can also use `RegExp` for the router:

```js
const Koa = require( 'koa' );
const Router = require( '@lvchengbin/koa-router' );

const app = new Koa();
const router = new Router( app );

router.get( /^\/user\/(\d+)/, async ( ctx, next, id ) => {
    ctx.body = id;
} );

app.listen( 3000 );
```

You can also try matching queries in query string:

```js
const Koa = require( 'koa' );
const Router = require( '@lvchengbin/koa-router' );

const app = new Koa();
const router = new Router( app );

// match all requests with a query responseType and it's value should be jsonp
router.get( { responseType : 'jsonp' } , async ( ctx, next ) => {
    ctx.body = id;
} );

// match all id start with 1
router.get( { id : /^1(\d+)/ }, async ctx => {
} );

app.listen( 3000 );
```

If you want to add a route for multiple types of methods, you can use `router.any` method, for example:

```js
const app = new Koa();
const router = new Router( app );

router.any( [ 'get', 'post' ], '/api', async ctx => {
    ctx.body = 'Method: ' + ctx.method;
} );
```

Using asterisk (*) as the first argument of `router.any` would match all methods:

```js
router.any( '*', '/api', async ctx => {
    ctx.body = 'This would be execute with all methods';
} );
```

Multiple `path`s can be set as an `Array` or a `Generator` in one rule:

```js
// using an array
router.get( [ '/path/a', '/path/b' ], async ( ctx, next ) => {
} );

// using a generator
router.get( function*() {
    yield '/path/a';
    yield '/path/b';
}, async ( ctx, next ) => {
} );
```

In default situation, if you pass the instance of `Koa` to the constructor of `koa-router`, `app.use` would be called automatically. Therefore, if you don't want to execute `app.use` automatically, you don't need to pass the `Koa` instance to the constructor of `koa-router`. Then, you can also call `app.use` later.

```js
const app = new Koa();
const router = new Router();

app.use( router.get( '/user', async ctx => {
    ctx.body = 'User';
} ) );
```

To execute multiple middlewares with a routing rule.

```js
const app = new Koa();
const router = new Router( app );

router.get( '/', [
    ( ctx, next ) => {
        next();
    },
    ctx => {
        ctx.body = 'Hello world!';
    }
] );
```

Route paths would be parsed by [path-to-regexp](https://github.com/pillarjs/path-to-regexp);
npm package: @lvchengbin/map
Description: An implementation of Map in JavaScript for browsers.
Author: LvChengbin
Latest version: 0.0.13

# Map
An implementation of Map in JavaScript for browsers. Supporting methods of Map in ES6.

## Usage

```js
$ npm i @lvchengbin/map --save
```

```js
import Map from '@lvchengbin/map';
const map = new Map( [ [ 'x', 1 ], [ 'y', 2 ] ] );
map.set( {}, 3 );
```
The native `Map` will be used if the client supports native `Map` and if the second argument of `Map` constructor is not false.

If you want to use the library in browsers that loading with `<SCRIPT>` tag, you can git it from [map.js](https://raw.githubusercontent.com/LvChengbin/map/master/dist/map.js), and for browsers do not support ES6, please use [map.bc.js](https://raw.githubusercontent.com/LvChengbin/map/master/dist/map.bc.js).

```html
<script src="./map.bc.js"></script>
<script>
var map = new Map( [ [ 'x', 1 ], [ 'y', 2 ] ] );
console.log( map.size );
</script>
```
npm package: @lvchengbin/promise
Description: Promise/A+ implementation for browsers.
Author: LvChengbin
Latest version: 1.1.7

# Promise

Promise implementation conforming the [Promises/A+](https://promisesaplus.com/) for browsers.

## Installation

```js
$ npm i @lvchengbin/promise --save
```

## Usage

### NodeJS

```js
const Promise = require( '@lvchengbin/promise' );
```

### ES6

```js
import Promise from '@lvchengbin/promise';
```

### Using in Browsers

If you want to invoke the JavaScript file to browser directly, you can use [promise.js](https://raw.githubusercontent.com/LvChengbin/promise/master/dist/promise.js). For old browsers which are not support ES5, you should use [promise.bc.js](https://raw.githubusercontent.com/LvChengbin/promise/master/dist/promise.bc.js).

```html
<script src="./promise.bc.js"></script> 
<script>
    new Promise( function( resolve ) {
        setTimeout( function() {
            resolve( 100 );
        }, 1000 );
    } ).then( function( value ) {
        console.log( value );
    } );
</script>
```
npm package: @lvchengbin/set
Description: An implemention of Set in Javascript for browsers.
Author: LvChengbin
Latest version: 0.0.2

# Set
An implementation of Set in JavaScript for browsers, supporting methods of Set in ES6.

## Usage

```js
$ npm i @lvchengbin/set --save
```

```js
import Set from '@lvchengbin/set';
const set = new Set( [ 'a', 'b', '1', '2', 1, 2 ] );
set.set( 3 );
```

The `Set` constructor has two argument, the first argument should be an `Array` and the second one should be a `Boolean` and be used to denote if to use the native `Set` or not if the client supports the native `Set` class, using `true` by default.

If you want to use the library in browsers that loading with `<SCRIPT>` tag, you can git it from [set.js](https://raw.githubusercontent.com/LvChengbin/set/master/dist/set.js), and for browsers do not support ES6, please use [set.bc.js](https://raw.githubusercontent.com/LvChengbin/set/master/dist/set.bc.js).

```html
<script src="./set.bc.js"></script>
<script>
var set = new Set( [ [ 'x', 1 ], [ 'y', 2 ] ] );
console.log( set.size );
</script>
```
npm package: @lvchengbin/sleep
Description: Sleep function for javascript.
Author: LvChengbin
Latest version: 0.0.2

# Sleep

A sleep function for javascript.

## Start

```js
$ npm i @lvchengbin/sleep --save
```

To use it in nodejs:

```js
const sleep = reuqire( '@lvchengbin/sleep' );
```

Or to import it as an ES6 module:

```js
import sleep = require( '@lvchengbin/sleep' );
```

## Usage

```js
async () => {
    await sleep( 1000 ); // sleep for 1 second
}

sleep( 1000 ).then( () => {
    // execute after 1 second
} );
```
npm package: @lvchengbin/url
Description: Polyfill of URL and URLSearchParams for browsers.
Author: LvChengbin
Latest version: 0.3.0

# URL

Polyfill for URL and URLSearchParams. Totally following the implementation of Google Chrome.

## Installation

```js
$ npm i @lvchengbin/url --save
```

## Usage

```js
const { URL, URLSearchParams } = require( '@lvchengbin/url' );
```

### ES6

```js
import { URL, URLSearchParams } from '@lvchengbin/url';
```

### Loading with `<SCRIPT>` tag

If you want to use this library in browsers and to load it with `<SCRIPT>` tag, you should use [url.js](https://raw.githubusercontent.com/LvChengbin/url/master/dist/url.js), and if you want to use the library in browsers which do not support ES6 syntax, you should use [url.bc.js](https://raw.githubusercontent.com/LvChengbin/url/master/dist/url.bc.js) instead.

```html
<script src="./url.bc.js"></script>
<script>
    var url = new JURL.URL( 'http://www.google.com/path?x=1&y=2' );        
    var params = new JURL.URLSearchParams( 'x=1&y=2' );
    console.log( 'url', url );
    console.log( 'params', params );
</script>
```
npm package: @lvchengbin/url-join
Description: oin multiple parts of URLs by removing useless slashes and other characters.
Author: LvChengbin
Latest version: 0.0.2

# url-join

Join all arguments together and mormalize the resulting URL.

## Installation

```sh
$ npm install --save @lvchengbin/url-join
```
## Usage

```js
const urlJoin = require( '@lvchengbin/url-join' );
const url = urlJoin( 'http://www.google.com', 'a', '/b/cd', '?foo=123', 'foo2=456', '#hash' );

console.log( url ); // Prints http://www.google.com/a/b/cd?foo=123&foo2=456#hash
```

### Special Features

 - Protocol-relative URL

     If the first argument starts with double slashes (//), the URL will be mormalized as a protocol-relative URL.

     ```js
     urlJoin( '//www.google.com', '/a/b' ); // //www.google.com/a/b
     ```

 - Removing trailing "&" automatically

     If there are useless "&" marks in arguments, they will be removed automatically

     ```js
     urlJoin( '/foo?x=1', '&y=2&', ); // /foo?x=1&y=2
     ```

 - Removing trailing "?" automatically

     If there isn't any search queries, the trailing "?" will be removed automatically, even thought it is passed explicitly.

     ```js
     urlJoin( '/foo/?' ); // /foo/
     ```

 - Inserting "&" automatically

     An "&" will be used to connect each part after a "?" appears in one arguments, until a "#" sign appears.

     ```js
     urlJoin( '?', 'x=1', 'y=2&z=3', 'a=4' ); // ?x=1&y=2&z=3&z=4
     ```