Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
.npmignore | D | 12-May-2024 | 13 | 2 | 1 | |
LICENSE | D | 12-May-2024 | 1.1 KiB | 22 | 17 | |
README.md | D | 12-May-2024 | 827 | 44 | 27 | |
index.js | D | 12-May-2024 | 277 | 13 | 10 | |
package.json | D | 12-May-2024 | 1.3 KiB | 58 | 57 | |
test.js | D | 12-May-2024 | 1 KiB | 35 | 28 |
README.md
1# defaults 2 3A simple one level options merge utility 4 5## install 6 7`npm install defaults` 8 9## use 10 11```javascript 12 13var defaults = require('defaults'); 14 15var handle = function(options, fn) { 16 options = defaults(options, { 17 timeout: 100 18 }); 19 20 setTimeout(function() { 21 fn(options); 22 }, options.timeout); 23} 24 25handle({ timeout: 1000 }, function() { 26 // we're here 1000 ms later 27}); 28 29handle({ timeout: 10000 }, function() { 30 // we're here 10s later 31}); 32 33``` 34 35## summary 36 37this module exports a function that takes 2 arguments: `options` and `defaults`. When called, it overrides all of `undefined` properties in `options` with the clones of properties defined in `defaults` 38 39Sidecases: if called with a falsy `options` value, options will be initialized to a new object before being merged onto. 40 41## license 42 43[MIT](LICENSE) 44