root-config

1.0.3 • Public • Published

第一步,新建root-config类

const myConfig = new RootConfig('.myconfigrc',(Joi)=>{
    return joi.object({
      username: Joi.string().min(2).max(30).required(),
      birthyear: Joi.number().integer().min(1900).max(2019)        
    })
})

第一个参数为函数名称。 第二个参数为返回Joi schema对象的函数。 也可以直接提供Joi schema对象。

第二步,保存和读取options

保存到.myconfigrc

    myConfig.saveOptions({
      username: 'test',
      birthyear: 1990
    })

读取.myconfigrc中的数据

    myConfig.loadOptions()

获取.myconfigrc路径

    myConfig.rcPath

建议专门封装一个文件,用于项目中使用,如建立utils/root-config.js


Readme

Keywords

Package Sidebar

Install

npm i root-config

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

8.16 kB

Total Files

5

Last publish

Collaborators

  • wanthering