-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b42b0f
commit d843c51
Showing
13 changed files
with
449 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { VPA } from '../src/vpa'; | ||
|
||
describe('VPA', () => { | ||
const tests: [string, boolean][] = [ | ||
['amazing-uid@upi', true], | ||
['random9999@upi', true], | ||
['vpa_with_underscore@upi', true], | ||
['vpa-with-hyphen@upi', true], | ||
['vpa.with.dot@upi', true], | ||
['9876543210@upi', true], | ||
|
||
['it@upi', false], | ||
['with#hash@upi', false], | ||
['with space@upi', false], | ||
['with@at@upi', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], | ||
]; | ||
test.each(tests)(`Check %s => %s`, (value, expected) => { | ||
expect(VPA.validate(value)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('VPA with options: { maxLength: 20 }', () => { | ||
const tests: [string, boolean][] = [ | ||
['amazing-uid@upi', true], | ||
['random9999@upi', true], | ||
|
||
['vpa_with_underscore@upi', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], | ||
]; | ||
test.each(tests)(`Check %s => %s`, (value, expected) => { | ||
expect(VPA.validate(value, { maxLength: 20 })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('VPA with options: { handles: true }', () => { | ||
const tests: [string, boolean][] = [ | ||
['amazing-uid@upi', true], | ||
['random9999@upi', true], | ||
['yesbank@ybl', true], | ||
['axisbank@okaxis', true], | ||
|
||
['axisbank@bankaxis', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], | ||
]; | ||
test.each(tests)(`Check %s => %s`, (value, expected) => { | ||
expect(VPA.validate(value, { handles: true })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('VPA with options: { handles: ["bankaxis", "superbank"] }', () => { | ||
const tests: [string, boolean][] = [ | ||
['amazing-uid@upi', true], | ||
['random9999@upi', true], | ||
['yesbank@ybl', true], | ||
['axisbank@okaxis', true], | ||
['axisbank@bankaxis', true], | ||
['super-vpa@superbank', true], | ||
|
||
['super-vpa@banksuper', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@superbank', false], | ||
]; | ||
const handles = ['bankaxis', 'superbank']; | ||
test.each(tests)(`Check %s => %s`, (value, expected) => { | ||
expect(VPA.validate(value, { handles })).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('VPA with options: { maxLength: 20, handles: ["bankaxis", "superbank"] }', () => { | ||
const tests: [string, boolean][] = [ | ||
['amazing-uid@upi', true], | ||
['random9999@upi', true], | ||
['yesbank@ybl', true], | ||
['axisbank@okaxis', true], | ||
['axisbank@bankaxis', true], | ||
['super-vpa@superbank', true], | ||
|
||
['super-vpa@banksuper', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@upi', false], | ||
['very-long-upi-id-or-vpa-should-not-pass-the-validation@superbank', false], | ||
]; | ||
const handles = ['bankaxis', 'superbank']; | ||
test.each(tests)(`Check %s => %s`, (value, expected) => { | ||
expect(VPA.validate(value, { maxLength: 20, handles })).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
[ | ||
"abfspay", | ||
"airtel", | ||
"airtelpaymentsbank", | ||
"albk", | ||
"allahabadbank", | ||
"allbank", | ||
"andb", | ||
"apb", | ||
"apl", | ||
"axis", | ||
"axisb", | ||
"axisbank", | ||
"axisgo", | ||
"bandhan", | ||
"barodampay", | ||
"barodapay", | ||
"boi", | ||
"cbin", | ||
"cboi", | ||
"centralbank", | ||
"cmsidfc", | ||
"cnrb", | ||
"csbcash", | ||
"csbpay", | ||
"cub", | ||
"dbs", | ||
"dcb", | ||
"dcbbank", | ||
"denabank", | ||
"dlb", | ||
"eazypay", | ||
"equitas", | ||
"ezeepay", | ||
"fbl", | ||
"federal", | ||
"finobank", | ||
"hdfcbank", | ||
"hdfcbankjd", | ||
"hsbc", | ||
"icici", | ||
"idbi", | ||
"idbibank", | ||
"idfc", | ||
"idfcbank", | ||
"idfcnetc", | ||
"ikwik", | ||
"imobile", | ||
"indbank", | ||
"indianbank", | ||
"indianbk", | ||
"indus", | ||
"indusind", | ||
"iob", | ||
"jkb", | ||
"jsbp", | ||
"karb", | ||
"karurvysyabank", | ||
"kaypay", | ||
"kbl", | ||
"kbl052", | ||
"kmb", | ||
"kmbl", | ||
"kotak", | ||
"kvb", | ||
"kvbank", | ||
"lime", | ||
"lvb", | ||
"lvbank", | ||
"mahb", | ||
"myicici", | ||
"obc", | ||
"okaxis", | ||
"okhdfcbank", | ||
"okicici", | ||
"oksbi", | ||
"paytm", | ||
"payzapp", | ||
"pingpay", | ||
"pnb", | ||
"pockets", | ||
"psb", | ||
"purz", | ||
"rajgovhdfcbank", | ||
"rbl", | ||
"sbi", | ||
"sc", | ||
"scb", | ||
"scbl", | ||
"scmobile", | ||
"sib", | ||
"srcb", | ||
"synd", | ||
"syndbank", | ||
"syndicate", | ||
"tjsb", | ||
"ubi", | ||
"uboi", | ||
"uco", | ||
"unionbank", | ||
"unionbankofindia", | ||
"united", | ||
"utbi", | ||
"vijayabank", | ||
"vijb", | ||
"vjb", | ||
"ybl", | ||
"yesbank", | ||
"yesbankltd", | ||
"freecharge", | ||
"upi" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export declare type VpaValidationOptions = { | ||
maxLength?: number; | ||
handles?: boolean | string[]; | ||
}; | ||
export declare class VPA { | ||
static defaultVpaHandles: string[] | undefined; | ||
static validate(value: string, options?: VpaValidationOptions): boolean; | ||
static getDefaultVpaHandles(): string[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ValidationOptionsDefaults = { | ||
maxLength: 50, | ||
handles: true, | ||
}; | ||
class VPA { | ||
static validate(value, options) { | ||
options = Object.assign({}, ValidationOptionsDefaults, options); | ||
const regex = /^[a-z0-9_.-]{3,}@[a-z]{3,}$/i; | ||
let isValidFormat = regex.test(value) && value.length <= options.maxLength; | ||
if (!isValidFormat) { | ||
return false; | ||
} | ||
if (options.handles) { | ||
const defaultHandles = VPA.getDefaultVpaHandles(); | ||
options.handles = (options.handles === true | ||
? defaultHandles | ||
: [...options.handles, ...defaultHandles]); | ||
const handle = value.split('@')[1]; | ||
isValidFormat = options.handles.indexOf(handle) >= 0; | ||
} | ||
return isValidFormat; | ||
} | ||
static getDefaultVpaHandles() { | ||
if (VPA.defaultVpaHandles === undefined) { | ||
VPA.defaultVpaHandles = require('./vpa-handles.json'); | ||
} | ||
return VPA.defaultVpaHandles; | ||
} | ||
} | ||
exports.VPA = VPA; | ||
VPA.defaultVpaHandles = undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,9 @@ | |
"GST", | ||
"GSTIN", | ||
"vehicle registration", | ||
"vpa", | ||
"upi", | ||
"upi id", | ||
"india", | ||
"validators", | ||
"validation" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.