-
Notifications
You must be signed in to change notification settings - Fork 7
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
13 changed files
with
888 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import regexData from '../data/json/class_regex.json' | ||
|
||
// Function to get the RegExp | ||
export function getRegExp(name) { | ||
if (!regexData.class_chars[name]) { | ||
throw new Error(`Invalid class name: ${name}`) | ||
} | ||
|
||
const charNames = regexData.class_chars[name] | ||
if (charNames.length === 0) { | ||
throw new Error(`No character definitions for class: ${name}`) | ||
} | ||
|
||
// Join the individual character regex patterns | ||
const pattern = charNames | ||
.map((charName) => { | ||
if (!regexData.char_regex[charName]) { | ||
throw new Error(`Invalid character name: ${charName}`) | ||
} | ||
return regexData.char_regex[charName] | ||
}) | ||
.join('|') | ||
|
||
return new RegExp(`^(?:${pattern})+$`) | ||
} |
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,21 @@ | ||
import classRegex from '../data/json/class_regex.json' | ||
|
||
export class RegexClass { | ||
// Static method that returns the RegExp object | ||
|
||
static getValueClassChars(name) { | ||
let classChars | ||
if (Array.isArray(classRegex.class_chars[name]) && classRegex.class_chars[name].length > 0) { | ||
classChars = | ||
'^(?:' + classRegex.class_chars[name].map((charClass) => classRegex.char_regex[charClass]).join('|') + ')+$' | ||
} else { | ||
classChars = '^.+$' // Any non-empty line or string. | ||
} | ||
return new RegExp(classChars) | ||
} | ||
|
||
static testRegex(name, value) { | ||
const regex = RegexClass.getValueClassChars(name) | ||
return regex.test(value) | ||
} | ||
} |
Oops, something went wrong.