Skip to content

Commit a41c8de

Browse files
feat: isISO15924 (#2215)
* feat: isISO15924 * test: isISO15924 * docs: add isISO15924 to README * refactor(isISO15924): update data sources * refactor(isISO15924): update data source reference * chore: fix linting
1 parent a7d5cff commit a41c8de

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Validator | Description
130130
**isISO6346(str)** | check if the string is a valid [ISO 6346](https://en.wikipedia.org/wiki/ISO_6346) shipping container identification.
131131
**isISO6391(str)** | check if the string is a valid [ISO 639-1][ISO 639-1] language code.
132132
**isISO8601(str [, options])** | check if the string is a valid [ISO 8601][ISO 8601] date. <br/>`options` is an object which defaults to `{ strict: false, strictSeparator: false }`. If `strict` is true, date strings with invalid dates like `2009-02-29` will be invalid. If `strictSeparator` is true, date strings with date and time separated by anything other than a T will be invalid.
133+
**isISO15924(str)** | check if the string is a valid [ISO 15924][ISO 15924] officially assigned script code.
133134
**isISO31661Alpha2(str)** | check if the string is a valid [ISO 3166-1 alpha-2][ISO 3166-1 alpha-2] officially assigned country code.
134135
**isISO31661Alpha3(str)** | check if the string is a valid [ISO 3166-1 alpha-3][ISO 3166-1 alpha-3] officially assigned country code.
135136
**isISO31661Numeric(str)** | check if the string is a valid [ISO 3166-1 numeric][ISO 3166-1 numeric] officially assigned country code.
@@ -252,6 +253,7 @@ This project is licensed under the [MIT](LICENSE). See the [LICENSE](LICENSE) fi
252253
[ISIN]: https://en.wikipedia.org/wiki/International_Securities_Identification_Number
253254
[ISO 639-1]: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
254255
[ISO 8601]: https://en.wikipedia.org/wiki/ISO_8601
256+
[ISO 15924]: https://en.wikipedia.org/wiki/ISO_15924
255257
[ISO 3166-1 alpha-2]: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
256258
[ISO 3166-1 alpha-3]: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
257259
[ISO 3166-1 numeric]: https://en.wikipedia.org/wiki/ISO_3166-1_numeric

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import { isISO6346, isFreightContainerID } from './lib/isISO6346';
9494
import isISO6391 from './lib/isISO6391';
9595
import isISO8601 from './lib/isISO8601';
9696
import isRFC3339 from './lib/isRFC3339';
97+
import isISO15924 from './lib/isISO15924';
9798
import isISO31661Alpha2 from './lib/isISO31661Alpha2';
9899
import isISO31661Alpha3 from './lib/isISO31661Alpha3';
99100
import isISO31661Numeric from './lib/isISO31661Numeric';
@@ -211,6 +212,7 @@ const validator = {
211212
isFreightContainerID,
212213
isISO6391,
213214
isISO8601,
215+
isISO15924,
214216
isRFC3339,
215217
isISO31661Alpha2,
216218
isISO31661Alpha3,

src/lib/isISO15924.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import assertString from './util/assertString';
2+
3+
// from https://www.unicode.org/iso15924/iso15924-codes.html
4+
const validISO15924Codes = new Set([
5+
'Adlm', 'Afak', 'Aghb', 'Ahom', 'Arab', 'Aran', 'Armi', 'Armn', 'Avst',
6+
'Bali', 'Bamu', 'Bass', 'Batk', 'Beng', 'Bhks', 'Blis', 'Bopo', 'Brah', 'Brai', 'Bugi', 'Buhd',
7+
'Cakm', 'Cans', 'Cari', 'Cham', 'Cher', 'Chis', 'Chrs', 'Cirt', 'Copt', 'Cpmn', 'Cprt', 'Cyrl', 'Cyrs',
8+
'Deva', 'Diak', 'Dogr', 'Dsrt', 'Dupl',
9+
'Egyd', 'Egyh', 'Egyp', 'Elba', 'Elym', 'Ethi',
10+
'Gara', 'Geok', 'Geor', 'Glag', 'Gong', 'Gonm', 'Goth', 'Gran', 'Grek', 'Gujr', 'Gukh', 'Guru',
11+
'Hanb', 'Hang', 'Hani', 'Hano', 'Hans', 'Hant', 'Hatr', 'Hebr', 'Hira', 'Hluw', 'Hmng', 'Hmnp', 'Hrkt', 'Hung',
12+
'Inds', 'Ital',
13+
'Jamo', 'Java', 'Jpan', 'Jurc',
14+
'Kali', 'Kana', 'Kawi', 'Khar', 'Khmr', 'Khoj', 'Kitl', 'Kits', 'Knda', 'Kore', 'Kpel', 'Krai', 'Kthi',
15+
'Lana', 'Laoo', 'Latf', 'Latg', 'Latn', 'Leke', 'Lepc', 'Limb', 'Lina', 'Linb', 'Lisu', 'Loma', 'Lyci', 'Lydi',
16+
'Mahj', 'Maka', 'Mand', 'Mani', 'Marc', 'Maya', 'Medf', 'Mend', 'Merc', 'Mero', 'Mlym', 'Modi', 'Mong', 'Moon', 'Mroo', 'Mtei', 'Mult', 'Mymr',
17+
'Nagm', 'Nand', 'Narb', 'Nbat', 'Newa', 'Nkdb', 'Nkgb', 'Nkoo', 'Nshu',
18+
'Ogam', 'Olck', 'Onao', 'Orkh', 'Orya', 'Osge', 'Osma', 'Ougr',
19+
'Palm', 'Pauc', 'Pcun', 'Pelm', 'Perm', 'Phag', 'Phli', 'Phlp', 'Phlv', 'Phnx', 'Plrd', 'Piqd', 'Prti', 'Psin',
20+
'Qaaa', 'Qaab', 'Qaac', 'Qaad', 'Qaae', 'Qaaf', 'Qaag', 'Qaah', 'Qaai', 'Qaaj', 'Qaak', 'Qaal', 'Qaam', 'Qaan', 'Qaao', 'Qaap', 'Qaaq', 'Qaar', 'Qaas', 'Qaat', 'Qaau', 'Qaav', 'Qaaw', 'Qaax', 'Qaay', 'Qaaz', 'Qaba', 'Qabb', 'Qabc', 'Qabd', 'Qabe', 'Qabf', 'Qabg', 'Qabh', 'Qabi', 'Qabj', 'Qabk', 'Qabl', 'Qabm', 'Qabn', 'Qabo', 'Qabp', 'Qabq', 'Qabr', 'Qabs', 'Qabt', 'Qabu', 'Qabv', 'Qabw', 'Qabx',
21+
'Ranj', 'Rjng', 'Rohg', 'Roro', 'Runr',
22+
'Samr', 'Sara', 'Sarb', 'Saur', 'Sgnw', 'Shaw', 'Shrd', 'Shui', 'Sidd', 'Sidt', 'Sind', 'Sinh', 'Sogd', 'Sogo', 'Sora', 'Soyo', 'Sund', 'Sunu', 'Sylo', 'Syrc', 'Syre', 'Syrj', 'Syrn',
23+
'Tagb', 'Takr', 'Tale', 'Talu', 'Taml', 'Tang', 'Tavt', 'Tayo', 'Telu', 'Teng', 'Tfng', 'Tglg', 'Thaa', 'Thai', 'Tibt', 'Tirh', 'Tnsa', 'Todr', 'Tols', 'Toto', 'Tutg',
24+
'Ugar',
25+
'Vaii', 'Visp', 'Vith',
26+
'Wara', 'Wcho', 'Wole',
27+
'Xpeo', 'Xsux',
28+
'Yezi', 'Yiii',
29+
'Zanb', 'Zinh', 'Zmth', 'Zsye', 'Zsym', 'Zxxx', 'Zyyy', 'Zzzz',
30+
]);
31+
32+
export default function isISO15924(str) {
33+
assertString(str);
34+
return validISO15924Codes.has(str);
35+
}
36+
37+
export const ScriptCodes = validISO15924Codes;

test/validators.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12131,6 +12131,28 @@ describe('Validators', () => {
1213112131
});
1213212132
});
1213312133

12134+
it('should validate ISO 15924 script codes', () => {
12135+
test({
12136+
validator: 'isISO15924',
12137+
valid: [
12138+
'Adlm',
12139+
'Bass',
12140+
'Copt',
12141+
'Dsrt',
12142+
'Egyd',
12143+
'Latn',
12144+
'Zzzz',
12145+
],
12146+
invalid: [
12147+
'',
12148+
'arab',
12149+
'zzzz',
12150+
'Qaby',
12151+
'Lati',
12152+
],
12153+
});
12154+
});
12155+
1213412156
it('should validate RFC 3339 dates', () => {
1213512157
test({
1213612158
validator: 'isRFC3339',

0 commit comments

Comments
 (0)