@nervosnetwork/ckb-sdk-utils
Version:
Utils module of @nervosnetwork/ckb-sdk-core
29 lines • 1.09 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertToBeHexStringOrBigint = exports.assertToBeHexString = void 0;
const index_js_1 = require("./exceptions/index.js");
const assertToBeHexString = (value) => {
if (typeof value !== 'string' || !value.startsWith('0x') || Number.isNaN(+value)) {
throw new index_js_1.HexStringException(value);
}
return true;
};
exports.assertToBeHexString = assertToBeHexString;
const assertToBeHexStringOrBigint = (value) => {
if (typeof value === 'bigint') {
return true;
}
if (typeof value === 'string') {
if (!value.startsWith('0x')) {
throw new index_js_1.HexStringWithout0xException(value);
}
return true;
}
throw new TypeError(`${value} should be type of string or bigint`);
};
exports.assertToBeHexStringOrBigint = assertToBeHexStringOrBigint;
exports.default = {
assertToBeHexString: exports.assertToBeHexString,
assertToBeHexStringOrBigint: exports.assertToBeHexStringOrBigint,
};
//# sourceMappingURL=validators.js.map
;