From 841b7a615e7f8b683ead1a065d5bffe8ed216754 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 10 Sep 2023 12:55:38 +0200 Subject: [PATCH 1/5] Add Esperanto to alpha.js --- src/lib/alpha.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/alpha.js b/src/lib/alpha.js index d540ed1cf..8c37934ff 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -35,6 +35,7 @@ export const alpha = { he: /^[א-ת]+$/, fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i, bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣৰৱ৲৳৴৵৶৷৸৹৺৻']+$/, + eo: /^[ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i, 'hi-IN': /^[\u0900-\u0961]+[\u0972-\u097F]*$/i, 'si-LK': /^[\u0D80-\u0DFF]+$/, }; @@ -75,6 +76,7 @@ export const alphanumeric = { he: /^[0-9א-ת]+$/, fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i, bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ০১২৩৪৫৬৭৮৯ৰৱ৲৳৴৵৶৷৸৹৺৻']+$/, + eo: /^[0-9ABCĈD-GĜHĤIJĴK-PRSŜTUŬVZ]+$/i, 'hi-IN': /^[\u0900-\u0963]+[\u0966-\u097F]*$/i, 'si-LK': /^[0-9\u0D80-\u0DFF]+$/, }; @@ -125,7 +127,7 @@ for (let locale, i = 0; i < bengaliLocales.length; i++) { // Source: https://en.wikipedia.org/wiki/Decimal_mark export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; export const commaDecimal = [ - 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'es-ES', 'fr-CA', 'fr-FR', + 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-ZM', 'eo', 'es-ES', 'fr-CA', 'fr-FR', 'id-ID', 'it-IT', 'ku-IQ', 'hi-IN', 'hu-HU', 'nb-NO', 'nn-NO', 'nl-NL', 'pl-PL', 'pt-PT', 'ru-RU', 'kk-KZ', 'si-LK', 'sl-SI', 'sr-RS@latin', 'sr-RS', 'sv-SE', 'tr-TR', 'uk-UA', 'vi-VN', ]; From 0d557babae8196b56479460b936505962ab0127f Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 10 Sep 2023 12:59:19 +0200 Subject: [PATCH 2/5] Add Esperanto (eo) to README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e00b7cfac..904d61787 100644 --- a/README.md +++ b/README.md @@ -91,8 +91,8 @@ Validator | Description **contains(str, seed [, options])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false, minOccurrences: 1 }`.
Options:
`ignoreCase`: Ignore case when doing comparison, default false.
`minOccurences`: Minimum number of occurrences for the seed in the string. Defaults to 1. **equals(str, comparison)** | check if the string matches the comparison. **isAfter(str [, options])** | check if the string is a date that is after the specified date.

`options` is an object that defaults to `{ comparisonDate: Date().toString() }`.
**Options:**
`comparisonDate`: Date to compare to. Defaults to `Date().toString()` (now). -**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).

`locale` is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'bn', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'kk-KZ', 'ko-KR', 'ja-JP', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA']` and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. `options` is an optional object that can be supplied with the following key(s): `ignore` which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. -**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

`locale` is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bn', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'kk-KZ', 'ko-KR', 'ja-JP','ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. `options` is an optional object that can be supplied with the following key(s): `ignore` which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlpha(str [, locale, options])** | check if the string contains only letters (a-zA-Z).

`locale` is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'bn', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'eo', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'kk-KZ', 'ko-KR', 'ja-JP', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA']` and defaults to `en-US`. Locale list is `validator.isAlphaLocales`. `options` is an optional object that can be supplied with the following key(s): `ignore` which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. +**isAlphanumeric(str [, locale, options])** | check if the string contains only letters and numbers (a-zA-Z0-9).

`locale` is one of `['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bn', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'eo', 'es-ES', 'fa-IR', 'fi-FI', 'fr-CA', 'fr-FR', 'he', 'hi-IN', 'hu-HU', 'it-IT', 'kk-KZ', 'ko-KR', 'ja-JP','ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'si-LK', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA']`) and defaults to `en-US`. Locale list is `validator.isAlphanumericLocales`. `options` is an optional object that can be supplied with the following key(s): `ignore` which can either be a String or RegExp of characters to be ignored e.g. " -" will ignore spaces and -'s. **isAscii(str)** | check if the string contains ASCII chars only. **isBase32(str [, options])** | check if the string is base32 encoded. `options` is optional and defaults to `{ crockford: false }`.
When `crockford` is true it tests the given base32 encoded string using [Crockford's base32 alternative][Crockford Base32]. **isBase58(str)** | check if the string is base58 encoded. From 322752e626030e9f67acb9f2a378b1a1b2e89ec4 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 10 Sep 2023 13:11:07 +0200 Subject: [PATCH 3/5] Add tests for Esperanto validation --- test/validators.test.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/validators.test.js b/test/validators.test.js index 6c68cd71a..7ab06a562 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -2048,6 +2048,23 @@ describe('Validators', () => { }); }); + it('should validate Esperanto alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['eo'], + valid: [ + 'eĥoŝanĝo ĉiuĵaŭde', + 'EĤOŜANĜO ĈIUĴAŬDE', + 'Esperanto', + 'Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj', + ], + invalid: [ + 'qwxyz', + '1887', + ], + }); + }); + it('should error on invalid locale', () => { test({ validator: 'isAlpha', @@ -2735,6 +2752,23 @@ describe('Validators', () => { }); }); + it('should validate Esperanto alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['eo'], + valid: [ + 'eĥoŝanĝo ĉiuĵaŭde 0123456789', + 'EĤOŜANĜO ĈIUĴAŬDE 0123456789', + 'Esperanto 1887', + 'Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj', + ], + invalid: [ + 'qwxyz', + 'qwxyz 123', + ], + }); + }); + it('should error on invalid locale', () => { test({ validator: 'isAlphanumeric', From e4de3d9575fd0903367ba2fd5e19065fbb9e4a33 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 10 Sep 2023 13:47:43 +0200 Subject: [PATCH 4/5] Fix tests --- test/validators.test.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/validators.test.js b/test/validators.test.js index 7ab06a562..15f7768b9 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -2053,14 +2053,15 @@ describe('Validators', () => { validator: 'isAlpha', args: ['eo'], valid: [ - 'eĥoŝanĝo ĉiuĵaŭde', - 'EĤOŜANĜO ĈIUĴAŬDE', + 'eĥoŝanĝoĉiuĵaŭde', + 'EĤOŜANĜOĈIUĴAŬDE', 'Esperanto', - 'Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj', + 'LaŭLudovikoZamenhofBongustasFreŝaĈeĥaManĝaĵoKunSpicoj', ], invalid: [ 'qwxyz', '1887', + 'qwxyz 1887', ], }); }); @@ -2757,10 +2758,10 @@ describe('Validators', () => { validator: 'isAlphanumeric', args: ['eo'], valid: [ - 'eĥoŝanĝo ĉiuĵaŭde 0123456789', - 'EĤOŜANĜO ĈIUĴAŬDE 0123456789', - 'Esperanto 1887', - 'Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj', + 'eĥoŝanĝoĉiuĵaŭde0123456789', + 'EĤOŜANĜOĈIUĴAŬDE0123456789', + 'Esperanto1887', + 'LaŭLudovikoZamenhofBongustasFreŝaĈeĥaManĝaĵoKunSpicoj', ], invalid: [ 'qwxyz', From 726c3ee7a838eb3da4541e16c0f9ca3941678c45 Mon Sep 17 00:00:00 2001 From: Robin van der Vliet Date: Sun, 12 Nov 2023 16:46:12 +0100 Subject: [PATCH 5/5] Update Esperanto tests --- test/validators.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/validators.test.js b/test/validators.test.js index 15f7768b9..f54599360 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -2053,6 +2053,7 @@ describe('Validators', () => { validator: 'isAlpha', args: ['eo'], valid: [ + 'saluton', 'eĥoŝanĝoĉiuĵaŭde', 'EĤOŜANĜOĈIUĴAŬDE', 'Esperanto', @@ -2758,6 +2759,7 @@ describe('Validators', () => { validator: 'isAlphanumeric', args: ['eo'], valid: [ + 'saluton', 'eĥoŝanĝoĉiuĵaŭde0123456789', 'EĤOŜANĜOĈIUĴAŬDE0123456789', 'Esperanto1887', @@ -2765,7 +2767,7 @@ describe('Validators', () => { ], invalid: [ 'qwxyz', - 'qwxyz 123', + 'qwxyz 1887', ], }); });