Ohm-Management - Projektarbeit B-ME
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.

readme.md 998B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # onetime [![Build Status](https://travis-ci.org/sindresorhus/onetime.svg?branch=master)](https://travis-ci.org/sindresorhus/onetime)
  2. > Ensure a function is only called once
  3. When called multiple times it will return the return value from the first call.
  4. *Unlike the module [once](https://github.com/isaacs/once), this one isn't naughty extending `Function.prototype`.*
  5. ## Install
  6. ```
  7. $ npm install --save onetime
  8. ```
  9. ## Usage
  10. ```js
  11. let i = 0;
  12. const foo = onetime(() => i++);
  13. foo(); //=> 0
  14. foo(); //=> 0
  15. foo(); //=> 0
  16. ```
  17. ```js
  18. const foo = onetime(() => {}, {throw: true});
  19. foo();
  20. foo();
  21. //=> Error: Function `foo` can only be called once
  22. ```
  23. ## API
  24. ### onetime(fn, [options])
  25. Returns a function that only calls `fn` once.
  26. #### fn
  27. Type: `Function`
  28. Function that should only be called once.
  29. #### options
  30. Type: `Object`
  31. ##### throw
  32. Type: `boolean`<br>
  33. Default: `false`
  34. Throw an error when called more than once.
  35. ## License
  36. MIT © [Sindre Sorhus](https://sindresorhus.com)