Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: chaijs/get-func-name
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fbd5eb57742d6e7669a857de85925559b9a830bb
Choose a base ref
...
head repository: chaijs/get-func-name
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 27ad8ba2225ebc10292a82c619258ad8c042e638
Choose a head ref
  • 4 commits
  • 7 files changed
  • 2 contributors

Commits on Oct 8, 2021

  1. Copy the full SHA
    6b72548 View commit details
  2. Convert project to an ES module (#28)

    * Replace simple-assert with a throw
    
    * Convert project to ES module
    
    * Simplify karma config
    
    * Remove unused dependencies
    
    * Set `engines` key to node >= 12
    
    * Remove `.travis.yml`
    
    * Add back dependencies that are actually needed
    
    * Update eslint and friends
    
    * Remove obsolete build npm script
    
    Co-authored-by: Keith Cirkel <keithamus@users.noreply.github.com>
    koddsson and keithamus authored Oct 8, 2021
    Copy the full SHA
    1436af2 View commit details

Commits on Sep 26, 2023

  1. Copy the full SHA
    f934b22 View commit details
  2. 2.0.1

    keithamus committed Sep 26, 2023
    5
    Copy the full SHA
    27ad8ba View commit details
Showing with 11,856 additions and 172 deletions.
  1. +0 −29 .travis.yml
  2. +15 −14 index.js
  3. +15 −0 karma.conf.cjs
  4. +0 −96 karma.conf.js
  5. +11,784 −0 package-lock.json
  6. +20 −28 package.json
  7. +22 −5 test/index.js
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

29 changes: 15 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
'use strict';

/* !
* Chai - getFuncName utility
* Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
* MIT Licensed
*/

/**
* ### .getFuncName(constructorFn)
*
@@ -19,26 +11,35 @@
* @api public
*/

var toString = Function.prototype.toString;
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
const { toString } = Function.prototype;
const functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*/)]+\*\/\s*)*([^\s(/]+)/;
const maxFunctionSourceLength = 512;
function getFuncName(aFunc) {
if (typeof aFunc !== 'function') {
return null;
}

var name = '';
let name = '';
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
var match = toString.call(aFunc).match(functionNameMatch);
// eslint-disable-next-line prefer-reflect
const functionSource = toString.call(aFunc);
// To avoid unconstrained resource consumption due to pathalogically large function names,
// we limit the available return value to be less than 512 characters.
if (functionSource.indexOf('(') > maxFunctionSourceLength) {
return name;
}
const match = toString.call(aFunc).match(functionNameMatch);
if (match) {
name = match[1];
[ name ] = match;
}
} else {
// If we've got a `name` property we just use it
// eslint-disable-next-line prefer-destructuring
name = aFunc.name;
}

return name;
}

module.exports = getFuncName;
export { getFuncName };
15 changes: 15 additions & 0 deletions karma.conf.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function configureKarma(config) {
config.set({
basePath: '.',
browsers: [ 'ChromeHeadless' ],
frameworks: [ 'mocha' ],
files: [
{ pattern: './index.js', type: 'module' },
{ pattern: './test/*.js', type: 'module' },
],
reporters: [ 'progress' ],
colors: true,
autoWatch: false,
singleRun: true,
});
};
96 changes: 0 additions & 96 deletions karma.conf.js

This file was deleted.

Loading