Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2
@@ -0,2 +1,6 @@ | ||
export declare function anyToHexValue(value: any, options?: { | ||
add0x?: boolean; | ||
defaults?: string; | ||
}): string; | ||
export declare function prepareHexValue(value: any, add0x?: boolean): string; | ||
export declare function verifyHexValue(value: any): boolean; | ||
export declare function verifyHexValue(value: any, prepare?: boolean): boolean; |
39
hex.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const buffer_1 = require("buffer"); | ||
const bignumber_js_1 = require("bignumber.js"); | ||
function anyToHexValue(value, options = {}) { | ||
const { add0x, defaults } = options; | ||
let result = null; | ||
switch (typeof value) { | ||
case "string": | ||
value = prepareHexValue(value, false); | ||
if (verifyHexValue(result)) { | ||
result = value; | ||
} | ||
break; | ||
case "number": | ||
result = value.toString(16); | ||
break; | ||
case "object": | ||
if (buffer_1.Buffer.isBuffer(value)) { | ||
result = value.toString("hex"); | ||
} | ||
else if (bignumber_js_1.BigNumber.isBigNumber(value)) { | ||
result = value.toString(16); | ||
} | ||
break; | ||
} | ||
if (result === null && typeof defaults !== "undefined") { | ||
result = defaults; | ||
} | ||
if (result && add0x) { | ||
result = `0x${result}`; | ||
} | ||
return result; | ||
} | ||
exports.anyToHexValue = anyToHexValue; | ||
function prepareHexValue(value, add0x = false) { | ||
@@ -18,5 +51,7 @@ let result = null; | ||
exports.prepareHexValue = prepareHexValue; | ||
function verifyHexValue(value) { | ||
function verifyHexValue(value, prepare = true) { | ||
let result = false; | ||
value = prepareHexValue(value, false); | ||
if (prepare) { | ||
value = prepareHexValue(value, false); | ||
} | ||
if (value !== null) { | ||
@@ -23,0 +58,0 @@ const charCodes = value.split("").map((char) => char.charCodeAt(0)); |
@@ -1,3 +0,4 @@ | ||
export * from "./crypto"; | ||
export * from "./address"; | ||
export * from "./buffer"; | ||
export * from "./encryption"; | ||
export * from "./hex"; | ||
export * from "./number"; |
@@ -6,4 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./crypto")); | ||
__export(require("./address")); | ||
__export(require("./buffer")); | ||
__export(require("./encryption")); | ||
__export(require("./hex")); | ||
__export(require("./number")); |
{ | ||
"name": "eth-utils", | ||
"version": "0.1.0-alpha.1", | ||
"version": "0.1.0-alpha.2", | ||
"description": "Ethereum Utils", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -6,1 +6,29 @@ # ETH Utils | ||
**WARNING!** This is experimental library, don't use it on production. | ||
## Installation | ||
```bash | ||
$ npm i eth-utils | ||
``` | ||
## Api | ||
### Address | ||
* `verifyAddress(value: string, caseSensitivity?: boolean): boolean` | ||
* `prepareAddress(value: string, caseSensitivity?: boolean): string` | ||
### Buffer | ||
* `anyToBuffer(value: any, options?: { size?: number; defaults?: Buffer;}): Buffer` | ||
### Encryption | ||
* `sha3(...data: Buffer[]): Buffer`; | ||
### Hex | ||
* `anyToHexValue(value: any, options?: { add0x?: boolean; defaults?: string;}): string` | ||
* `prepareHexValue(value: any, add0x?: boolean): string` | ||
* `verifyHexValue(value: any, prepare?: boolean): boolean` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6779
12
180
34
1