-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fb7c1c
commit 7352104
Showing
5 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.toBuffer = toBuffer;var _strings = require("./strings"); | ||
|
||
|
||
|
||
|
||
|
||
|
||
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.toBuffer = toBuffer;exports.bufferToHex = bufferToHex;var _strings = require("./strings"); | ||
|
||
/** | ||
* @description Converts strings or numbers to buffer | ||
* @param {string|number|buffer} value | ||
* @param {String} [encoding='hex'] | ||
* @returns {Buffer} | ||
*/ | ||
function toBuffer(value, encoding = 'hex') { | ||
if (Buffer.isBuffer(value)) return value; | ||
if (typeof value === 'number') value = value.toString(); | ||
value = (0, _strings.remove0x)(value); | ||
if (!encoding && (0, _strings.isHexString)(value)) encoding = 'hex'; | ||
return Buffer.from(value, encoding); | ||
} | ||
|
||
/** | ||
* @description Converts buffer to hex string | ||
* @param {Buffer} buffer | ||
* @returns {String} | ||
*/ | ||
function bufferToHex(buffer) { | ||
return (0, _strings.add0x)(buffer.toString('hex')); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters