pax_global_header00006660000000000000000000000064145143307550014521gustar00rootroot0000000000000052 comment=667210f7dadd064646ae4cf9810939160d96640a set-function-length-1.1.1/000077500000000000000000000000001451433075500154165ustar00rootroot00000000000000set-function-length-1.1.1/.eslintrc000066400000000000000000000006241451433075500172440ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "id-length": "off", "new-cap": ["error", { "capIsNewExceptions": [ "GetIntrinsic" ], }], "no-extra-parens": "off", }, "overrides": [ { "files": ["test/**/*.js"], "rules": { "id-length": "off", "max-lines-per-function": "off", "multiline-comment-style": "off", "no-empty-function": "off", }, }, ], } set-function-length-1.1.1/.github/000077500000000000000000000000001451433075500167565ustar00rootroot00000000000000set-function-length-1.1.1/.github/FUNDING.yml000066400000000000000000000010631451433075500205730ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/set-function-name community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with a single custom sponsorship URL set-function-length-1.1.1/.github/workflows/000077500000000000000000000000001451433075500210135ustar00rootroot00000000000000set-function-length-1.1.1/.github/workflows/node-aught.yml000066400000000000000000000005551451433075500235760ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '< 10' type: minors command: npm run tests-only node: name: 'node < 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' set-function-length-1.1.1/.github/workflows/node-pretest.yml000066400000000000000000000002451451433075500241500ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main set-function-length-1.1.1/.github/workflows/node-tens.yml000066400000000000000000000005601451433075500234330ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only node: name: 'node >= 10' needs: [tests] runs-on: ubuntu-latest steps: - run: 'echo tests completed' set-function-length-1.1.1/.github/workflows/rebase.yml000066400000000000000000000007001451433075500227740ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] permissions: contents: read jobs: _: permissions: contents: write # for ljharb/rebase to push code to rebase pull-requests: read # for ljharb/rebase to get info about PR name: "Automatic Rebase" runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: ljharb/rebase@master env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} set-function-length-1.1.1/.github/workflows/require-allow-edits.yml000066400000000000000000000005151451433075500254350ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] permissions: contents: read jobs: _: permissions: pull-requests: read # for ljharb/require-allow-edits to check 'allow edits' on PR name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main set-function-length-1.1.1/.gitignore000066400000000000000000000032741451433075500174140ustar00rootroot00000000000000# Logs logs *.log npm-debug.log* yarn-debug.log* yarn-error.log* lerna-debug.log* # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # Runtime data pids *.pid *.seed *.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov # Coverage directory used by tools like istanbul coverage *.lcov # nyc test coverage .nyc_output # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) bower_components # node-waf configuration .lock-wscript # Compiled binary addons (https://nodejs.org/api/addons.html) build/Release # Dependency directories node_modules/ jspm_packages/ # TypeScript v1 declaration files typings/ # TypeScript cache *.tsbuildinfo # Optional npm cache directory .npm # Optional eslint cache .eslintcache # Microbundle cache .rpt2_cache/ .rts2_cache_cjs/ .rts2_cache_es/ .rts2_cache_umd/ # Optional REPL history .node_repl_history # Output of 'npm pack' *.tgz # Yarn Integrity file .yarn-integrity # dotenv environment variables file .env .env.test # parcel-bundler cache (https://parceljs.org/) .cache # Next.js build output .next # Nuxt.js build / generate output .nuxt dist # Gatsby files .cache/ # Comment in the public line in if your project uses Gatsby and *not* Next.js # https://nextjs.org/blog/next-9-1#public-directory-support # public # vuepress build output .vuepress/dist # Serverless directories .serverless/ # FuseBox cache .fusebox/ # DynamoDB Local files .dynamodb/ # TernJS port file .tern-port # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore *.d.ts *.d.ts.map set-function-length-1.1.1/.npmrc000066400000000000000000000000671451433075500165410ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s set-function-length-1.1.1/.nycrc000066400000000000000000000003301451433075500165310ustar00rootroot00000000000000{ "all": true, "check-coverage": false, "reporter": ["text-summary", "text", "html", "json"], "lines": 86, "statements": 85.93, "functions": 82.43, "branches": 76.06, "exclude": [ "coverage", "test" ] } set-function-length-1.1.1/CHANGELOG.md000066400000000000000000000044171451433075500172350ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v1.1.1](https://github.com/ljharb/set-function-length/compare/v1.1.0...v1.1.1) - 2023-10-19 ### Fixed - [Fix] move `define-data-property` to runtime deps [`#2`](https://github.com/ljharb/set-function-length/issues/2) ### Commits - [Dev Deps] update `object-inspect`; add missing `call-bind` [`5aecf79`](https://github.com/ljharb/set-function-length/commit/5aecf79e7d6400957a5d9bd9ac20d4528908ca18) ## [v1.1.0](https://github.com/ljharb/set-function-length/compare/v1.0.1...v1.1.0) - 2023-10-13 ### Commits - [New] add `env` entry point [`475c87a`](https://github.com/ljharb/set-function-length/commit/475c87aa2f59b700aaed589d980624ec596acdcb) - [Tests] add coverage with `nyc` [`14f0bf8`](https://github.com/ljharb/set-function-length/commit/14f0bf8c145ae60bf14a026420a06bb7be132c36) - [eslint] fix linting failure [`fb516f9`](https://github.com/ljharb/set-function-length/commit/fb516f93c664057138c53559ef63c8622a093335) - [Deps] update `define-data-property` [`d727e7c`](https://github.com/ljharb/set-function-length/commit/d727e7c6c9a40d7bf26797694e500ea68741feea) ## [v1.0.1](https://github.com/ljharb/set-function-length/compare/v1.0.0...v1.0.1) - 2023-10-12 ### Commits - [Refactor] use `get-intrinsic`, since it‘s in the dep graph anyways [`278a954`](https://github.com/ljharb/set-function-length/commit/278a954a06cd849051c569ff7aee56df6798933e) - [meta] add `exports` [`72acfe5`](https://github.com/ljharb/set-function-length/commit/72acfe5a0310071fb205a72caba5ecbab24336a0) ## v1.0.0 - 2023-10-12 ### Commits - Initial implementation, tests, readme [`fce14e1`](https://github.com/ljharb/set-function-length/commit/fce14e17586460e4f294405173be72b6ffdf7e5f) - Initial commit [`ca7ba85`](https://github.com/ljharb/set-function-length/commit/ca7ba857c7c283f9d26e21f14e71cd388f2cb722) - npm init [`6a7e493`](https://github.com/ljharb/set-function-length/commit/6a7e493927736cebcaf5c1a84e69b8e6b7b744d8) - Only apps should have lockfiles [`d2bf6c4`](https://github.com/ljharb/set-function-length/commit/d2bf6c43de8a51b02a0aa53e8d62cb50c4a2b0da) set-function-length-1.1.1/LICENSE000066400000000000000000000020731451433075500164250ustar00rootroot00000000000000MIT License Copyright (c) Jordan Harband and contributors 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. set-function-length-1.1.1/README.md000066400000000000000000000041671451433075500167050ustar00rootroot00000000000000# set-function-length [![Version Badge][npm-version-svg]][package-url] [![github actions][actions-image]][actions-url] [![coverage][codecov-image]][codecov-url] [![License][license-image]][license-url] [![Downloads][downloads-image]][downloads-url] [![npm badge][npm-badge-png]][package-url] 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 ```javascript 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); ``` [package-url]: https://npmjs.org/package/set-function-length [npm-version-svg]: https://versionbadg.es/ljharb/set-function-length.svg [deps-svg]: https://david-dm.org/ljharb/set-function-length.svg [deps-url]: https://david-dm.org/ljharb/set-function-length [dev-deps-svg]: https://david-dm.org/ljharb/set-function-length/dev-status.svg [dev-deps-url]: https://david-dm.org/ljharb/set-function-length#info=devDependencies [npm-badge-png]: https://nodei.co/npm/set-function-length.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/set-function-length.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/set-function-length.svg [downloads-url]: https://npm-stat.com/charts.html?package=set-function-length [codecov-image]: https://codecov.io/gh/ljharb/set-function-length/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/ljharb/set-function-length/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/set-function-length [actions-url]: https://github.com/ljharb/set-function-length/actions set-function-length-1.1.1/env.js000066400000000000000000000013031451433075500165410ustar00rootroot00000000000000'use strict'; var gOPD = require('gopd'); var functionsHaveConfigurableLengths = gOPD && gOPD(function () {}, 'length').configurable; var functionsHaveWritableLengths = gOPD && gOPD(function () {}, 'length').writable; var boundFnsHaveConfigurableLengths = gOPD && gOPD(function () {}.bind(), 'length').configurable; var boundFnsHaveWritableLengths = gOPD && gOPD(function () {}.bind(), 'length').writable; module.exports = { __proto__: null, boundFnsHaveConfigurableLengths: boundFnsHaveConfigurableLengths, boundFnsHaveWritableLengths: boundFnsHaveWritableLengths, functionsHaveConfigurableLengths: functionsHaveConfigurableLengths, functionsHaveWritableLengths: functionsHaveWritableLengths }; set-function-length-1.1.1/index.js000066400000000000000000000022221451433075500170610ustar00rootroot00000000000000'use strict'; var GetIntrinsic = require('get-intrinsic'); var define = require('define-data-property'); var hasDescriptors = require('has-property-descriptors')(); var gOPD = require('gopd'); var $TypeError = GetIntrinsic('%TypeError%'); var $floor = GetIntrinsic('%Math.floor%'); module.exports = function setFunctionLength(fn, length) { if (typeof fn !== 'function') { throw new $TypeError('`fn` is not a function'); } if (typeof length !== 'number' || length < 0 || length > 0xFFFFFFFF || $floor(length) !== length) { throw new $TypeError('`length` must be a positive 32-bit integer'); } var loose = arguments.length > 2 && !!arguments[2]; var functionLengthIsConfigurable = true; var functionLengthIsWritable = true; if ('length' in fn && gOPD) { var desc = gOPD(fn, 'length'); if (desc && !desc.configurable) { functionLengthIsConfigurable = false; } if (desc && !desc.writable) { functionLengthIsWritable = false; } } if (functionLengthIsConfigurable || functionLengthIsWritable || !loose) { if (hasDescriptors) { define(fn, 'length', length, true, true); } else { define(fn, 'length', length); } } return fn; }; set-function-length-1.1.1/package.json000066400000000000000000000041351451433075500177070ustar00rootroot00000000000000{ "name": "set-function-length", "version": "1.1.1", "description": "Set a function's length property", "main": "index.js", "exports": { ".": "./index.js", "./env": "./env.js", "./package.json": "./package.json" }, "directories": { "test": "test" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "prelint": "evalmd README.md", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", "test": "npm run tests-only", "posttest": "aud --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "repository": { "type": "git", "url": "git+https://github.com/ljharb/set-function-length.git" }, "keywords": [ "javascript", "ecmascript", "set", "function", "length", "function.length" ], "author": "Jordan Harband ", "license": "MIT", "bugs": { "url": "https://github.com/ljharb/set-function-length/issues" }, "homepage": "https://github.com/ljharb/set-function-length#readme", "devDependencies": { "@ljharb/eslint-config": "^21.1.0", "aud": "^2.0.3", "auto-changelog": "^2.4.0", "call-bind": "^1.0.4", "es-value-fixtures": "^1.4.2", "eslint": "=8.8.0", "evalmd": "^0.0.19", "for-each": "^0.3.3", "in-publish": "^2.0.1", "npmignore": "^0.3.0", "nyc": "^10.3.2", "object-inspect": "^1.13.1", "safe-publish-latest": "^2.0.0", "tape": "^5.7.1" }, "dependencies": { "define-data-property": "^1.1.1", "get-intrinsic": "^1.2.1", "gopd": "^1.0.1", "has-property-descriptors": "^1.0.0" }, "engines": { "node": ">= 0.4" }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "publishConfig": { "ignore": [ ".github/workflows", "test" ] } } set-function-length-1.1.1/test/000077500000000000000000000000001451433075500163755ustar00rootroot00000000000000set-function-length-1.1.1/test/env.js000066400000000000000000000044571451433075500175350ustar00rootroot00000000000000'use strict'; var test = require('tape'); var gOPD = require('gopd'); var callBind = require('call-bind'); var env = require('../env'); test('functionsHaveConfigurableLengths', function (t) { var fn = function f() {}; t.test('yes', { skip: !env.functionsHaveConfigurableLengths }, function (st) { st.equal(gOPD(fn, 'length').configurable, true, 'function length is configurable'); st.end(); }); t.test('no', { skip: env.functionsHaveConfigurableLengths }, function (st) { st['throws']( function () { if (gOPD && !env.functionsHaveWritableLengths) { Object.defineProperty(fn, 'length', { value: 42 }); } else { delete fn.length; } }, TypeError, 'function length is not configurable' ); st.end(); }); t.end(); }); test('functionsHaveWritableLengths', function (t) { var fn = function f() {}; t.test('yes', { skip: !env.functionsHaveWritableLengths }, function (st) { st.equal(gOPD(fn, 'length').writable, true, 'function length is writable'); st.end(); }); t.test('no', { skip: env.functionsHaveWritableLengths }, function (st) { st['throws']( function () { fn.length = 42; }, TypeError, 'function length is not writable' ); st.end(); }); t.end(); }); test('boundFnsHaveConfigurableLengths', function (t) { var fn = callBind(function f() {}); t.test('yes', { skip: !env.boundFnsHaveConfigurableLengths }, function (st) { st.equal(gOPD(fn, 'length').configurable, true, 'bound function length is configurable'); st.end(); }); t.test('no', { skip: env.boundFnsHaveConfigurableLengths }, function (st) { st['throws']( function () { if (gOPD) { Object.defineProperty(fn, 'length', { value: 42 }); } else { delete fn.length; } }, TypeError, 'bound function length is not configurable' ); st.end(); }); t.end(); }); test('boundFnsHaveWritableLengths', function (t) { var fn = callBind(function f() {}); t.test('yes', { skip: !env.boundFnsHaveWritableLengths }, function (st) { st.equal(gOPD(fn, 'length').writable, true, 'bound function length is writable'); st.end(); }); t.test('no', { skip: env.boundFnsHaveWritableLengths }, function (st) { st['throws']( function () { fn.length = 42; }, TypeError, 'bound function length is not writable' ); st.end(); }); t.end(); }); set-function-length-1.1.1/test/index.js000066400000000000000000000055761451433075500200570ustar00rootroot00000000000000'use strict'; var test = require('tape'); var forEach = require('for-each'); var inspect = require('object-inspect'); var v = require('es-value-fixtures'); var gOPD = require('gopd'); var functionsHaveConfigurableLengths = true; var functionsHaveWritableLengths = true; if (gOPD) { var desc = gOPD(function f() {}, 'length'); if (!desc.configurable) { functionsHaveConfigurableLengths = false; } if (!desc.writable) { functionsHaveWritableLengths = false; } } var setFunctionLength = require('../'); test('set function length', function (t) { forEach(v.nonFunctions, function (nonFunction) { t['throws']( function () { setFunctionLength(nonFunction); }, TypeError, inspect(nonFunction) + ' is not a function' ); }); forEach(v.nonNumbers.concat(v.nonIntegerNumbers, 0xFFFFFFFF + 1), function (nonInteger) { t['throws']( function () { setFunctionLength(nonInteger); }, TypeError, inspect(nonInteger) + ' is not an integer in the proper range' ); }); t.test('setting the length', { skip: !functionsHaveConfigurableLengths && !functionsHaveWritableLengths }, function (st) { forEach([].concat( function zero() {}, function one(_) {}, // eslint-disable-line no-unused-vars function two(_, __) {} // eslint-disable-line no-unused-vars ), function (fn) { var origLength = fn.length; var newLength = (origLength * 2) + 12; var msg = inspect(fn) + ': returns it (' + Function.prototype.toString.call(fn) + ')'; st.equal(setFunctionLength(fn, newLength), fn, msg); st.equal( fn.length, newLength, inspect(fn) + ': sets the name from ' + inspect(origLength) + ' to ' + inspect(newLength) ); }); st.end(); }); t.test('setting the length loosely', function (st) { forEach([].concat( function zero() {}, function one(_) {}, // eslint-disable-line no-unused-vars function two(_, __) {} // eslint-disable-line no-unused-vars ), function (fn) { var origLength = fn.length; var msg = inspect(fn) + ': returns it (' + Function.prototype.toString.call(fn) + ')'; st.equal(setFunctionLength(fn, 42, true), fn, msg); var msg2 = (functionsHaveConfigurableLengths || functionsHaveWritableLengths) ? inspect(fn) + ': loosely changes ' + inspect(origLength) + ' to ' + inspect(42) : inspect(fn) + ': loosely noops and keeps ' + inspect(origLength); st.equal( fn.length, (functionsHaveConfigurableLengths || functionsHaveWritableLengths) ? 42 : origLength, msg2 ); }); st.end(); }); t.test('functions with a deleted length', { skip: !functionsHaveConfigurableLengths }, function (st) { var f = function g(_) {}; // eslint-disable-line no-unused-vars st.equal(f.length, 1, 'initial function length is 1'); delete f.length; st.equal(f.length, 0, 'function with deleted length is 0'); setFunctionLength(f, 42); st.equal(f.length, 42, 'set function length is 42'); st.end(); }); t.end(); });