Beta 7 with some repo names changed.
This commit is contained in:
1 parent
0f7b40cca7
commit
963c19493a
3408 files changed
+462217
-15516
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Returns a `Boolean` on whether or not the a `String` starts with '0x'
|
||||
* @param {String} str the string input value
|
||||
* @return {Boolean} a boolean if it is or is not hex prefixed
|
||||
* @throws if the str input is not a string
|
||||
*/
|
||||
module.exports = function isHexPrefixed(str) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new Error("[is-hex-prefixed] value must be type 'string', is currently type " + (typeof str) + ", while checking isHexPrefixed.");
|
||||
}
|
||||
|
||||
return str.slice(0, 2) === '0x';
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
const isHexPrefixed = require('../index.js');
|
||||
const assert = require('chai').assert;
|
||||
|
||||
describe("isHexPrefixed", () => {
|
||||
describe("constructor", () => {
|
||||
it("should have the method exported", () => {
|
||||
assert.equal(typeof isHexPrefixed, 'function');
|
||||
});
|
||||
});
|
||||
|
||||
describe("should function normall", () => {
|
||||
it('should isHexPrefixed check if hex is prefixed', () => {
|
||||
assert.equal(isHexPrefixed('0xsdffsd'), true);
|
||||
assert.equal(isHexPrefixed('0x'), true);
|
||||
assert.equal(isHexPrefixed('0x3982349284'), true);
|
||||
assert.equal(isHexPrefixed('0x824723894jshdksjdhks'), true);
|
||||
});
|
||||
|
||||
it('should isHexPrefixed check if hex is prefixed not prefixed', () => {
|
||||
assert.equal(isHexPrefixed('sdffsd'), false);
|
||||
assert.equal(isHexPrefixed(''), false);
|
||||
assert.equal(isHexPrefixed('3982349284'), false);
|
||||
assert.equal(isHexPrefixed('824723894jshdksjdhks'), false);
|
||||
});
|
||||
|
||||
it('should isHexPrefixed throw as expected string got buffer', () => {
|
||||
try {
|
||||
isHexPrefixed(new Buffer());
|
||||
} catch (error) {
|
||||
assert.equal(typeof error, 'object');
|
||||
}
|
||||
});
|
||||
|
||||
it('should isHexPrefixed throw as expected string got empty object', () => {
|
||||
try {
|
||||
isHexPrefixed({});
|
||||
} catch (error) {
|
||||
assert.equal(typeof error, 'object');
|
||||
}
|
||||
});
|
||||
|
||||
it('should isHexPrefixed throw as expected string got number', () => {
|
||||
try {
|
||||
isHexPrefixed(823947243994);
|
||||
} catch (error) {
|
||||
assert.equal(typeof error, 'object');
|
||||
}
|
||||
});
|
||||
|
||||
it('should isHexPrefixed throw as expected string got undefined', () => {
|
||||
try {
|
||||
isHexPrefixed(undefined);
|
||||
} catch (error) {
|
||||
assert.equal(typeof error, 'object');
|
||||
}
|
||||
});
|
||||
|
||||
it('should isHexPrefixed throw as expected string got null', () => {
|
||||
try {
|
||||
isHexPrefixed(null);
|
||||
} catch (error) {
|
||||
assert.equal(typeof error, 'object');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user