keep-func-props
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"name": "keep-func-props", | ||
"version": "1.1.0", | ||
"main": "build/src/index.js", | ||
"version": "1.2.0", | ||
"main": "build/src/main.js", | ||
"files": [ | ||
"build/src" | ||
"build/src", | ||
"examples", | ||
"!~" | ||
], | ||
@@ -13,3 +15,3 @@ "scripts": { | ||
"hooks": { | ||
"pre-push": "gulp check" | ||
"pre-push": "gulp check --full" | ||
} | ||
@@ -41,12 +43,11 @@ }, | ||
"dependencies": { | ||
"@babel/runtime": "^7.3.4", | ||
"core-js": "^2.6.5", | ||
"mimic-fn": "^1.2.0" | ||
"core-js": "^3.0.0", | ||
"mimic-fn": "^2.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.2.1", | ||
"ava": "^1.4.1", | ||
"gulp": "^4.0.0", | ||
"gulp-shared-tasks": "^0.18.1", | ||
"gulp-shared-tasks": "^0.24.3", | ||
"husky": "^1.3.1", | ||
"sinon": "^7.2.6" | ||
"sinon": "^7.3.1" | ||
}, | ||
@@ -53,0 +54,0 @@ "engines": { |
@@ -1,5 +0,14 @@ | ||
[![downloads](https://img.shields.io/npm/dt/keep-func-props.svg?logo=npm)](https://www.npmjs.com/package/keep-func-props) [![last commit](https://img.shields.io/github/last-commit/ehmicky/keep-func-props.svg?logo=github&logoColor=white)](https://github.com/ehmicky/keep-func-props/graphs/contributors) [![Coverage Status](https://img.shields.io/codecov/c/github/ehmicky/keep-func-props.svg?label=test%20coverage&logo=codecov)](https://codecov.io/gh/ehmicky/keep-func-props) [![travis](https://img.shields.io/travis/ehmicky/keep-func-props/master.svg?logo=travis)](https://travis-ci.org/ehmicky/keep-func-props/builds) [![node](https://img.shields.io/node/v/keep-func-props.svg?logo=node.js)](#) [![Gitter](https://img.shields.io/gitter/room/ehmicky/keep-func-props.svg?logo=gitter)](https://gitter.im/ehmicky/keep-func-props) | ||
[![Codecov](https://img.shields.io/codecov/c/github/ehmicky/keep-func-props.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/keep-func-props) | ||
[![Travis](https://img.shields.io/badge/cross-platform-4cc61e.svg?logo=travis)](https://travis-ci.org/ehmicky/keep-func-props) | ||
[![Node](https://img.shields.io/node/v/keep-func-props.svg?logo=node.js)](https://www.npmjs.com/package/keep-func-props) | ||
[![Gitter](https://img.shields.io/gitter/room/ehmicky/keep-func-props.svg?logo=gitter)](https://gitter.im/ehmicky/keep-func-props) | ||
[![Twitter](https://img.shields.io/badge/%E2%80%8B-twitter-4cc61e.svg?logo=twitter)](https://twitter.com/intent/follow?screen_name=ehmicky) | ||
[![Medium](https://img.shields.io/badge/%E2%80%8B-medium-4cc61e.svg?logo=medium)](https://medium.com/@ehmicky) | ||
Wrap a function without changing its name, length and other properties. | ||
Function wrappers return a new function which means the original | ||
function's `name`, `length` and other properties are usually lost. This module | ||
enhances them to keep those properties instead. | ||
Function wrappers are commonly used in functional programming. They take a | ||
@@ -10,5 +19,3 @@ function as input and return it wrapped. Examples include | ||
However those wrappers return a new function which means the original | ||
function's `name`, `length` and other properties are lost. This module | ||
enhances a function wrapper to keep those properties. | ||
# Example | ||
@@ -18,3 +25,4 @@ <!-- eslint-disable import/no-extraneous-dependencies, import/no-internal-modules, node/no-extraneous-require --> | ||
```js | ||
const keepFuncProps = require('keep-func-props') | ||
const { keepFuncProps } = require('keep-func-props') | ||
// Any function wrapper works | ||
const memoize = require('lodash/memoize') | ||
@@ -24,15 +32,17 @@ | ||
const anyFunction = function() { | ||
return true | ||
} | ||
const anyFunction = () => true | ||
// Function name is `memoized` | ||
console.log(memoize(anyFunction)) | ||
// Function name is `anyFunction` | ||
console.log(betterMemoize(anyFunction)) | ||
console.log(memoize(anyFunction)) // `[Function: memoized]` | ||
console.log(betterMemoize(anyFunction)) // `[Function: anyFunction]` | ||
``` | ||
# Installation | ||
# Demo | ||
You can try this library: | ||
- either directly [in your browser](https://repl.it/@ehmicky/keep-func-props). | ||
- or by executing the [`examples` files](examples/README.md) in a terminal. | ||
# Install | ||
```bash | ||
@@ -44,25 +54,57 @@ npm install keep-func-props | ||
<!-- eslint-disable import/no-extraneous-dependencies, node/no-extraneous-require --> | ||
```js | ||
const keepFuncProps = require('keep-func-props') | ||
const { keepFuncProps } = require('keep-func-props') | ||
const functionWrapper = function(func) { | ||
return (...args) => func(...args) | ||
// Any function wrapper works | ||
const wrapper = function(anyFunction) { | ||
return (...args) => anyFunction(...args) | ||
} | ||
// `betterWrapper` is like `functionWrapper` but it keeps the function | ||
// properties | ||
const betterWrapper = keepFuncProps(functionWrapper) | ||
// `betterWrapper` is like `wrapper` but it keeps the function properties | ||
const betterWrapper = keepFuncProps(wrapper) | ||
``` | ||
The function wrapper must: | ||
## keepFuncProps(wrapper) | ||
- take a function as first argument | ||
- take additional arguments (e.g. an options object) | ||
- return a new function | ||
`wrapper`: `(anyFunction, [...args]) => newFunction`<br> | ||
_Returns_: new `wrapper` | ||
Each of those requirements is optional. | ||
A function `wrapper` is passed as argument. A copy of it is returned. | ||
# Related projects | ||
# See also | ||
If you want to modify a function that is not a function wrapper, check out | ||
[`mimic-fn`](https://github.com/sindresorhus/mimic-fn). | ||
- [`mimic-fn`](https://github.com/sindresorhus/mimic-fn): same but for | ||
functions that do not wrap other functions. | ||
# Support | ||
If you found a bug or would like a new feature, _don't hesitate_ to | ||
[submit an issue on GitHub](../../issues). | ||
For other questions, feel free to | ||
[chat with us on Gitter](https://gitter.im/ehmicky/keep-func-props). | ||
Everyone is welcome regardless of personal background. We enforce a | ||
[Code of conduct](CODE_OF_CONDUCT.md) in order to promote a positive and | ||
inclusive environment. | ||
# Contributing | ||
This project was made with ❤️. The simplest way to give back is by starring and | ||
sharing it online. | ||
If the documentation is unclear or has a typo, please click on the page's `Edit` | ||
button (pencil icon) and suggest a correction. | ||
If you would like to help us fix a bug or add a new feature, please check our | ||
[guidelines](CONTRIBUTING.md). Pull requests are welcome! | ||
<!-- Thanks goes to our wonderful contributors: --> | ||
<!-- ALL-CONTRIBUTORS-LIST:START --> | ||
<!-- prettier-ignore --> | ||
<table><tr><td align="center"><a href="https://twitter.com/ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4" width="100px;" alt="ehmicky"/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/keep-func-props/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/keep-func-props/commits?author=ehmicky" title="Documentation">📖</a></td></tr></table> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21000
2
9
55
107
2
+ Addedcore-js@3.39.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
- Removed@babel/runtime@^7.3.4
- Removed@babel/runtime@7.26.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removedmimic-fn@1.2.0(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
Updatedcore-js@^3.0.0
Updatedmimic-fn@^2.1.0