-
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
1 parent
a568296
commit 692f769
Showing
14 changed files
with
119 additions
and
18 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
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
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
2 changes: 1 addition & 1 deletion
2
src/validation-schema.ts → src/model/validation-schema.model.ts
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
File renamed without changes.
File renamed without changes.
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,29 @@ | ||
import { convertStringToRegExp } from './regex.utils'; | ||
describe('RegExpUtils', () => { | ||
describe('convertStringToRegExp', () => { | ||
|
||
it('should convert a string into a regular expression', () => { | ||
expect(convertStringToRegExp('/abc/').toString()).toBe('/abc/'); | ||
expect(convertStringToRegExp('/abc/g').toString()).toBe('/abc/g'); | ||
expect(convertStringToRegExp('/abc/gimuy').toString()).toBe('/abc/gimuy'); | ||
expect(convertStringToRegExp('/[abc]+\\w*/gimuy').toString()).toBe('/[abc]+\\w*/gimuy'); | ||
}); | ||
|
||
it('should throw an error on invalid strings', () => { | ||
expect.assertions(4); | ||
const test = (pattern: string) => { | ||
try { | ||
convertStringToRegExp(pattern); | ||
} catch (err) { | ||
expect(err).toBeDefined(); | ||
} | ||
}; | ||
|
||
test(''); | ||
test('//'); | ||
test('/'); | ||
test('/abc/xyvvx'); | ||
}); | ||
|
||
}); | ||
}); |
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,16 @@ | ||
/** | ||
* Convert a string to a regular expression. The string should be formed like a RegExp | ||
* literal. | ||
* @param pattern | ||
* @returns {RegExp} | ||
*/ | ||
export function convertStringToRegExp(pattern: string): RegExp { | ||
const regExpPattern = /^\/(.+)\/([gimuy]*)$/; | ||
const args: string[] | null = regExpPattern.exec(pattern); | ||
if (args === null) { | ||
throw Error(`Invalid regExp string "${pattern}"`); | ||
} | ||
const body = args[1] || ''; | ||
const flags = args[2]; | ||
return new RegExp(body, flags); | ||
} |