weoptions

0.0.11 • Public • Published

weoptions Build Status codecov

我想要有个公共 options, 但可以通过不同的ID, just init/get/set

中文 | english

Install

npm install weoptions
yarn add weoptions

Usage

// index.js
let strict = false;
const weoptions = require('weoptions')('id', strict);
 
let options = {
    name: 'yobrave',
    a: {
        b: {
            c: 1,
        },
    },
    // ...
};
 
let w = weoptions(options);
// init
 
w.set('a.b.c', 2); //
// 2
w.set('a.b.e.d', 2); //
// 2
// if strict == false, create e d, set d=2
// if strict == true, create e d throw TypeError
 
w.get();
// options
// or
w.get('a.b.c');
// 2
// other.js
const weoptions = require('weoptions')('id'); // after init
 
w.get();
// options
w.set('a.b.c', 1);
// 1
 
w._setStrict(true);
// change strict with id

API

1. weoptions(id, strict)

id

name: id
Type: string
Desc: the id of your options, just like debug

strict

name: strict
Type: boolean
Default: false
Desc: the strict of your options
⚠️: if true, anything after WEOPTIONS(options) add/remove/new willthrow Error

return

name: return
Type: WEOPTIONS | W
Desc: if id had init, return W , else return WEOPTIONS

- WEOPTIONS(options):W

options

name: options
Type: any
Desc: options init

- W.set(position, value)

position

name: position
Type: string
Desc: options position

value

name: value
Type: any
Desc: options value

use dset API

- W.get(position)

position

name: position
Type: string
Desc: options position

use dlv API

- W._setStrict(bool)

bool

name: bool
Type: boolean
Desc: change strict to bool

License

MIT © chinanf-boy

Readme

Keywords

Package Sidebar

Install

npm i weoptions

Weekly Downloads

1

Version

0.0.11

License

MIT

Unpacked Size

6.64 kB

Total Files

4

Last publish

Collaborators

  • yobrave1995