tis-cli前端项目快速搭建命令行工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
827 B

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