agentia-utilities
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -7,4 +7,10 @@ 'use strict'; | ||
var eslint = require('gulp-eslint'); | ||
var git = require('gulp-git'); | ||
var bump = require('gulp-bump'); | ||
var argv = require('yargs').argv; | ||
var fs = require('fs'); | ||
var files = { | ||
root: './', | ||
pkg: './package.json', | ||
src: ['./index.js'], | ||
@@ -14,2 +20,8 @@ test: ['./test/**/*.spec.js'] | ||
var getPackageJson = function () { | ||
/*eslint-disable*/ | ||
return JSON.parse(fs.readFileSync(files.pkg, 'utf8')); | ||
/*eslint-enable*/ | ||
}; | ||
gulp.task('lint', function () { | ||
@@ -47,1 +59,23 @@ return gulp.src(files.src.concat(files.test)) | ||
}); | ||
gulp.task('bump', function() { | ||
var versioning = function() { | ||
if (argv.minor || argv.feature) { | ||
return 'minor'; | ||
} | ||
if (argv.major) { | ||
return 'major'; | ||
} | ||
return 'patch'; | ||
}; | ||
return gulp.src(files.pkg) | ||
.pipe(bump({ type: versioning() })) | ||
.pipe(gulp.dest(files.root)) | ||
.on('end', function() { | ||
var pkg = getPackageJson(); | ||
var msg = 'chore(version): bumped version to ' + pkg.version; | ||
gulp.src(files.pkg) | ||
.pipe(git.commit(msg)); | ||
}); | ||
}); |
109
index.js
'use strict'; | ||
var typeOf = function typeOf(value) { | ||
return Object.prototype.toString.call(value) | ||
.replace(/^\[.+\s(.+?)\]$/, '$1') | ||
.toLowerCase(); | ||
}; | ||
var isArray = function isArray(arg) { | ||
return Array.isArray(arg); | ||
return Array.isArray(arg); | ||
}; | ||
var isFunction = function isFunction(arg) { | ||
return (typeof arg === 'function'); | ||
return (typeOf(arg) === 'function'); | ||
}; | ||
var isObject = function isObject(arg) { | ||
return (Object.prototype.toString.call(arg) === '[object Object]'); | ||
return (typeOf(arg) === 'object'); | ||
}; | ||
var isDate = function isDate(arg) { | ||
return (Object.prototype.toString.call(arg) === '[object Date]'); | ||
return (typeOf(arg) === 'date'); | ||
}; | ||
var isString = function isString(arg) { | ||
return (typeof arg === 'string'); | ||
return (typeOf(arg) === 'string'); | ||
}; | ||
var isNumber = function isNumber(arg) { | ||
return (typeof arg === 'number'); | ||
return (typeOf(arg) === 'number'); | ||
}; | ||
var isBoolean = function isBoolean(arg) { | ||
return (typeof arg === 'boolean'); | ||
return (typeOf(arg) === 'boolean'); | ||
}; | ||
var isUndefined = function isUndefined(arg) { | ||
return (typeof arg === 'undefined'); | ||
return (typeOf(arg) === 'undefined'); | ||
}; | ||
var isNull = function isNull(arg) { | ||
return (arg === null); | ||
return (typeOf(arg) === 'null'); | ||
}; | ||
var exists = function exists(arg) { | ||
return !isUndefined(arg) && !isNull(arg); | ||
return !isUndefined(arg) && !isNull(arg); | ||
}; | ||
@@ -45,11 +51,11 @@ | ||
var string = ''; | ||
var string = ''; | ||
length = !length ? 20 : length; | ||
characters = characters || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'; | ||
length = !length ? 20 : length; | ||
characters = characters || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'; | ||
for (var i = 0; i < length; i++) { | ||
string += characters.charAt(Math.floor(Math.random() * characters.length)); | ||
} | ||
return string; | ||
for (var i = 0; i < length; i++) { | ||
string += characters.charAt(Math.floor(Math.random() * characters.length)); | ||
} | ||
return string; | ||
@@ -59,24 +65,24 @@ }; | ||
var round = function round(num, exp) { | ||
exp = !exp ? 0 : exp; | ||
var multiplier = Math.pow(10, exp); | ||
return Math.floor(num * multiplier) / multiplier; | ||
exp = !exp ? 0 : exp; | ||
var multiplier = Math.pow(10, exp); | ||
return Math.floor(num * multiplier) / multiplier; | ||
}; | ||
var defineProp = function defineProp(obj, name, getter, setter) { | ||
var options = { | ||
configurable: true, | ||
var options = { | ||
configurable: true, | ||
enumerable: true | ||
}; | ||
}; | ||
if (isFunction(getter)) { | ||
options.get = getter; | ||
} | ||
if (isFunction(getter)) { | ||
options.get = getter; | ||
} | ||
if (!isFunction(getter) && exists(getter)) { | ||
options.value = getter; | ||
} | ||
if (!isFunction(getter) && exists(getter)) { | ||
options.value = getter; | ||
} | ||
if (isFunction(setter)) { | ||
options.set = setter; | ||
} | ||
if (isFunction(setter)) { | ||
options.set = setter; | ||
} | ||
@@ -87,8 +93,8 @@ Object.defineProperty(obj, name, options); | ||
var getParamNames = function getParamNames(fn) { | ||
var params; | ||
var params; | ||
if (isFunction(fn)) { | ||
fn = fn.toString(); | ||
params = fn.slice(fn.indexOf('(') + 1, fn.indexOf(')')).match(/([^\s,]+)/g); | ||
} | ||
if (isFunction(fn)) { | ||
fn = fn.toString(); | ||
params = fn.slice(fn.indexOf('(') + 1, fn.indexOf(')')).match(/([^\s,]+)/g); | ||
} | ||
return isArray(params) ? params : []; | ||
@@ -98,16 +104,17 @@ }; | ||
module.exports = { | ||
isArray: isArray, | ||
isFunction: isFunction, | ||
isObject: isObject, | ||
isDate: isDate, | ||
isString: isString, | ||
isNumber: isNumber, | ||
isBoolean: isBoolean, | ||
isUndefined: isUndefined, | ||
isNull: isNull, | ||
exists: exists, | ||
randomString: randomString, | ||
round: round, | ||
defineProp: defineProp, | ||
getParamNames: getParamNames | ||
typeOf: typeOf, | ||
isArray: isArray, | ||
isFunction: isFunction, | ||
isObject: isObject, | ||
isDate: isDate, | ||
isString: isString, | ||
isNumber: isNumber, | ||
isBoolean: isBoolean, | ||
isUndefined: isUndefined, | ||
isNull: isNull, | ||
exists: exists, | ||
randomString: randomString, | ||
round: round, | ||
defineProp: defineProp, | ||
getParamNames: getParamNames | ||
}; |
{ | ||
"name": "agentia-utilities", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Multipurpose utilities for by Agentia modules", | ||
@@ -30,8 +30,11 @@ "main": "index.js", | ||
"gulp": "^3.8.11", | ||
"gulp-bump": "^0.3.0", | ||
"gulp-eslint": "^0.8.0", | ||
"gulp-git": "^1.2.0", | ||
"gulp-istanbul": "^0.8.1", | ||
"gulp-mocha": "^2.0.1", | ||
"istanbul": "^0.3.13", | ||
"mocha": "^2.2.1" | ||
"mocha": "^2.2.1", | ||
"yargs": "^3.7.2" | ||
} | ||
} |
@@ -10,2 +10,46 @@ 'use strict'; | ||
describe('.typeOf()', function() { | ||
it('should recognize arrays', function() { | ||
expect(utils.typeOf([])).to.equal('array'); | ||
expect(utils.typeOf(new Array())).to.equal('array'); | ||
}); | ||
it('should recognize functions', function() { | ||
expect(utils.typeOf(function() {})).to.equal('function'); | ||
}); | ||
it('should recognize objects', function() { | ||
expect(utils.typeOf({})).to.equal('object'); | ||
}); | ||
it('should recognize dates', function() { | ||
expect(utils.typeOf(new Date())).to.equal('date'); | ||
}); | ||
it('should recognize strings', function() { | ||
expect(utils.typeOf(String(''))).to.equal('string'); | ||
expect(utils.typeOf('')).to.equal('string'); | ||
}); | ||
it('should recognize numbers', function() { | ||
expect(utils.typeOf(Number(0))).to.equal('number'); | ||
expect(utils.typeOf(0)).to.equal('number'); | ||
}); | ||
it('should recognize booleans', function() { | ||
expect(utils.typeOf(true)).to.equal('boolean'); | ||
expect(utils.typeOf(false)).to.equal('boolean'); | ||
}); | ||
it('should recognize undefined', function() { | ||
expect(utils.typeOf(undefined)).to.equal('undefined'); | ||
}); | ||
it('should recognize nulls', function() { | ||
expect(utils.typeOf(null)).to.equal('null'); | ||
}); | ||
}); | ||
describe('.isArray()', function() { | ||
@@ -12,0 +56,0 @@ |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
29178
453
12
1