deep-clone-fn
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -8,2 +8,2 @@ export interface DeepCloneFunctionOptions { | ||
} | ||
export default function deepCloneFunction<ArgumentsType extends unknown[], ReturnType, FunctionType extends (...args: ArgumentsType) => ReturnType>(fn: FunctionType, { ignoreNonConfigurable }?: DeepCloneFunctionOptions): FunctionType; | ||
export default function deepCloneFunction<F>(fn: F, { ignoreNonConfigurable }?: DeepCloneFunctionOptions): F; |
@@ -61,13 +61,15 @@ /* eslint-disable @typescript-eslint/no-base-to-string */ | ||
export default function deepCloneFunction(fn, { ignoreNonConfigurable = false } = {}) { | ||
const { name } = fn; | ||
const fnToClone = fn; | ||
const { name } = fnToClone; | ||
function clonedFn(...args) { | ||
return fn(...args); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call | ||
return fnToClone(...args); | ||
} | ||
for (const property of Reflect.ownKeys(fn)) { | ||
copyProperty(clonedFn, fn, property, ignoreNonConfigurable); | ||
for (const property of Reflect.ownKeys(fnToClone)) { | ||
copyProperty(clonedFn, fnToClone, property, ignoreNonConfigurable); | ||
} | ||
changePrototype(clonedFn, fn); | ||
changeToString(clonedFn, fn, name); | ||
changePrototype(clonedFn, fnToClone); | ||
changeToString(clonedFn, fnToClone, name); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
return clonedFn; | ||
} |
{ | ||
"name": "deep-clone-fn", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Deep clone a function.", | ||
@@ -61,3 +61,3 @@ "license": "MIT", | ||
}, | ||
"readme": "# deep-clone-fn\n\nA modification of Sindre Sorhus' excellent [mimic-fn](https://www.npmjs.com/package/mimic-fn) for deep cloning functions.\n\n## Installation\n\n```shell\nnpm install deep-clone-fn\n```\n\n## Usage\n\n```typescript\nimport deepCloneFunction from 'deep-clone-fn';\n\nfunction f(x) {\n return x;\n}\n\nf.myProperty = { foo: 'bar' };\n\nconst g = deepCloneFunction(f);\n\nf.myProperty.foo = 'baz';\n\nconsole.log(g.myProperty); // { foo: 'bar' }\nconsole.log(g('foo')); // foo\n```\n" | ||
"readme": "# deep-clone-fn\n\nA modification of Sindre Sorhus's excellent [mimic-fn](https://www.npmjs.com/package/mimic-fn) for deep cloning functions.\n\n## Installation\n\n```shell\nnpm install deep-clone-fn\n```\n\n## Usage\n\n```typescript\nimport deepCloneFunction from 'deep-clone-fn';\n\nfunction f(x) {\n return x;\n}\n\nf.myProperty = { foo: 'bar' };\n\nconst g = deepCloneFunction(f);\n\nf.myProperty.foo = 'baz';\n\nconsole.log(g.myProperty); // { foo: 'bar' }\nconsole.log(g('foo')); // foo\n```\n" | ||
} |
# deep-clone-fn | ||
A modification of Sindre Sorhus' excellent [mimic-fn](https://www.npmjs.com/package/mimic-fn) for deep cloning functions. | ||
A modification of Sindre Sorhus's excellent [mimic-fn](https://www.npmjs.com/package/mimic-fn) for deep cloning functions. | ||
@@ -5,0 +5,0 @@ ## Installation |
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
6718
85