Beta 7 with some repo names changed.

This commit is contained in:
Luis Fernando Molina committed 2020-11-15 13:05:19 +01:00
1 parent 0f7b40cca7
commit 963c19493a
3408 files changed
+462217 -15516

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
var isHexPrefixed = require('is-hex-prefixed');
/**
* Removes '0x' from a given `String` is present
* @param {String} str the string value
* @return {String|Optional} a string by pass if necessary
*/
module.exports = function stripHexPrefix(str) {
if (typeof str !== 'string') {
return str;
}
return isHexPrefixed(str) ? str.slice(2) : str;
}
+47
View File
@@ -0,0 +1,47 @@
const stripHexPrefix = require('../index.js');
const assert = require('chai').assert;
describe("isHexPrefixed", () => {
describe("constructor", () => {
it("should be function export", () => {
assert.equal(typeof stripHexPrefix, 'function');
});
});
describe("should function normall", () => {
it('should stripHexPrefix strip prefix of valid strings', () => {
assert.equal(stripHexPrefix('0xkdsfksfdkj'), 'kdsfksfdkj');
assert.equal(stripHexPrefix('0xksfdkj'), 'ksfdkj');
assert.equal(stripHexPrefix('0xkdsfdkj'), 'kdsfdkj');
assert.equal(stripHexPrefix('0x23442sfdkj'), '23442sfdkj');
assert.equal(stripHexPrefix('0xkdssdfssfdkj'), 'kdssdfssfdkj');
assert.equal(stripHexPrefix('0xaaaasfdkj'), 'aaaasfdkj');
assert.equal(stripHexPrefix('0xkdsdfsfsdfsdfsdfdkj'), 'kdsdfsfsdfsdfsdfdkj');
assert.equal(stripHexPrefix('0x111dssdddj'), '111dssdddj');
assert.equal(stripHexPrefix('0x'), '');
assert.equal(stripHexPrefix(''), '');
assert.equal(stripHexPrefix('-0xsdfsfd'), '-0xsdfsfd');
assert.equal(stripHexPrefix('-0x'), '-0x');
});
it('should stripHexPrefix strip prefix of mix hexed strings', () => {
assert.equal(stripHexPrefix('0xkdsfksfdkj'), 'kdsfksfdkj');
assert.equal(stripHexPrefix('ksfdkj'), 'ksfdkj');
assert.equal(stripHexPrefix('kdsfdkj'), 'kdsfdkj');
assert.equal(stripHexPrefix('23442sfdkj'), '23442sfdkj');
assert.equal(stripHexPrefix('0xkdssdfssfdkj'), 'kdssdfssfdkj');
assert.equal(stripHexPrefix('aaaasfdkj'), 'aaaasfdkj');
assert.equal(stripHexPrefix('kdsdfsfsdfsdfsdfdkj'), 'kdsdfsfsdfsdfsdfdkj');
assert.equal(stripHexPrefix('111dssdddj'), '111dssdddj');
});
it('should stripHexPrefix bypass if not string', () => {
assert.equal(stripHexPrefix(null), null);
assert.equal(stripHexPrefix(undefined), undefined);
assert.equal(stripHexPrefix(242423), 242423);
assert.deepEqual(stripHexPrefix({}), {});
assert.deepEqual(stripHexPrefix([]), []);
assert.equal(stripHexPrefix(true), true);
});
});
});