1 | # set-function-length <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
---|
2 |
|
---|
3 | [![github actions][actions-image]][actions-url]
|
---|
4 | [![coverage][codecov-image]][codecov-url]
|
---|
5 | [![License][license-image]][license-url]
|
---|
6 | [![Downloads][downloads-image]][downloads-url]
|
---|
7 |
|
---|
8 | [![npm badge][npm-badge-png]][package-url]
|
---|
9 |
|
---|
10 | Set a function’s length.
|
---|
11 |
|
---|
12 | Arguments:
|
---|
13 | - `fn`: the function
|
---|
14 | - `length`: the new length. Must be an integer between 0 and 2**32.
|
---|
15 | - `loose`: Optional. If true, and the length fails to be set, do not throw. Default false.
|
---|
16 |
|
---|
17 | Returns `fn`.
|
---|
18 |
|
---|
19 | ## Usage
|
---|
20 |
|
---|
21 | ```javascript
|
---|
22 | var setFunctionLength = require('set-function-length');
|
---|
23 | var assert = require('assert');
|
---|
24 |
|
---|
25 | function zero() {}
|
---|
26 | function one(_) {}
|
---|
27 | function two(_, __) {}
|
---|
28 |
|
---|
29 | assert.equal(zero.length, 0);
|
---|
30 | assert.equal(one.length, 1);
|
---|
31 | assert.equal(two.length, 2);
|
---|
32 |
|
---|
33 | assert.equal(setFunctionLength(zero, 10), zero);
|
---|
34 | assert.equal(setFunctionLength(one, 11), one);
|
---|
35 | assert.equal(setFunctionLength(two, 12), two);
|
---|
36 |
|
---|
37 | assert.equal(zero.length, 10);
|
---|
38 | assert.equal(one.length, 11);
|
---|
39 | assert.equal(two.length, 12);
|
---|
40 | ```
|
---|
41 |
|
---|
42 | [package-url]: https://npmjs.org/package/set-function-length
|
---|
43 | [npm-version-svg]: https://versionbadg.es/ljharb/set-function-length.svg
|
---|
44 | [deps-svg]: https://david-dm.org/ljharb/set-function-length.svg
|
---|
45 | [deps-url]: https://david-dm.org/ljharb/set-function-length
|
---|
46 | [dev-deps-svg]: https://david-dm.org/ljharb/set-function-length/dev-status.svg
|
---|
47 | [dev-deps-url]: https://david-dm.org/ljharb/set-function-length#info=devDependencies
|
---|
48 | [npm-badge-png]: https://nodei.co/npm/set-function-length.png?downloads=true&stars=true
|
---|
49 | [license-image]: https://img.shields.io/npm/l/set-function-length.svg
|
---|
50 | [license-url]: LICENSE
|
---|
51 | [downloads-image]: https://img.shields.io/npm/dm/set-function-length.svg
|
---|
52 | [downloads-url]: https://npm-stat.com/charts.html?package=set-function-length
|
---|
53 | [codecov-image]: https://codecov.io/gh/ljharb/set-function-length/branch/main/graphs/badge.svg
|
---|
54 | [codecov-url]: https://app.codecov.io/gh/ljharb/set-function-length/
|
---|
55 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/set-function-length
|
---|
56 | [actions-url]: https://github.com/ljharb/set-function-length/actions
|
---|