1 |
|
2 |
|
3 | import { u8aToU8a } from "../u8a/toU8a.js";
|
4 | import { isHex } from "./hex.js";
|
5 | import { isString } from "./string.js";
|
6 | const FORMAT = [9, 10, 13];
|
7 |
|
8 |
|
9 | function isAsciiByte(b) {
|
10 | return b < 127 && (b >= 32 || FORMAT.includes(b));
|
11 | }
|
12 |
|
13 | function isAsciiChar(s) {
|
14 | return isAsciiByte(s.charCodeAt(0));
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export function isAscii(value) {
|
25 | const isStringIn = isString(value);
|
26 |
|
27 | if (value) {
|
28 | return isStringIn && !isHex(value) ? value.toString().split('').every(isAsciiChar) : u8aToU8a(value).every(isAsciiByte);
|
29 | }
|
30 |
|
31 | return isStringIn;
|
32 | } |
\ | No newline at end of file |