From de834d38b03a10206f009cdb5c3eb9644b1d426c Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 31 Oct 2024 19:51:08 +0530 Subject: [PATCH 1/3] fix getOTPRegexForValueType util function for OTPValueType.ALPHANUMERIC_UPPER value --- src/ts/utils/regex.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ts/utils/regex.ts b/src/ts/utils/regex.ts index 05f8599..25199f8 100644 --- a/src/ts/utils/regex.ts +++ b/src/ts/utils/regex.ts @@ -30,7 +30,7 @@ export function getOTPRegexForValueType(valueType: OTPValueType): RegExp { return /[^a-z0-9]/g; // Match anything except alphanumeric lower characters case OTPValueType.ALPHANUMERIC_UPPER: - return /[^A-Za-z0-9]/g; // Match anything except alphanumeric upper characters + return /[^A-Z0-9]/g; // Match anything except alphanumeric upper characters // throw error for invalid type default: From 70bec2192aacdad8bd00fe58de9869b2d27f7152 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 31 Oct 2024 19:51:46 +0530 Subject: [PATCH 2/3] Add unit test for getOTPRegexForValueType util function --- tests/utils/regex.ts | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/utils/regex.ts diff --git a/tests/utils/regex.ts b/tests/utils/regex.ts new file mode 100644 index 0000000..2ba3eb6 --- /dev/null +++ b/tests/utils/regex.ts @@ -0,0 +1,46 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; +import { getOTPRegexForValueType, OTPValueType } from '../../src/ts/main'; + +describe('Test getOTPRegexForValueType function', () => { + it('should return valid regex for valid value type', () => { + const numericRegex = getOTPRegexForValueType(OTPValueType.NUMERIC); + expect(numericRegex.toString()).to.equal('/[^0-9]/g'); + + const alphabeticRegex = getOTPRegexForValueType(OTPValueType.ALPHABETIC); + expect(alphabeticRegex.toString()).to.equal('/[^A-Za-z]/g'); + + const alphabeticLowerRegex = getOTPRegexForValueType( + OTPValueType.ALPHABETIC_LOWER + ); + expect(alphabeticLowerRegex.toString()).to.equal('/[^a-z]/g'); + + const alphabeticUpperRegex = getOTPRegexForValueType( + OTPValueType.ALPHABETIC_UPPER + ); + expect(alphabeticUpperRegex.toString()).to.equal('/[^A-Z]/g'); + + const alphanumericRegex = getOTPRegexForValueType( + OTPValueType.ALPHANUMERIC + ); + expect(alphanumericRegex.toString()).to.equal('/[^A-Za-z0-9]/g'); + + const alphanumericLowerRegex = getOTPRegexForValueType( + OTPValueType.ALPHANUMERIC_LOWER + ); + expect(alphanumericLowerRegex.toString()).to.equal('/[^a-z0-9]/g'); + + const alphanumericUpperRegex = getOTPRegexForValueType( + OTPValueType.ALPHANUMERIC_UPPER + ); + expect(alphanumericUpperRegex.toString()).to.equal('/[^A-Z0-9]/g'); + }); + + it('should throw error for invalid value type', () => { + // @ts-ignore + expect(() => getOTPRegexForValueType('invalid')).to.throw( + Error, + 'Invalid OTP field value type' + ); + }); +}); From 988e05e401a0ad4ed161a447d0f2ec5180481db0 Mon Sep 17 00:00:00 2001 From: Satyam Seth Date: Thu, 31 Oct 2024 19:51:56 +0530 Subject: [PATCH 3/3] 1.0.5 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 213677f..2f2a447 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@satyam-seth/otp-field", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@satyam-seth/otp-field", - "version": "1.0.4", + "version": "1.0.5", "license": "ISC", "devDependencies": { "@types/chai": "^4.3.6", diff --git a/package.json b/package.json index ef2daea..80740d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@satyam-seth/otp-field", - "version": "1.0.4", + "version": "1.0.5", "description": "A configurable OTP field built using TypeScript and SCSS", "repository": { "type": "git",