Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hex-encoding

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hex-encoding - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

license

20

dist/browser.js

@@ -1,7 +0,5 @@

"use strict";
/* IMPORT */
Object.defineProperty(exports, "__esModule", { value: true });
const uint8_encoding_1 = require("uint8-encoding");
const constants_1 = require("./constants");
const is_1 = require("./is");
import U8 from 'uint8-encoding';
import { DEC2HEX, HEX2DEC } from './constants.js';
import is from './is.js';
/* MAIN */

@@ -13,3 +11,3 @@ const Browser = {

for (let i = 0, l = data.length; i < l; i++) {
hex += constants_1.DEC2HEX[data[i]];
hex += DEC2HEX[data[i]];
}

@@ -19,3 +17,3 @@ return hex;

encodeStr: (data) => {
return Browser.encode(uint8_encoding_1.default.encode(data));
return Browser.encode(U8.encode(data));
},

@@ -26,3 +24,3 @@ decode: (data) => {

for (let i = 0; i < length; i++) {
u8[i] = constants_1.HEX2DEC[data.slice(i * 2, (i * 2) + 2)];
u8[i] = HEX2DEC[data.slice(i * 2, (i * 2) + 2)];
}

@@ -32,7 +30,7 @@ return u8;

decodeStr: (data) => {
return uint8_encoding_1.default.decode(Browser.decode(data));
return U8.decode(Browser.decode(data));
},
is: is_1.default
is
};
/* EXPORT */
exports.default = Browser;
export default Browser;

@@ -1,5 +0,2 @@

"use strict";
/* MAIN */
Object.defineProperty(exports, "__esModule", { value: true });
exports.HEX2DEC = exports.DEC2HEX = void 0;
const DEC2HEX = (() => {

@@ -14,3 +11,2 @@ const alphabet = '0123456789abcdef';

})();
exports.DEC2HEX = DEC2HEX;
const HEX2DEC = (() => {

@@ -31,2 +27,3 @@ const hex2dec = {};

})();
exports.HEX2DEC = HEX2DEC;
/* EXPORT */
export { DEC2HEX, HEX2DEC };

@@ -1,4 +0,2 @@

"use strict";
/* MAIN */
Object.defineProperty(exports, "__esModule", { value: true });
const is = (data) => {

@@ -12,2 +10,2 @@ if (data.length % 2)

/* EXPORT */
exports.default = is;
export default is;

@@ -1,5 +0,4 @@

"use strict";
/* IMPORT */
Object.defineProperty(exports, "__esModule", { value: true });
const is_1 = require("./is");
import { Buffer } from 'node:buffer';
import is from './is.js';
/* MAIN */

@@ -21,5 +20,5 @@ const Node = {

},
is: is_1.default
is
};
/* EXPORT */
exports.default = Node;
export default Node;
{
"name": "hex-encoding",
"repository": "github:fabiospampinato/hex-encoding",
"description": "Hex encoding. An extremely fast and synchronous JS implementation.",
"version": "1.0.0",
"version": "2.0.0",
"type": "module",
"main": "dist/node.js",
"types": "dist/node.d.ts",
"types": "./dist/node.d.ts",
"exports": {

@@ -12,22 +14,11 @@ "node": "./dist/node.js",

"scripts": {
"benchmark": "node tasks/benchmark.js",
"clean": "rimraf dist",
"compile": "tsc --skipLibCheck",
"compile:watch": "tsc --skipLibCheck --watch",
"test": "fava",
"test:watch": "fava -w",
"benchmark": "tsex benchmark",
"benchmark:watch": "tsex benchmark --watch",
"clean": "tsex clean",
"compile": "tsex compile",
"compile:watch": "tsex compile --watch",
"test": "tsex test",
"test:watch": "tsex test --watch",
"prepublishOnly": "npm run clean && npm run compile && npm run test"
},
"bugs": {
"url": "https://github.com/fabiospampinato/hex-encoding/issues"
},
"license": "MIT",
"author": {
"name": "Fabio Spampinato",
"email": "spampinabio@gmail.com"
},
"repository": {
"type": "git",
"url": "https://github.com/fabiospampinato/hex-encoding.git"
},
"keywords": [

@@ -40,13 +31,12 @@ "hex",

"dependencies": {
"uint8-encoding": "^1.0.0"
"uint8-encoding": "^2.0.0"
},
"devDependencies": {
"@types/node": "^17.0.22",
"@types/node": "^17.0.23",
"benchloop": "^1.3.2",
"fast-check": "^2.23.2",
"fava": "^0.0.5",
"rimraf": "^3.0.2",
"typescript": "^4.6.2",
"typescript-transform-export-interop": "^1.0.4"
"fast-check": "^2.24.0",
"fava": "^0.0.6",
"tsex": "^1.0.4",
"typescript": "^4.6.3"
}
}
/* IMPORT */
import {Buffer} from 'node:buffer';
import is from './is';

@@ -5,0 +6,0 @@

/* IMPORT */
const benchmark = require ( 'benchloop' );
const fs = require ( 'fs' );
const U8 = require ( 'uint8-encoding' );
const {default: Hex} = require ( '../dist/node' );
import benchmark from 'benchloop';
import fs from 'node:fs';
import U8 from 'uint8-encoding';
import Hex from '../dist/node.js';

@@ -9,0 +9,0 @@ const WAP = fs.readFileSync ( './tasks/war_and_peace.txt', 'utf8' );

@@ -15,2 +15,2 @@

module.exports = Fixtures;
export default Fixtures;
/* IMPORT */
const fc = require ( 'fast-check' );
const {describe} = require ( 'fava' );
const {default: Hex} = require ( '../dist/node' );
const Fixtures = require ( './fixtures' );
import fc from 'fast-check';
import {describe} from 'fava';
import HexBrowser from '../dist/browser.js';
import HexNode from '../dist/node.js';
import Fixtures from './fixtures.js';
/* MAIN */
describe ( 'Hex', it => {
describe ( 'Hex', () => {
it ( 'works with strings', t => {
for ( const [Hex, name] of [[HexBrowser, 'browser'], [HexNode, 'node']] ) {
for ( const fixture of Fixtures ) {
describe ( name, it => {
const encoded = Hex.encodeStr ( fixture );
const decoded = Hex.decodeStr ( encoded );
it ( 'returns an actual Uint8Array', t => {
t.is ( decoded, fixture );
t.is ( Hex.decode ( 'ff' ).constructor, Uint8Array );
}
});
});
it ( 'works with strings', t => {
it ( 'works with Uint8Arrays', t => {
for ( const fixture of Fixtures ) {
const encoder = new TextEncoder ();
const encoded = Hex.encodeStr ( fixture );
const decoded = Hex.decodeStr ( encoded );
for ( const fixture of Fixtures ) {
t.is ( decoded, fixture );
const fixtureU8 = encoder.encode ( fixture );
}
const encoded = Hex.encode ( fixtureU8 );
const decoded = Hex.decode ( encoded );
});
t.deepEqual ( decoded, fixtureU8 );
it ( 'works with Uint8Arrays', t => {
}
const encoder = new TextEncoder ();
});
for ( const fixture of Fixtures ) {
it ( 'works with fc-generated strings', t => {
const fixtureU8 = encoder.encode ( fixture );
const assert = str => t.true ( !Hex.is ( str ) || ( Hex.decodeStr ( Hex.encodeStr ( str ) ) === str ) );
const property = fc.property ( fc.fullUnicodeString (), assert );
const encoded = Hex.encode ( fixtureU8 );
const decoded = Hex.decode ( encoded );
fc.assert ( property, { numRuns: 1000000 } );
t.deepEqual ( decoded, fixtureU8 );
});
}
it ( 'works like Buffer', t => {
});
const assert = str => Hex.is ( str ) ? t.deepEqual ( Hex.encodeStr ( str ), Buffer.from ( str ).toString ( 'hex' ) ) : t.pass ();
const property = fc.property ( fc.fullUnicodeString (), assert );
it ( 'works with fc-generated strings', t => {
fc.assert ( property, { numRuns: 1000000 } );
const assert = str => t.true ( !Hex.is ( str ) || ( Hex.decodeStr ( Hex.encodeStr ( str ) ) === str ) );
const property = fc.property ( fc.fullUnicodeString (), assert );
});
fc.assert ( property, { numRuns: 1000000 } );
it ( 'can detect Hex-encoded strings', t => {
});
const fixtures = [
['', true],
['a', false],
['A', false],
['ab', true],
['AB', true],
['abc', false],
['ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', false],
['0123456789abcdef', true],
['0123456789ABCDEF', true],
['0123456789ABCdef', true],
['\uffff\uffff\uffff\uffff', false],
['😃', false],
['👪', false]
];
it ( 'works like Buffer', t => {
for ( const [fixture, result] of fixtures ) {
const assert = str => Hex.is ( str ) ? t.deepEqual ( Hex.encodeStr ( str ), Buffer.from ( str ).toString ( 'hex' ) ) : t.pass ();
const property = fc.property ( fc.fullUnicodeString (), assert );
t.is ( Hex.is ( fixture ), result );
fc.assert ( property, { numRuns: 1000000 } );
}
});
});
it ( 'can detect Hex-encoded strings', t => {
const fixtures = [
['', true],
['a', false],
['A', false],
['ab', true],
['AB', true],
['abc', false],
['ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/', false],
['0123456789abcdef', true],
['0123456789ABCDEF', true],
['0123456789ABCdef', true],
['\uffff\uffff\uffff\uffff', false],
['😃', false],
['👪', false]
];
for ( const [fixture, result] of fixtures ) {
t.is ( Hex.is ( fixture ), result );
}
});
});
}
});
{
"compilerOptions": {
"alwaysStrict": true,
"declaration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"inlineSourceMap": false,
"jsx": "react",
"lib": ["es2020"],
"module": "commonjs",
"moduleResolution": "node",
"newLine": "LF",
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": false,
"outDir": "dist",
"pretty": true,
"strictNullChecks": true,
"target": "es2016"
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
"extends": "tsex/tsconfig.json"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc