@zlattice/lattice-js
Version:
Lattice blockchain TypeScript SDK with dual module support (CJS + ESM)
25 lines • 863 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.stripHexPrefix = stripHexPrefix;
exports.addHexPrefix = addHexPrefix;
const constants_1 = require("../common/constants.js");
/**
* Strip the hex prefix from a hex string
* @param hex - The hex string to strip the prefix from
* @returns The hex string without the prefix
*/
function stripHexPrefix(hex) {
/* if (!isHexString(hex)) {
throw new Error("Invalid hex string");
} */
return hex.startsWith(constants_1.HEX_PREFIX) ? hex.slice(constants_1.HEX_PREFIX.length) : hex;
}
/**
* Ensure the hex string has 0x prefix
* @param hex - The original hex string
* @returns The hex string with 0x prefix
*/
function addHexPrefix(hex) {
return hex.startsWith(constants_1.HEX_PREFIX) ? hex : constants_1.HEX_PREFIX + hex;
}
//# sourceMappingURL=string.js.map