node-buffs
TypeScript icon, indicating that this package has built-in type declarations

0.8.25 • Public • Published

node-buffs

travis-ci codecov Maintainability npm version npm downloads Dependencies license code style: prettier

NPM Package Quality

node useful toolkit. 封装了常用的 nodejs 工具包,如配置加载,加密和字符串转换等。

Getting Started

yarn add node-buffs
const { createConfigLoader } = require('node-buffs');
// or
import { createConfigLoader } from 'node-buffs';

模块

ConfigLoader

一个灵活配置读取器,通过环境变量 ENV 加载对应的 dotenv 文件,也可通过预制的优先级覆盖配置。

  • ENV=undefined -> .env
  • ENV=local -> .env.local
  • ENV=staging -> .env.staging

加载优先级: overwrite options -> process.env -> options(.env) -> optionsLoader -> default

e.g:

  • set required, will throw exceptions at startup when variable cannot found in .env or environments
import { createConfigLoader } from 'node-buffs';

// Load order:
// 1. load from overwrite options
// 2. load from process.env
// 3. load from .env
// 4. load from optionsLoader (json or function)
// 5. load from default

// lv4
export const configLoader = createConfigLoader({
  optionsLoader: { data: 'o.o' },
  requiredVariables: ['SECRET_KEY'],
});

// 具有最高的优先级 lv1
configLoader.setOverwriteOptions({
  highestOrder: '^_^',
});

// lv5
const key = configLoader.loadConfig('SECRET_KEY', 'default-secret');
const configs = configLoader.loadConfigs();

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Readme

Keywords

none

Package Sidebar

Install

npm i node-buffs

Weekly Downloads

5

Version

0.8.25

License

MIT

Unpacked Size

30.2 kB

Total Files

18

Last publish

Collaborators

  • danielwii