Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
827 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | # defaults
|
---|
| 2 |
|
---|
| 3 | A simple one level options merge utility
|
---|
| 4 |
|
---|
| 5 | ## install
|
---|
| 6 |
|
---|
| 7 | `npm install defaults`
|
---|
| 8 |
|
---|
| 9 | ## use
|
---|
| 10 |
|
---|
| 11 | ```javascript
|
---|
| 12 |
|
---|
| 13 | var defaults = require('defaults');
|
---|
| 14 |
|
---|
| 15 | var handle = function(options, fn) {
|
---|
| 16 | options = defaults(options, {
|
---|
| 17 | timeout: 100
|
---|
| 18 | });
|
---|
| 19 |
|
---|
| 20 | setTimeout(function() {
|
---|
| 21 | fn(options);
|
---|
| 22 | }, options.timeout);
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | handle({ timeout: 1000 }, function() {
|
---|
| 26 | // we're here 1000 ms later
|
---|
| 27 | });
|
---|
| 28 |
|
---|
| 29 | handle({ timeout: 10000 }, function() {
|
---|
| 30 | // we're here 10s later
|
---|
| 31 | });
|
---|
| 32 |
|
---|
| 33 | ```
|
---|
| 34 |
|
---|
| 35 | ## summary
|
---|
| 36 |
|
---|
| 37 | this 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 |
|
---|
| 39 | Sidecases: 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.