-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
85 additions
and
19 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,39 @@ | ||
import { isValid_File_Extension } from '../file-extension'; | ||
|
||
describe('File Extension Validation', () => { | ||
it('should return true for a valid file extension', () => { | ||
const fileName = 'document.pdf'; | ||
const allowedExtensions = ['pdf', 'doc', 'txt']; | ||
expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(true); | ||
}); | ||
|
||
it('should return false for an invalid file extension', () => { | ||
const fileName = 'image.jpeg'; | ||
const allowedExtensions = ['pdf', 'doc', 'txt']; | ||
expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); | ||
}); | ||
|
||
it('should return false for a file with no extension', () => { | ||
const fileName = 'file'; | ||
const allowedExtensions = ['pdf', 'doc', 'txt']; | ||
expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); | ||
}); | ||
|
||
it('should return true for a valid file extension with mixed case', () => { | ||
const fileName = 'presentation.PPT'; | ||
const allowedExtensions = ['ppt', 'doc', 'txt']; | ||
expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(true); | ||
}); | ||
|
||
it('should return false for an empty file name', () => { | ||
const fileName = ''; | ||
const allowedExtensions = ['pdf', 'doc', 'txt']; | ||
expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); | ||
}); | ||
|
||
it('should return false for an empty allowed extensions list', () => { | ||
const fileName = 'document.pdf'; | ||
const allowedExtensions: string[] = []; | ||
expect(isValid_File_Extension(fileName, allowedExtensions)).toBe(false); | ||
}); | ||
}); |
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,13 @@ | ||
/** | ||
* | ||
* @param fileName | ||
* @param allowedExtensions | ||
* @returns | ||
*/ | ||
export const isValid_File_Extension = ( | ||
fileName: string, | ||
allowedExtensions: string[] | ||
): boolean => { | ||
const extension = fileName.split('.').pop()?.toLowerCase() || ''; | ||
return allowedExtensions.includes(extension); | ||
}; |
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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
/** | ||
* A hex code, short for hexadecimal code, is a way of representing numbers using a base-16 numeral system. | ||
* @param color | ||
* @returns | ||
* @param color | ||
* @returns | ||
*/ | ||
export const isValid_Hex_Color = (color: string): boolean => { | ||
const hexRegex = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; | ||
return hexRegex.test(color); | ||
} | ||
|
||
const hexRegex = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; | ||
return hexRegex.test(color); | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
export * from './aadhaar'; | ||
export * from './credit-card'; | ||
export * from './email'; | ||
export * from './file-extension'; | ||
export * from './ip'; | ||
export * from './hex-color'; | ||
export * from './postal-zip' | ||
export * from './postal-zip'; | ||
export * from './ssn'; | ||
export * from './url'; |
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