Skip to content

Commit 1436af2

Browse files
koddssonkeithamus
andauthoredOct 8, 2021
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>
1 parent 6b72548 commit 1436af2

7 files changed

+8993
-169
lines changed
 

‎.travis.yml

-29
This file was deleted.

‎index.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
'use strict';
2-
3-
/* !
4-
* Chai - getFuncName utility
5-
* Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com>
6-
* MIT Licensed
7-
*/
8-
91
/**
102
* ### .getFuncName(constructorFn)
113
*
@@ -19,26 +11,28 @@
1911
* @api public
2012
*/
2113

22-
var toString = Function.prototype.toString;
23-
var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;
14+
const { toString } = Function.prototype;
15+
const functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*/)]+\*\/\s*)*([^\s(/]+)/;
2416
function getFuncName(aFunc) {
2517
if (typeof aFunc !== 'function') {
2618
return null;
2719
}
2820

29-
var name = '';
21+
let name = '';
3022
if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') {
3123
// Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined
32-
var match = toString.call(aFunc).match(functionNameMatch);
24+
// eslint-disable-next-line prefer-reflect
25+
const match = toString.call(aFunc).match(functionNameMatch);
3326
if (match) {
34-
name = match[1];
27+
[ name ] = match;
3528
}
3629
} else {
3730
// If we've got a `name` property we just use it
31+
// eslint-disable-next-line prefer-destructuring
3832
name = aFunc.name;
3933
}
4034

4135
return name;
4236
}
4337

44-
module.exports = getFuncName;
38+
export { getFuncName };

‎karma.conf.cjs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = function configureKarma(config) {
2+
config.set({
3+
basePath: '.',
4+
browsers: [ 'ChromeHeadless' ],
5+
frameworks: [ 'mocha' ],
6+
files: [
7+
{ pattern: './index.js', type: 'module' },
8+
{ pattern: './test/*.js', type: 'module' },
9+
],
10+
reporters: [ 'progress' ],
11+
colors: true,
12+
autoWatch: false,
13+
singleRun: true,
14+
});
15+
};

‎karma.conf.js

-96
This file was deleted.

‎package-lock.json

+8,949
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+18-26
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,20 @@
1515
"Aleksey Shvayka (https://github.com/shvaikalesh)"
1616
],
1717
"files": [
18-
"index.js",
19-
"get-func-name.js"
18+
"index.js"
2019
],
20+
"type": "module",
2121
"main": "./index.js",
2222
"repository": {
2323
"type": "git",
2424
"url": "git+ssh://git@github.com/chaijs/get-func-name.git"
2525
},
2626
"scripts": {
27-
"build": "browserify --bare $npm_package_main --standalone getFuncName -o get-func-name.js",
2827
"lint": "eslint --ignore-path .gitignore .",
29-
"prepublish": "npm run build",
3028
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
3129
"pretest": "npm run lint",
3230
"test": "npm run test:node && npm run test:browser && npm run upload-coverage",
33-
"test:browser": "karma start --singleRun=true",
31+
"test:browser": "karma start karma.conf.cjs --singleRun=true",
3432
"test:node": "istanbul cover _mocha",
3533
"upload-coverage": "lcov-result-merger 'coverage/**/lcov.info' | coveralls; exit 0"
3634
},
@@ -41,7 +39,7 @@
4139
},
4240
"eslintConfig": {
4341
"extends": [
44-
"strict/es5"
42+
"strict/es6"
4543
],
4644
"env": {
4745
"es6": true
@@ -51,33 +49,27 @@
5149
},
5250
"rules": {
5351
"complexity": 0,
54-
"max-statements": 0
52+
"max-statements": 0,
53+
"prefer-arrow-callback": "off"
5554
}
5655
},
5756
"dependencies": {},
5857
"devDependencies": {
59-
"browserify": "^13.0.0",
60-
"browserify-istanbul": "^2.0.0",
61-
"coveralls": "2.11.14",
62-
"eslint": "^2.4.0",
63-
"eslint-config-strict": "^9.1.0",
58+
"coveralls": "^3.1.1",
59+
"eslint": "^7.32.0",
60+
"eslint-config-strict": "^14.0.1",
6461
"eslint-plugin-filenames": "^1.1.0",
65-
"ghooks": "^1.0.1",
66-
"istanbul": "^0.4.2",
67-
"karma": "^1.3.0",
68-
"karma-browserify": "^5.0.2",
69-
"karma-coverage": "^1.1.1",
70-
"karma-mocha": "^1.2.0",
71-
"karma-phantomjs-launcher": "^1.0.0",
72-
"karma-sauce-launcher": "^1.0.0",
73-
"lcov-result-merger": "^1.0.2",
74-
"mocha": "^3.1.2",
75-
"phantomjs-prebuilt": "^2.1.5",
76-
"semantic-release": "^4.3.5",
77-
"travis-after-all": "^1.4.4",
62+
"ghooks": "^2.0.4",
63+
"istanbul": "^0.4.5",
64+
"karma": "^6.3.4",
65+
"karma-chrome-launcher": "^3.1.0",
66+
"karma-mocha": "^2.0.1",
67+
"lcov-result-merger": "^3.1.0",
68+
"mocha": "^9.1.2",
69+
"semantic-release": "^18.0.0",
7870
"validate-commit-msg": "^2.3.1"
7971
},
8072
"engines": {
81-
"node": "*"
73+
"node": ">= 12"
8274
}
8375
}

‎test/index.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
'use strict';
2-
var getFuncName = require('..');
1+
import { getFuncName } from '../index.js';
32
function assert(expr, msg) {
43
if (!expr) {
54
throw new Error(msg || 'Assertion Failed');
@@ -24,7 +23,7 @@ describe('getFuncName', function () {
2423
});
2524

2625
it('should return empty string for anonymous functions', function () {
27-
var anonymousFunc = (function () {
26+
const anonymousFunc = (function () {
2827
return function () { // eslint-disable-line func-style
2928
return 2;
3029
};
@@ -54,7 +53,7 @@ describe('getFuncName', function () {
5453

5554
it('should return `null` when passed a Symbol as argument', function () {
5655
if (typeof Symbol !== 'undefined') {
57-
assert(getFuncName(Symbol()) === null);
56+
assert(getFuncName(Symbol('symbol')) === null);
5857
}
5958
});
6059

0 commit comments

Comments
 (0)
Please sign in to comment.