agentia-utilities
Advanced tools
Comparing version 1.1.0 to 1.2.0
15
index.js
@@ -81,7 +81,15 @@ 'use strict'; | ||
console.log(options); | ||
Object.defineProperty(obj, name, options); | ||
}; | ||
var getParamNames = function getParamNames(fn) { | ||
var params; | ||
if (isFunction(fn)) { | ||
fn = fn.toString(); | ||
params = fn.slice(fn.indexOf('(') + 1, fn.indexOf(')')).match(/([^\s,]+)/g); | ||
} | ||
return isArray(params) ? params : []; | ||
}; | ||
module.exports = { | ||
@@ -100,3 +108,4 @@ isArray: isArray, | ||
round: round, | ||
defineProp: defineProp | ||
defineProp: defineProp, | ||
getParamNames: getParamNames | ||
}; |
{ | ||
"name": "agentia-utilities", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Multipurpose utilities for by Agentia modules", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "gulp spec" | ||
"test": "gulp lint && gulp spec" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -299,2 +299,38 @@ 'use strict'; | ||
describe('.getParamNames()', function() { | ||
it('should return an array of params', function() { | ||
var fn = function(a, b, c) { | ||
return a + b + c; | ||
}; | ||
var params = utils.getParamNames(fn); | ||
expect(params).to.be.an('array'); | ||
expect(params).to.have.length.of(3); | ||
expect(params).to.include('a'); | ||
expect(params).to.include('b'); | ||
expect(params).to.include('c'); | ||
}); | ||
it('should return an empty array, when function has no params', function() { | ||
var fn = function() {}; | ||
var params = utils.getParamNames(fn); | ||
expect(params).to.be.an('array'); | ||
expect(params).to.be.empty; | ||
}); | ||
it('should return an empty array, when argument is not a function', function() { | ||
expect(utils.getParamNames({})).to.be.empty; | ||
expect(utils.getParamNames(true)).to.be.empty; | ||
expect(utils.getParamNames('string')).to.be.empty; | ||
expect(utils.getParamNames(new Date())).to.be.empty; | ||
expect(utils.getParamNames([])).to.be.empty; | ||
expect(utils.getParamNames(0)).to.be.empty; | ||
expect(utils.getParamNames(null)).to.be.empty; | ||
expect(utils.getParamNames(undefined)).to.be.empty; | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27132
383