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