the editable site (validation-lab)
This commit is contained in:
commit
3ac81d5a52
13454 files changed
+2227005
No files matched your search
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @import {CompilePattern} from '../types.js'
|
||||
*/
|
||||
|
||||
/**
|
||||
* Compiles a pattern object into a regular expression.
|
||||
*
|
||||
* @type {CompilePattern}
|
||||
*/
|
||||
export function compilePattern(pattern) {
|
||||
if (!pattern._compiled) {
|
||||
const before =
|
||||
(pattern.atBreak ? '[\\r\\n][\\t ]*' : '') +
|
||||
(pattern.before ? '(?:' + pattern.before + ')' : '')
|
||||
|
||||
pattern._compiled = new RegExp(
|
||||
(pattern.beforeNode ? '^' : before ? '(' + before + ')' : '') +
|
||||
(/[$()*+.?[\\\]^{|}]/.test(pattern.character) ? '\\' : '') +
|
||||
pattern.character +
|
||||
(pattern.afterNode
|
||||
? '$'
|
||||
: pattern.after
|
||||
? '(?:' + pattern.after + ')'
|
||||
: ''),
|
||||
pattern.unicode ? 'gu' : 'g'
|
||||
)
|
||||
}
|
||||
|
||||
return pattern._compiled
|
||||
}
|
||||
Reference in new issue
Block a user