Current Folder
This commit is contained in:
1 parent
8b3382289b
commit
cfcada880d
4379 files changed
No files matched your search
+46
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"name": "strip-hex-prefix",
|
||||
"version": "1.0.0",
|
||||
"description": "A simple method that will strip a valid hex prefix off a string, if present.",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "mocha src/tests/**/**.js",
|
||||
"test-travis": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- src/tests/**/*.js",
|
||||
"coveralls": "npm run test-travis && cat ./coverage/lcov.info | coveralls"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/SilentCicero/strip-hex-prefix.git"
|
||||
},
|
||||
"engines": {
|
||||
"npm": ">=3",
|
||||
"node": ">=6.5.0"
|
||||
},
|
||||
"keywords": [
|
||||
"is",
|
||||
"hex",
|
||||
"prefixed",
|
||||
"prefix",
|
||||
"checker",
|
||||
"method"
|
||||
],
|
||||
"author": "Nick Dodson <thenickdodson@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/SilentCicero/strip-hex-prefix/issues"
|
||||
},
|
||||
"homepage": "https://github.com/SilentCicero/strip-hex-prefix#readme",
|
||||
"dependencies": {
|
||||
"is-hex-prefixed": "1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "3.5.0",
|
||||
"mocha": "3.2.0",
|
||||
"istanbul": "0.4.5",
|
||||
"coveralls": "2.11.9"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/strip-hex-prefix/-/strip-hex-prefix-1.0.0.tgz"
|
||||
,"_integrity": "sha1-DF8VX+8RUTczd96du1iNoFUA428="
|
||||
,"_from": "strip-hex-prefix@1.0.0"
|
||||
}
|
||||
+14
@@ -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
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user