source: trip-planner-front/node_modules/defaults/README.md@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 827 bytes
Line 
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)
Note: See TracBrowser for help on using the repository browser.