flocore-node/lib/utils.js
Braydon Fuller d958e83f1d build: add support for nodejs 0.10
For Ubuntu 14.04 Node.js compatibility: http://packages.ubuntu.com/trusty/nodejs
2016-04-25 17:23:48 -04:00

30 lines
699 B
JavaScript

'use strict';
var MAX_SAFE_INTEGER = 0x1fffffffffffff; // 2 ^ 53 - 1
var utils = {};
utils.isHash = function isHash(value) {
return typeof value === 'string' && value.length === 64 && /^[0-9a-fA-F]+$/.test(value);
};
utils.isSafeNatural = function isSafeNatural(value) {
return typeof value === 'number' &&
isFinite(value) &&
Math.floor(value) === value &&
value >= 0 &&
value <= MAX_SAFE_INTEGER;
};
utils.startAtZero = function startAtZero(obj, key) {
if (!obj.hasOwnProperty(key)) {
obj[key] = 0;
}
};
utils.isAbsolutePath = require('path').isAbsolute;
if (!utils.isAbsolutePath) {
utils.isAbsolutePath = require('path-is-absolute');
}
module.exports = utils;