UNPKG

1.61 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.assertIsString = exports.assertIsArray = exports.assertIsBuffer = exports.assertIsHexString = void 0;
4const internal_1 = require("./internal");
5/**
6 * Throws if a string is not hex prefixed
7 * @param {string} input string to check hex prefix of
8 */
9const assertIsHexString = function (input) {
10 if (!(0, internal_1.isHexString)(input)) {
11 const msg = `This method only supports 0x-prefixed hex strings but input was: ${input}`;
12 throw new Error(msg);
13 }
14};
15exports.assertIsHexString = assertIsHexString;
16/**
17 * Throws if input is not a buffer
18 * @param {Buffer} input value to check
19 */
20const assertIsBuffer = function (input) {
21 if (!Buffer.isBuffer(input)) {
22 const msg = `This method only supports Buffer but input was: ${input}`;
23 throw new Error(msg);
24 }
25};
26exports.assertIsBuffer = assertIsBuffer;
27/**
28 * Throws if input is not an array
29 * @param {number[]} input value to check
30 */
31const assertIsArray = function (input) {
32 if (!Array.isArray(input)) {
33 const msg = `This method only supports number arrays but input was: ${input}`;
34 throw new Error(msg);
35 }
36};
37exports.assertIsArray = assertIsArray;
38/**
39 * Throws if input is not a string
40 * @param {string} input value to check
41 */
42const assertIsString = function (input) {
43 if (typeof input !== 'string') {
44 const msg = `This method only supports strings but input was: ${input}`;
45 throw new Error(msg);
46 }
47};
48exports.assertIsString = assertIsString;
49//# sourceMappingURL=helpers.js.map
\No newline at end of file