Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

set-function-length

ljharb119.5mMIT1.2.2TypeScript support: included

Set a function's length property

javascript, ecmascript, set, function, length, function.length

readme

set-function-length Version Badge

github actions coverage License Downloads

npm badge

Set a function’s length.

Arguments:

  • fn: the function
  • length: the new length. Must be an integer between 0 and 2**32.
  • loose: Optional. If true, and the length fails to be set, do not throw. Default false.

Returns fn.

Usage

var setFunctionLength = require('set-function-length');
var assert = require('assert');

function zero() {}
function one(_) {}
function two(_, __) {}

assert.equal(zero.length, 0);
assert.equal(one.length, 1);
assert.equal(two.length, 2);

assert.equal(setFunctionLength(zero, 10), zero);
assert.equal(setFunctionLength(one, 11), one);
assert.equal(setFunctionLength(two, 12), two);

assert.equal(zero.length, 10);
assert.equal(one.length, 11);
assert.equal(two.length, 12);

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.2.2 - 2024-03-09

Commits

  • [types] use shared config 027032f
  • [actions] remove redundant finisher; use reusable workflow 1fd4fb1
  • [types] use a handwritten d.ts file instead of emit 01b9761
  • [Deps] update define-data-property, get-intrinsic, has-property-descriptors bee8eaf
  • [Dev Deps] update call-bind, tape 5dae579
  • [Tests] use @arethetypeswrong/cli 7e22425

v1.2.1 - 2024-02-06

Commits

  • [Dev Deps] update call-bind, tape, typescript d9a4601
  • [Deps] update define-data-property, get-intrinsic 38d39ae
  • [Refactor] use es-errors, so things that only need those do not need get-intrinsic b4bfe5a

v1.2.0 - 2024-01-14

Commits

  • [New] add types f6d9088
  • [Fix] ensure env properties are always booleans 0c42f84
  • [Dev Deps] update aud, call-bind, npmignore, tape 2b75f75
  • [Deps] update get-intrinsic, has-property-descriptors 19bf0fc
  • [meta] add sideEffects flag 8bb9b78

v1.1.1 - 2023-10-19

Fixed

  • [Fix] move define-data-property to runtime deps #2

Commits

  • [Dev Deps] update object-inspect; add missing call-bind 5aecf79

v1.1.0 - 2023-10-13

Commits

  • [New] add env entry point 475c87a
  • [Tests] add coverage with nyc 14f0bf8
  • [eslint] fix linting failure fb516f9
  • [Deps] update define-data-property d727e7c

v1.0.1 - 2023-10-12

Commits

  • [Refactor] use get-intrinsic, since it‘s in the dep graph anyways 278a954
  • [meta] add exports 72acfe5

v1.0.0 - 2023-10-12

Commits