Modularise JS source in 'lib' subdirectory.

Generate public API documention via jsdoc comments.
This commit is contained in:
Lovell Fuller
2016-11-01 14:33:16 +00:00
parent 552cfd6ff1
commit 8717ecc429
62 changed files with 3384 additions and 2779 deletions

94
lib/is.js Normal file
View File

@@ -0,0 +1,94 @@
'use strict';
/**
* Is this value defined and not null?
* @private
*/
const defined = function (val) {
return typeof val !== 'undefined' && val !== null;
};
/**
* Is this value an object?
* @private
*/
const object = function (val) {
return typeof val === 'object';
};
/**
* Is this value a function?
* @private
*/
const fn = function (val) {
return typeof val === 'function';
};
/**
* Is this value a boolean?
* @private
*/
const bool = function (val) {
return typeof val === 'boolean';
};
/**
* Is this value a Buffer object?
* @private
*/
const buffer = function (val) {
return object(val) && val instanceof Buffer;
};
/**
* Is this value a non-empty string?
* @private
*/
const string = function (val) {
return typeof val === 'string' && val.length > 0;
};
/**
* Is this value a real number?
* @private
*/
const number = function (val) {
return typeof val === 'number' && !Number.isNaN(val);
};
/**
* Is this value an integer?
* @private
*/
const integer = function (val) {
return number(val) && val % 1 === 0;
};
/**
* Is this value within an inclusive given range?
* @private
*/
const inRange = function (val, min, max) {
return val >= min && val <= max;
};
/**
* Is this value within the elements of an array?
* @private
*/
const inArray = function (val, list) {
return list.indexOf(val) !== -1;
};
module.exports = {
defined: defined,
object: object,
fn: fn,
bool: bool,
buffer: buffer,
string: string,
number: number,
integer: integer,
inRange: inRange,
inArray: inArray
};