keep-func-props
Advanced tools
Comparing version 1.3.2 to 2.0.0
@@ -14,3 +14,3 @@ "use strict";require("core-js/modules/es.array.iterator");var _mimicFn=_interopRequireDefault(require("mimic-fn"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} | ||
if(typeof func==="function"&&typeof newFunc==="function"){ | ||
(0,_mimicFn.default)(newFunc,func); | ||
(0,_mimicFn.default)(newFunc,func,{ignoreNonConfigurable:true}); | ||
} | ||
@@ -17,0 +17,0 @@ |
@@ -25,3 +25,14 @@ // Demo of the main usage. | ||
// Function `name` and other properties are kept | ||
console.log(getTrue) // `[Function: getTrue]` | ||
console.log(wrapper(getTrue)) // `[Function]` | ||
console.log(betterWrapper(getTrue)) // `[Function: getTrue]` | ||
// Function body is kept when stringified | ||
console.log(String(getTrue)) | ||
// () => true | ||
console.log(String(wrapper(getTrue))) | ||
// (...args) => anyFunction(...args) | ||
console.log(String(betterWrapper(getTrue))) | ||
// /* Wrapped */ | ||
// () => true |
{ | ||
"name": "keep-func-props", | ||
"version": "1.3.2", | ||
"version": "2.0.0", | ||
"main": "build/src/main.js", | ||
@@ -18,3 +18,3 @@ "files": [ | ||
}, | ||
"description": "Wrap a function without changing its name, length and other properties", | ||
"description": "Wrap a function without changing its name and other properties", | ||
"keywords": [ | ||
@@ -43,10 +43,10 @@ "function", | ||
"dependencies": { | ||
"core-js": "^3.0.1", | ||
"mimic-fn": "^2.1.0" | ||
"core-js": "^3.1.3", | ||
"mimic-fn": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.4.1", | ||
"ava": "^2.1.0", | ||
"gulp": "^4.0.2", | ||
"gulp-shared-tasks": "^0.27.68", | ||
"husky": "^2.3.0", | ||
"gulp-shared-tasks": "^0.29.18", | ||
"husky": "^2.4.1", | ||
"sinon": "^7.3.2" | ||
@@ -53,0 +53,0 @@ }, |
@@ -0,1 +1,3 @@ | ||
<img src="https://raw.githubusercontent.com/ehmicky/design/master/keep-func-props/keep-func-props.svg?sanitize=true" width="700"/> | ||
[![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) | ||
@@ -8,8 +10,10 @@ [![Travis](https://img.shields.io/badge/cross-platform-4cc61e.svg?logo=travis)](https://travis-ci.org/ehmicky/keep-func-props) | ||
Wrap a function without changing its name, length and other properties. | ||
Wrap a function without changing its name 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. | ||
`name` and other properties are usually lost. This module enhances them to keep | ||
those properties instead. | ||
The new function will print the original function's body when stringified. | ||
Function wrappers are commonly used in functional programming. They take a | ||
@@ -31,4 +35,20 @@ function as input and return it wrapped. Examples include | ||
// Function `name` and other properties are kept | ||
console.log(anyFunction) // `[Function: anyFunction]` | ||
console.log(memoize(anyFunction)) // `[Function: memoized]` | ||
console.log(betterMemoize(anyFunction)) // `[Function: anyFunction]` | ||
// Function body is kept when stringified | ||
console.log(String(anyFunction)) | ||
// () => true | ||
console.log(String(memoize(anyFunction))) | ||
// function() { | ||
// var args = arguments, | ||
// key = resolver ? resolver.apply(this, args) : args[0], | ||
// cache = memoized.cache; | ||
// ... | ||
// } | ||
console.log(String(betterMemoize(anyFunction))) | ||
// /* Wrapped with memoized() */ | ||
// () => true | ||
``` | ||
@@ -35,0 +55,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
21957
64
123
+ Addedmimic-fn@3.1.0(transitive)
- Removedmimic-fn@2.1.0(transitive)
Updatedcore-js@^3.1.3
Updatedmimic-fn@^3.0.0