1 |
|
2 |
|
3 | import { u8aToU8a } from "../u8a/toU8a.js";
|
4 | import { isHex } from "./hex.js";
|
5 | import { isString } from "./string.js";
|
6 |
|
7 |
|
8 | function isAsciiStr(str) {
|
9 | const count = str.length;
|
10 |
|
11 | for (let i = 0; i < count; i++) {
|
12 | const b = str.charCodeAt(i);
|
13 |
|
14 | if (!(b < 127 && (b >= 32 || b === 10 || b === 9 || b === 13))) {
|
15 | return false;
|
16 | }
|
17 | }
|
18 |
|
19 | return true;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 | function isAsciiBytes(u8a) {
|
25 | const count = u8a.length;
|
26 |
|
27 | for (let i = 0; i < count; i++) {
|
28 | const b = u8a[i];
|
29 |
|
30 | if (!(b < 127 && (b >= 32 || b === 10 || b === 9 || b === 13))) {
|
31 | return false;
|
32 | }
|
33 | }
|
34 |
|
35 | return true;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 | export function isAscii(value) {
|
46 | return isString(value) ? isHex(value) ? isAsciiBytes(u8aToU8a(value)) : isAsciiStr(value) : value ? isAsciiBytes(value) : false;
|
47 | } |
\ | No newline at end of file |