@routebot/constants 0.3.67 → 0.3.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/constants/login-code.constants.js +32 -0
- package/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Personal mobile login codes (SMS-less countries, e.g. US).
|
|
2
|
+
// Alphabet is intentionally restricted for easy typing across keyboards/locales:
|
|
3
|
+
// - No I, L, O, 0, 1 (ambiguous when read aloud / transcribed)
|
|
4
|
+
// - No Q, W (missing or awkward on many non-English layouts)
|
|
5
|
+
const LOGIN_CODE_ALPHABET = "ABCDEFGHJKMNPRSTUVYZ23456789";
|
|
6
|
+
const LOGIN_CODE_LENGTH = 8;
|
|
7
|
+
|
|
8
|
+
const LOGIN_CODE_PATTERN = new RegExp(`^[${LOGIN_CODE_ALPHABET}]{${LOGIN_CODE_LENGTH}}$`);
|
|
9
|
+
|
|
10
|
+
const normalizeLoginCode = (input) => {
|
|
11
|
+
const upper = (input || "").toString().toUpperCase();
|
|
12
|
+
let out = "";
|
|
13
|
+
for (const ch of upper) {
|
|
14
|
+
if (LOGIN_CODE_ALPHABET.includes(ch)) {
|
|
15
|
+
out += ch;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const isValidLoginCode = (code) => {
|
|
22
|
+
if (code == null || code === "") return true;
|
|
23
|
+
return LOGIN_CODE_PATTERN.test(code);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
LOGIN_CODE_ALPHABET,
|
|
28
|
+
LOGIN_CODE_LENGTH,
|
|
29
|
+
LOGIN_CODE_PATTERN,
|
|
30
|
+
normalizeLoginCode,
|
|
31
|
+
isValidLoginCode,
|
|
32
|
+
};
|
package/index.js
CHANGED