fc35012d889fde6af5ff4f279f8b20dcc2e5d6c258c27af342921b21c393acef466fe0a8b2faa3ad705fa3e02ad71d2ae032f260ef63318da02e2d9823838b 771 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # defaults
  2. > A simple one level options merge utility
  3. ## Install
  4. ```sh
  5. npm install defaults
  6. ```
  7. ## Usage
  8. ```js
  9. const defaults = require('defaults');
  10. const handle = (options, fn) => {
  11. options = defaults(options, {
  12. timeout: 100
  13. });
  14. setTimeout(() => {
  15. fn(options);
  16. }, options.timeout);
  17. }
  18. handle({timeout: 1000}, () => {
  19. // We're here 1000 ms later
  20. });
  21. handle({timeout: 10000}, () => {
  22. // We're here 10s later
  23. });
  24. ```
  25. ## Summary
  26. 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`
  27. Sidecases: if called with a falsy `options` value, options will be initialized to a new object before being merged onto.