pax_global_header00006660000000000000000000000064145003412340014506gustar00rootroot0000000000000052 comment=eebd109730ffb1dff9e22efd3bcff163e87edb00 set-function-name-2.0.1/000077500000000000000000000000001450034123400150425ustar00rootroot00000000000000set-function-name-2.0.1/.eslintrc000066400000000000000000000004001450034123400166600ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "id-length": "off", }, "overrides": [ { "files": ["test/**/*.js"], "rules": { "id-length": "off", "multiline-comment-style": "off", "no-empty-function": "off", }, }, ], } set-function-name-2.0.1/.github/000077500000000000000000000000001450034123400164025ustar00rootroot00000000000000set-function-name-2.0.1/.github/FUNDING.yml000066400000000000000000000010631450034123400202170ustar00rootroot00000000000000# 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-name-2.0.1/.github/workflows/000077500000000000000000000000001450034123400204375ustar00rootroot00000000000000set-function-name-2.0.1/.github/workflows/node-aught.yml000066400000000000000000000005551450034123400232220ustar00rootroot00000000000000name: '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-name-2.0.1/.github/workflows/node-pretest.yml000066400000000000000000000002451450034123400235740ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] permissions: contents: read jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main set-function-name-2.0.1/.github/workflows/node-tens.yml000066400000000000000000000005601450034123400230570ustar00rootroot00000000000000name: '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-name-2.0.1/.github/workflows/rebase.yml000066400000000000000000000007001450034123400224200ustar00rootroot00000000000000name: 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-name-2.0.1/.github/workflows/require-allow-edits.yml000066400000000000000000000005151450034123400250610ustar00rootroot00000000000000name: 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-name-2.0.1/.gitignore000066400000000000000000000032511450034123400170330ustar00rootroot00000000000000# 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 set-function-name-2.0.1/.npmrc000066400000000000000000000000671450034123400161650ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s set-function-name-2.0.1/CHANGELOG.md000066400000000000000000000060401450034123400166530ustar00rootroot00000000000000# 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). ## [v2.0.1](https://github.com/jfsiii/set-function-name/compare/v2.0.0...v2.0.1) - 2023-09-13 ### Commits - [Fix] move `functions-have-names` to runtime deps [`db2eda8`](https://github.com/jfsiii/set-function-name/commit/db2eda8da4c8aecfad01739000bbd63d04a8e8cf) ## [v2.0.0](https://github.com/jfsiii/set-function-name/compare/v1.0.0...v2.0.0) - 2023-09-12 ### Commits - [eslint] add `npm run lint` [`23e1fcd`](https://github.com/jfsiii/set-function-name/commit/23e1fcd85b64b864cb8f7e894da78d540e72923a) - [actions] add reused GHA [`525127e`](https://github.com/jfsiii/set-function-name/commit/525127e08bdb35b0d44f565492456c7d1d5923fc) - [meta] add `.gitignore` [`aa3abdf`](https://github.com/jfsiii/set-function-name/commit/aa3abdfa6af18adf70281352905dd69ef8b2c66f) - [Tests] switch tests to use tape; add posttest [`8ad6d30`](https://github.com/jfsiii/set-function-name/commit/8ad6d30c61f78d2f9beec156ba7f1c4c3741c593) - [readme] add readme [`732c46c`](https://github.com/jfsiii/set-function-name/commit/732c46c05e0fa6843dbc85b3af1e9c9bf22e7bf9) - [New] add optional `loose` argument [`f5e4771`](https://github.com/jfsiii/set-function-name/commit/f5e4771266c95567d87f6dc2cff94c986bc7e074) - [meta] relicense package to MIT; fix repo URLs [`13948f8`](https://github.com/jfsiii/set-function-name/commit/13948f8bb4ec8a25b67332d8de232ad0c0dc4e6d) - [meta] add `auto-changelog` [`7ab201c`](https://github.com/jfsiii/set-function-name/commit/7ab201c0d83d464664cc4588acad0d0f75926679) - [Breaking] throw if a non-function is provided [`cf6fc8f`](https://github.com/jfsiii/set-function-name/commit/cf6fc8f3396d58aa8c32a83375cbf57d933d7e79) - [Breaking] drop UMD, just use CJS [`47abfe8`](https://github.com/jfsiii/set-function-name/commit/47abfe89abfaa72f71e0a77a52a5ff2b7377e11a) - [Refactor] use `define-data-property` and `has-property-descriptors` [`9921c2b`](https://github.com/jfsiii/set-function-name/commit/9921c2b64c571255084aefaa02660314609e8ea0) - [meta] use `npmignore` to autogenerate an npmignore file [`c5dbe4f`](https://github.com/jfsiii/set-function-name/commit/c5dbe4f4c44298596338432e2ac9946a10c98edd) - Only apps should have lockfiles [`98bbfa1`](https://github.com/jfsiii/set-function-name/commit/98bbfa145387f318152a6b792bd69aca3c544813) - [meta] add `safe-publish-latest` [`8916cd8`](https://github.com/jfsiii/set-function-name/commit/8916cd8f5549dceee31f06d35a76e2f9d4933a8b) - [meta] add `engines` [`2427c8e`](https://github.com/jfsiii/set-function-name/commit/2427c8e2499f378c9ff3d92c7d544c771ca810df) ## v1.0.0 - 2017-09-14 ### Commits - Initial commit. Including tests. [`f26a1f2`](https://github.com/jfsiii/set-function-name/commit/f26a1f2c69a70dad5049b1daa08eae5f6acd9a1e) - add .npmignore to ignore test directory [`9cac96f`](https://github.com/jfsiii/set-function-name/commit/9cac96fd9e98f25883be6e727ac32356522a5d69) set-function-name-2.0.1/LICENSE000066400000000000000000000020731450034123400160510ustar00rootroot00000000000000MIT 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-name-2.0.1/README.md000066400000000000000000000045131450034123400163240ustar00rootroot00000000000000# set-function-name [![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 name. Arguments: - `fn`: the function - `name`: the new name - `loose`: Optional. If true, and the name fails to be set, do not throw. Default false. Returns `fn`. ## Usage ```javascript var setFunctionName = require('set-function-name'); var assert = require('assert'); const obj = { concise() {}, arrow: () => {}, named: function named() {}, anon: function () {}, }; assert.equal(obj.concise.name, 'concise'); assert.equal(obj.arrow.name, 'arrow'); assert.equal(obj.named.name, 'named'); assert.equal(obj.anon.name, 'anon'); assert.equal(setFunctionName(obj.concise, 'brief'), obj.concise); assert.equal(setFunctionName(obj.arrow, 'pointy'), obj.arrow); assert.equal(setFunctionName(obj.named, ''), obj.named); assert.equal(setFunctionName(obj.anon, 'anonymous'), obj.anon); assert.equal(obj.concise.name, 'brief'); assert.equal(obj.arrow.name, 'pointy'); assert.equal(obj.named.name, ''); assert.equal(obj.anon.name, 'anonymous'); ``` [package-url]: https://npmjs.org/package/set-function-name [npm-version-svg]: https://versionbadg.es/ljharb/set-function-name.svg [deps-svg]: https://david-dm.org/ljharb/set-function-name.svg [deps-url]: https://david-dm.org/ljharb/set-function-name [dev-deps-svg]: https://david-dm.org/ljharb/set-function-name/dev-status.svg [dev-deps-url]: https://david-dm.org/ljharb/set-function-name#info=devDependencies [npm-badge-png]: https://nodei.co/npm/set-function-name.png?downloads=true&stars=true [license-image]: https://img.shields.io/npm/l/set-function-name.svg [license-url]: LICENSE [downloads-image]: https://img.shields.io/npm/dm/set-function-name.svg [downloads-url]: https://npm-stat.com/charts.html?package=set-function-name [codecov-image]: https://codecov.io/gh/ljharb/set-function-name/branch/main/graphs/badge.svg [codecov-url]: https://app.codecov.io/gh/ljharb/set-function-name/ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/set-function-name [actions-url]: https://github.com/ljharb/set-function-name/actions set-function-name-2.0.1/index.js000066400000000000000000000011571450034123400165130ustar00rootroot00000000000000'use strict'; var define = require('define-data-property'); var hasDescriptors = require('has-property-descriptors')(); var functionsHaveConfigurableNames = require('functions-have-names').functionsHaveConfigurableNames(); var $TypeError = TypeError; module.exports = function setFunctionName(fn, name) { if (typeof fn !== 'function') { throw new $TypeError('`fn` is not a function'); } var loose = arguments.length > 2 && !!arguments[2]; if (!loose || functionsHaveConfigurableNames) { if (hasDescriptors) { define(fn, 'name', name, true, true); } else { define(fn, 'name', name); } } return fn; }; set-function-name-2.0.1/package.json000066400000000000000000000041341450034123400173320ustar00rootroot00000000000000{ "name": "set-function-name", "version": "2.0.1", "description": "Set a function's name property", "main": "index.js", "directories": { "test": "test" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "lint": "eslint --ext=js,mjs .", "postlint": "evalmd README.md", "pretest": "npm run lint", "tests-only": "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-name.git" }, "keywords": [ "set", "assign", "function", "name", "function.name" ], "author": "Jordan Harband ", "license": "MIT", "bugs": { "url": "https://github.com/ljharb/set-function-name/issues" }, "homepage": "https://github.com/ljharb/set-function-name#readme", "devDependencies": { "@ljharb/eslint-config": "^21.1.0", "aud": "^2.0.3", "auto-changelog": "^2.4.0", "es-value-fixtures": "^1.4.2", "eslint": "=8.8.0", "evalmd": "^0.0.19", "for-each": "^0.3.3", "function.prototype.name": "^1.1.6", "in-publish": "^2.0.1", "make-arrow-function": "^1.2.0", "make-async-function": "^1.0.0", "make-async-generator-function": "^1.0.0", "make-generator-function": "^2.0.0", "npmignore": "^0.3.0", "object-inspect": "^1.12.3", "safe-publish-latest": "^2.0.0", "tape": "^5.6.6" }, "dependencies": { "define-data-property": "^1.0.1", "functions-have-names": "^1.2.3", "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-name-2.0.1/test/000077500000000000000000000000001450034123400160215ustar00rootroot00000000000000set-function-name-2.0.1/test/index.js000066400000000000000000000027101450034123400174660ustar00rootroot00000000000000'use strict'; var test = require('tape'); var functionsHaveConfigurableNames = require('functions-have-names').functionsHaveConfigurableNames(); var generators = require('make-generator-function')(); var arrows = require('make-arrow-function').list(); var asyncs = require('make-async-function').list(); var asyncGens = require('make-async-generator-function')(); var forEach = require('for-each'); var inspect = require('object-inspect'); var v = require('es-value-fixtures'); var functionName = require('function.prototype.name'); var setFunctionName = require('../'); test('set function name', function (t) { forEach(v.nonFunctions, function (nonFunction) { t['throws']( function () { setFunctionName(nonFunction); }, TypeError, inspect(nonFunction) + ' is not a function' ); }); t.test('setting the name', { skip: !functionsHaveConfigurableNames }, function (st) { var i = 1; forEach([].concat( function () {}, function f() {}, { inferred: function () {} }.inferred, arrows, asyncs, generators, asyncGens ), function (fn) { var origName = functionName(fn); i += 1; var newName = origName + i; var msg = inspect(fn) + ': returns it (' + Function.prototype.toString.call(fn) + ')'; st.equal(setFunctionName(fn, newName), fn, msg); st.equal( functionName(fn), newName, inspect(fn) + ': sets the name from ' + inspect(origName) + ' to ' + inspect(newName) ); }); st.end(); }); t.end(); });