Mòrèn (默认)
Fill default values in object when empty.
Features
- Fill default values in object easily.
- Can use function to create dynamic default value.
- TypeScript declaration included.
Installation
Via npm:
npm i moren
Via Yarn:
yarn add moren
Usage
const moren = ; const defaults = a: 'aaa' b: false objalength + 1; const completeObj = a: 'XXX' b: true c: 0;const incompleteObj = a: 'X' b: true;const emptyObj = {}; const result1 = ;/** * { * a: 'XXX', * b: true, * c: 0 * } */ const result2 = ;/** * { * a: 'X', * b: true, * c: 2 // It's `a.length` (1) + 1 * } */ const result3 = ;/** * { * a: 'aaa', * b: false, * c: 4 // It's `a.length` (3) + 1 * } */
API
moren(obj, defaults)
obj
An object to be filled.
defaults
An object that contains default value or the function that return value.
If you give a function as object's value, moren will pass current obj
into function.
So, you can use given obj
to create and return actual default value back.