1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.isAscii = void 0;
|
4 | const toU8a_js_1 = require("../u8a/toU8a.js");
|
5 | const hex_js_1 = require("./hex.js");
|
6 | const string_js_1 = require("./string.js");
|
7 |
|
8 | function isAsciiStr(str) {
|
9 | for (let i = 0, count = str.length; i < count; i++) {
|
10 | const b = str.charCodeAt(i);
|
11 |
|
12 | if (b < 32 || b > 126) {
|
13 | return false;
|
14 | }
|
15 | }
|
16 | return true;
|
17 | }
|
18 |
|
19 | function isAsciiBytes(u8a) {
|
20 | for (let i = 0, count = u8a.length; i < count; i++) {
|
21 | const b = u8a[i] | 0;
|
22 |
|
23 | if (b < 32 || b > 126) {
|
24 | return false;
|
25 | }
|
26 | }
|
27 | return true;
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | function isAscii(value) {
|
36 | return (0, string_js_1.isString)(value)
|
37 | ? (0, hex_js_1.isHex)(value)
|
38 | ? isAsciiBytes((0, toU8a_js_1.u8aToU8a)(value))
|
39 | : isAsciiStr(value)
|
40 | : value
|
41 | ? isAsciiBytes(value)
|
42 | : false;
|
43 | }
|
44 | exports.isAscii = isAscii;
|