util: minor.

This commit is contained in:
Christopher Jeffrey 2017-08-13 12:21:56 -07:00
parent ebb79e5ff1
commit b021f7cdd4
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -183,7 +183,7 @@ util.isAscii = function isAscii(str) {
*/
util.isBase58 = function isBase58(str) {
return typeof str === 'string' && /^[1-9a-zA-Z]+$/.test(str);
return typeof str === 'string' && /^[1-9A-Za-z]+$/.test(str);
};
/**
@ -197,7 +197,7 @@ util.isBase58 = function isBase58(str) {
util.isHex = function isHex(str) {
if (typeof str !== 'string')
return false;
return /^[0-9a-f]+$/i.test(str) && str.length % 2 === 0;
return str.length % 2 === 0 && /^[0-9A-Fa-f]+$/.test(str);
};
/**
@ -358,7 +358,7 @@ util.error = function error(...args) {
/**
* Return hrtime (shim for browser).
* @param {Array} time
* @returns {Array}
* @returns {Array} [seconds, nanoseconds]
*/
util.hrtime = function hrtime(time) {
@ -372,9 +372,14 @@ util.hrtime = function hrtime(time) {
}
const ms = now % 1000;
const sec = (now - ms) / 1000;
return [sec, ms * 1e6];
// Seconds
const hi = (now - ms) / 1000;
// Nanoseconds
const lo = ms * 1e6;
return [hi, lo];
}
if (time) {
@ -773,8 +778,11 @@ util.binaryRemove = function binaryRemove(items, item, compare) {
*/
util.isUpperCase = function isUpperCase(str) {
assert(typeof str === 'string');
if (str.length === 0)
return false;
return (str.charCodeAt(0) & 32) === 0;
};
@ -786,15 +794,14 @@ util.isUpperCase = function isUpperCase(str) {
*/
util.startsWith = function startsWith(str, prefix) {
assert(typeof str === 'string');
if (!str.startsWith)
return str.indexOf(prefix) === 0;
return str.startsWith(prefix);
};
if (!''.startsWith) {
util.startsWith = function startsWith(str, prefix) {
return str.indexOf(prefix) === 0;
};
}
/**
* Get memory usage info.
* @returns {Object}