Upgrade Ava to v4

This commit is contained in:
Henry Mercer 2022-02-01 18:01:11 +00:00
parent 9a40cc5274
commit ce89f1b611
1153 changed files with 27264 additions and 95308 deletions

View file

@ -1,12 +1,10 @@
declare namespace mimicFn {
interface Options {
/**
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.
export interface Options {
/**
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.
@default false
*/
readonly ignoreNonConfigurable?: boolean;
}
@default false
*/
readonly ignoreNonConfigurable?: boolean;
}
/**
@ -22,7 +20,7 @@ Modifies the `to` function to mimic the `from` function. Returns the `to` functi
@example
```
import mimicFn = require('mimic-fn');
import mimicFunction from 'mimic-fn';
function foo() {}
foo.unicorn = '🦄';
@ -34,7 +32,7 @@ function wrapper() {
console.log(wrapper.name);
//=> 'wrapper'
mimicFn(wrapper, foo);
mimicFunction(wrapper, foo);
console.log(wrapper.name);
//=> 'foo'
@ -43,14 +41,12 @@ console.log(wrapper.unicorn);
//=> '🦄'
```
*/
declare function mimicFn<
export default function mimicFunction<
ArgumentsType extends unknown[],
ReturnType,
FunctionType extends (...arguments: ArgumentsType) => ReturnType
>(
to: (...arguments: ArgumentsType) => ReturnType,
from: FunctionType,
options?: mimicFn.Options,
options?: Options,
): FunctionType;
export = mimicFn;

View file

@ -1,5 +1,3 @@
'use strict';
const copyProperty = (to, from, property, ignoreNonConfigurable) => {
// `Function#length` should reflect the parameters of `to` not `from` since we keep its body.
// `Function#prototype` is non-writable and non-configurable so can never be modified.
@ -23,8 +21,8 @@ const copyProperty = (to, from, property, ignoreNonConfigurable) => {
};
// `Object.defineProperty()` throws if the property exists, is not configurable and either:
// - one its descriptors is changed
// - it is non-writable and its value is changed
// - one its descriptors is changed
// - it is non-writable and its value is changed
const canCopyProperty = function (toDescriptor, fromDescriptor) {
return toDescriptor === undefined || toDescriptor.configurable || (
toDescriptor.writable === fromDescriptor.writable &&
@ -59,7 +57,7 @@ const changeToString = (to, from, name) => {
Object.defineProperty(to, 'toString', {...toStringDescriptor, value: newToString});
};
const mimicFn = (to, from, {ignoreNonConfigurable = false} = {}) => {
export default function mimicFunction(to, from, {ignoreNonConfigurable = false} = {}) {
const {name} = to;
for (const property of Reflect.ownKeys(from)) {
@ -70,6 +68,4 @@ const mimicFn = (to, from, {ignoreNonConfigurable = false} = {}) => {
changeToString(to, from, name);
return to;
};
module.exports = mimicFn;
}

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View file

@ -1,16 +1,19 @@
{
"name": "mimic-fn",
"version": "3.1.0",
"version": "4.0.0",
"description": "Make a function mimic another one",
"license": "MIT",
"repository": "sindresorhus/mimic-fn",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
@ -35,8 +38,8 @@
"change"
],
"devDependencies": {
"ava": "^2.1.0",
"tsd": "^0.7.1",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

View file

@ -1,24 +1,20 @@
<img src="media/logo.svg" alt="mimic-fn" width="400">
<br>
[![Build Status](https://travis-ci.org/sindresorhus/mimic-fn.svg?branch=master)](https://travis-ci.org/sindresorhus/mimic-fn)
> Make a function mimic another one
Useful when you wrap a function in another function and like to preserve the original name and other properties.
## Install
```
$ npm install mimic-fn
```
## Usage
```js
const mimicFn = require('mimic-fn');
import mimicFunction from 'mimic-fn';
function foo() {}
foo.unicorn = '🦄';
@ -30,7 +26,7 @@ function wrapper() {
console.log(wrapper.name);
//=> 'wrapper'
mimicFn(wrapper, foo);
mimicFunction(wrapper, foo);
console.log(wrapper.name);
//=> 'foo'
@ -45,7 +41,7 @@ console.log(String(wrapper));
## API
### mimicFn(to, from, options?)
### mimicFunction(to, from, options?)
Modifies the `to` function to mimic the `from` function. Returns the `to` function.
@ -71,7 +67,7 @@ Type: `object`
##### ignoreNonConfigurable
Type: `boolean`<br>
Type: `boolean`\
Default: `false`
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.
@ -81,7 +77,6 @@ Skip modifying [non-configurable properties](https://developer.mozilla.org/en-US
- [rename-fn](https://github.com/sindresorhus/rename-fn) - Rename a function
- [keep-func-props](https://github.com/ehmicky/keep-func-props) - Wrap a function without changing its name and other properties
---
<div align="center">