New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

inherits-ex

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inherits-ex - npm Package Compare versions

Comparing version 2.1.0-alpha.9 to 2.1.0-alpha.10

8

lib/isEmptyFunction-cli.d.ts
/**
* Determines whether the given string represents an empty constructor.
* Determines whether the given function is empty.
*
* @param {string} vStr - The string to check.
* @returns {boolean} - Returns true if the string represents an empty constructor, otherwise false
* @param {Function} aFunc - The function to check.
* @returns {boolean} - Returns true if it's empty, otherwise false
*/
export function isEmptyFunctionCli(aFunc: any): boolean;
export function isEmptyFunctionCli(aFunc: Function): boolean;
export default isEmptyFunctionCli;

@@ -9,9 +9,10 @@ "use strict";

/**
* Determines whether the given string represents an empty constructor.
* Determines whether the given function is empty.
*
* @param {string} vStr - The string to check.
* @returns {boolean} - Returns true if the string represents an empty constructor, otherwise false
* @param {Function} aFunc - The function to check.
* @returns {boolean} - Returns true if it's empty, otherwise false
*/
function isEmptyFunctionCli(aFunc) {
return /^function\s*\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;]*}$/g.test(aFunc.toString());
aFunc = aFunc.toString();
return /^(function\s+)?\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;\n\r]*}$/g.test(aFunc) || /^\((.|[\n\r\u2028\u2029])*\)\s*=>\s*{[\s;]*}$/g.test(aFunc);
}

@@ -18,0 +19,0 @@ ;

@@ -5,4 +5,8 @@ /**

* @returns {boolean} - True if the function is empty, false otherwise.
*/
*
* @example
* isEmptyFunction(Array.prototype.push); // -> false
* isEmptyFunction(()=>{}); // -> true
*/
export function isEmptyFunction(aFunc: Function): boolean;
export default isEmptyFunction;

@@ -14,7 +14,14 @@ "use strict";

* @returns {boolean} - True if the function is empty, false otherwise.
*/
*
* @example
* isEmptyFunction(Array.prototype.push); // -> false
* isEmptyFunction(()=>{}); // -> true
*/
function isEmptyFunction(aFunc) {
const vStr = aFunc.toString();
let result = /^function\s*\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;]*}$/g.test(vStr);
let result = /^(function\s+)?\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;\n\r]*}$/g.test(vStr);
if (!result) {
result = /^\((.|[\n\r\u2028\u2029])*\)\s*=>\s*{[\s;]*}$/g.test(vStr);
}
if (!result) {
result = (0, _isEmptyCtor.default)(vStr);

@@ -21,0 +28,0 @@ }

@@ -5,3 +5,3 @@ {

"homepage": "https://github.com/snowyu/inherits-ex.js",
"version": "2.1.0-alpha.9",
"version": "2.1.0-alpha.10",
"author": {

@@ -8,0 +8,0 @@ "name": "Riceball LEE",

/**
* Determines whether the given string represents an empty constructor.
* Determines whether the given function is empty.
*
* @param {string} vStr - The string to check.
* @returns {boolean} - Returns true if the string represents an empty constructor, otherwise false
* @param {Function} aFunc - The function to check.
* @returns {boolean} - Returns true if it's empty, otherwise false
*/
export function isEmptyFunctionCli(aFunc) {
return /^function\s*\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;]*}$/g.test(aFunc.toString());
aFunc = aFunc.toString()
return /^(function\s+)?\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;\n\r]*}$/g.test(aFunc) ||
/^\((.|[\n\r\u2028\u2029])*\)\s*=>\s*{[\s;]*}$/g.test(aFunc);
};
export default isEmptyFunctionCli;

@@ -7,6 +7,11 @@ import isEmptyCtor from './isEmptyCtor.js';

* @returns {boolean} - True if the function is empty, false otherwise.
*/
*
* @example
* isEmptyFunction(Array.prototype.push); // -> false
* isEmptyFunction(()=>{}); // -> true
*/
export function isEmptyFunction(aFunc) {
const vStr = aFunc.toString();
let result = /^function\s*\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;]*}$/g.test(vStr);
let result = /^(function\s+)?\S*\s*\((.|[\n\r\u2028\u2029])*\)\s*{[\s;\n\r]*}$/g.test(vStr);
if (!result) { result = /^\((.|[\n\r\u2028\u2029])*\)\s*=>\s*{[\s;]*}$/g.test(vStr)}
if (!result) {result = isEmptyCtor(vStr)}

@@ -13,0 +18,0 @@

@@ -23,2 +23,26 @@ import chai from 'chai'

});
it("should test empty function expression", function() {
expect(isEmptyFunction(()=>{})).to.equal(true);
expect(isEmptyFunction((a,b,c)=>{ })).to.equal(true);
expect(isEmptyFunction((a,b,c)=>{
;
})).to.equal(true);
expect(isEmptyFunction((a,b,c,e)=>{ ; })).to.equal(true);
expect(isEmptyFunction((a,b,c,e)=>3)).to.not.equal(true);
});
it("should test empty method", function() {
class A {
m(b,
ac) {
;
}
m2() {}
m3() { }
n(abc, ase) {return}
}
expect(isEmptyFunction(A.prototype.m)).to.equal(true);
expect(isEmptyFunction(A.prototype.m2)).to.equal(true);
expect(isEmptyFunction(A.prototype.m3)).to.equal(true);
expect(isEmptyFunction(A.prototype.n)).to.not.equal(true);
});
it.skip("should support istanbul hooked empty function", function() {

@@ -25,0 +49,0 @@ function Test(location){__cov_jOpjHgc_dBxBGFBAhmJ5rg.f['5']++;};

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc