版博士V2.0程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <img src="media/logo.svg" alt="mimic-fn" width="400">
  2. <br>
  3. > Make a function mimic another one
  4. Useful when you wrap a function in another function and like to preserve the original name and other properties.
  5. ## Install
  6. ```
  7. $ npm install mimic-fn
  8. ```
  9. ## Usage
  10. ```js
  11. import mimicFunction from 'mimic-fn';
  12. function foo() {}
  13. foo.unicorn = '🦄';
  14. function wrapper() {
  15. return foo();
  16. }
  17. console.log(wrapper.name);
  18. //=> 'wrapper'
  19. mimicFunction(wrapper, foo);
  20. console.log(wrapper.name);
  21. //=> 'foo'
  22. console.log(wrapper.unicorn);
  23. //=> '🦄'
  24. console.log(String(wrapper));
  25. //=> '/* Wrapped with wrapper() */\nfunction foo() {}'
  26. ```
  27. ## API
  28. ### mimicFunction(to, from, options?)
  29. Modifies the `to` function to mimic the `from` function. Returns the `to` function.
  30. `name`, `displayName`, and any other properties of `from` are copied. The `length` property is not copied. Prototype, class, and inherited properties are copied.
  31. `to.toString()` will return the same as `from.toString()` but prepended with a `Wrapped with to()` comment.
  32. #### to
  33. Type: `Function`
  34. Mimicking function.
  35. #### from
  36. Type: `Function`
  37. Function to mimic.
  38. #### options
  39. Type: `object`
  40. ##### ignoreNonConfigurable
  41. Type: `boolean`\
  42. Default: `false`
  43. Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor#Description) instead of throwing an error.
  44. ## Related
  45. - [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function
  46. - [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name and other properties
  47. ---
  48. <div align="center">
  49. <b>
  50. <a href="https://tidelift.com/subscription/pkg/npm-mimic-fn?utm_source=npm-mimic-fn&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  51. </b>
  52. <br>
  53. <sub>
  54. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  55. </sub>
  56. </div>