0.0.11 • Published 7 years ago

weoptions v0.0.11

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

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

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago