From 58cc9189a5c7e30f00c2c826a47c725903730300 Mon Sep 17 00:00:00 2001 From: rak810 <> Date: Thu, 27 May 2021 10:04:29 +0000 Subject: [PATCH 1/3] feat: added support for Bengali language --- .gitignore | 1 + README.md | 4 ++-- src/lib/alpha.js | 21 ++++++++++++++------- test/validators.js | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 9c8fa47bf..4d3907bb5 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ yarn.lock /index.js validator.js validator.min.js +.replit diff --git a/README.md b/README.md index 67496d8b5..ea6544f5b 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,8 @@ Validator | Description **contains(str, seed [, options ])** | check if the string contains the seed.

`options` is an object that defaults to `{ ignoreCase: false}`.
`ignoreCase` specified whether the case of the substring be same or not. **equals(str, comparison)** | check if the string matches the comparison. **isAfter(str [, date])** | check if the string is a date that's after the specified date (defaults to 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', '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', 'fr-CA', 'fr-FR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', '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', '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', 'fr-CA', 'fr-FR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', '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-BD', 'bn-IN', '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', 'fr-CA', 'fr-FR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', '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', 'bg-BG','bn-BD', 'bn-IN', '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', 'fr-CA', 'fr-FR', 'he', 'hu-HU', 'it-IT', 'ku-IQ', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sk-SK', 'sr-RS', 'sr-RS@latin', 'sv-SE', '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)** | check if a string is base32 encoded. **isBase58(str)** | check if a string is base58 encoded. diff --git a/src/lib/alpha.js b/src/lib/alpha.js index c898cacfe..666b8d61e 100644 --- a/src/lib/alpha.js +++ b/src/lib/alpha.js @@ -30,6 +30,7 @@ export const alpha = { ar: /^[ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, he: /^[א-ת]+$/, fa: /^['آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی']+$/i, + bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣৰৱ৲৳৴৵৶৷৸৹৺৻']+$/, }; export const alphanumeric = { @@ -63,6 +64,7 @@ export const alphanumeric = { ar: /^[٠١٢٣٤٥٦٧٨٩0-9ءآأؤإئابةتثجحخدذرزسشصضطظعغفقكلمنهوىيًٌٍَُِّْٰ]+$/, he: /^[0-9א-ת]+$/, fa: /^['0-9آاءأؤئبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهةی۱۲۳۴۵۶۷۸۹۰']+$/i, + bn: /^['ঀঁংঃঅআইঈউঊঋঌএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহ়ঽািীুূৃৄেৈোৌ্ৎৗড়ঢ়য়ৠৡৢৣ০১২৩৪৫৬৭৮৯ৰৱ৲৳৴৵৶৷৸৹৺৻']+$/, }; export const decimal = { @@ -81,10 +83,8 @@ for (let locale, i = 0; i < englishLocales.length; i++) { } // Source: http://www.localeplanet.com/java/ -export const arabicLocales = [ - 'AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', - 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE', -]; +export const arabicLocales = ['AE', 'BH', 'DZ', 'EG', 'IQ', 'JO', 'KW', 'LB', 'LY', + 'MA', 'QM', 'QA', 'SA', 'SD', 'SY', 'TN', 'YE']; for (let locale, i = 0; i < arabicLocales.length; i++) { locale = `ar-${arabicLocales[i]}`; @@ -93,9 +93,7 @@ for (let locale, i = 0; i < arabicLocales.length; i++) { decimal[locale] = decimal.ar; } -export const farsiLocales = [ - 'IR', 'AF', -]; +export const farsiLocales = ['IR', 'AF']; for (let locale, i = 0; i < farsiLocales.length; i++) { locale = `fa-${farsiLocales[i]}`; @@ -103,6 +101,15 @@ for (let locale, i = 0; i < farsiLocales.length; i++) { decimal[locale] = decimal.ar; } +export const bengaliLocales = ['BD', 'IN']; + +for (let locale, i = 0; i < bengaliLocales.length; i++) { + locale = `bn-${bengaliLocales[i]}`; + alpha[locale] = alpha.bn; + alphanumeric[locale] = alphanumeric.bn; + decimal[locale] = decimal['en-US']; +} + // Source: https://en.wikipedia.org/wiki/Decimal_mark export const dotDecimal = ['ar-EG', 'ar-LB', 'ar-LY']; export const commaDecimal = [ diff --git a/test/validators.js b/test/validators.js index c7119487b..8e5f3920b 100644 --- a/test/validators.js +++ b/test/validators.js @@ -1172,6 +1172,26 @@ describe('Validators', () => { }); }); + it('should validate Bengali alpha strings', () => { + test({ + validator: 'isAlpha', + args: ['bn-BD'], + valid: [ + 'অয়াওর', + 'ফগফদ্রত', + 'ফদ্ম্যতভ', + 'বেরেওভচনভন', + 'আমারবাসগা', + ], + invalid: [ + 'দাস২৩৪', + ' দ্গফহ্নভ ', + '', + '(গফদ)', + ], + }); + }); + it('should validate czech alpha strings', () => { test({ validator: 'isAlpha', @@ -1786,6 +1806,25 @@ describe('Validators', () => { }); }); + it('should validate Bengali alphanumeric strings', () => { + test({ + validator: 'isAlphanumeric', + args: ['bn-BD'], + valid: [ + 'দ্গজ্ঞহ্রত্য১২৩', + 'দ্গগফ৮৯০', + 'চব৩৬৫ভবচ', + '১২৩৪', + '৩৪২৩৪দফজ্ঞদফ', + ], + invalid: [ + ' ', + '১২৩ ', + 'hel৩২0', + ], + }); + }); + it('should validate czech alphanumeric strings', () => { test({ validator: 'isAlphanumeric', From 74ea0fbd804dd6770d2f4e9bde8ea675075eb72a Mon Sep 17 00:00:00 2001 From: rak810 <> Date: Thu, 27 May 2021 10:06:36 +0000 Subject: [PATCH 2/3] removed local changes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4d3907bb5..86aaedee1 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,4 @@ yarn.lock /index.js validator.js validator.min.js -.replit + From 42ecd6c1a9233708bce552763dbe45300d3024f8 Mon Sep 17 00:00:00 2001 From: rak810 Date: Thu, 18 Nov 2021 00:44:47 +0600 Subject: [PATCH 3/3] Changes Made in Branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea6544f5b..dd20a7f71 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # validator.js - +# Changes made - 1707074 [![NPM version][npm-image]][npm-url] [![CI][ci-image]][ci-url] [![Coverage][codecov-image]][codecov-url]