Skip to content

Commit 3608e89

Browse files
committed
feat: add regex flags and finish ignoreValues
1 parent bb3a929 commit 3608e89

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/index.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ const reVar = /^-?(?:@.+|(?:(?:[a-zA-Z_-]|[^\x00-\x7F])+(?:[a-zA-Z0-9_-]|[^\x00-
4444
* @default
4545
*/
4646
const reFunc = /^(?!var\(\s*--)[\s\S]+\([\s\S]*\)$/
47-
const isRegexString = (value) => value.charAt(0) === '/' && value.slice(-1) === '/'
48-
const getRegexString = (value) => value.slice(1, -1)
49-
const stringToRegex = (value) => new RegExp(getRegexString(value))
50-
const mapIgnoreValue = (ignoreValue) => (isRegexString(ignoreValue) ? getRegexString(ignoreValue) : `^${ignoreValue}$`)
47+
const reRegex = /^\/(.*)\/([a-zA-Z]*)$/
48+
const isRegexString = (value) => reRegex.test(value)
49+
const getRegexString = (value) => value.match(reRegex).slice(1)
50+
const stringToRegex = (value) => new RegExp(...getRegexString(value))
51+
const mapIgnoreValue = (ignoreValue) => (isRegexString(ignoreValue) ? stringToRegex(ignoreValue) : new RegExp(`^${ignoreValue}$`))
5152

5253
/**
5354
* A rule function essentially returns a little PostCSS plugin.
@@ -163,19 +164,19 @@ const ruleFunction = (properties, options, context = {}) => (root, result) => {
163164
}
164165

165166
if (ignoreValues && (!validVar || !validFunc || !validKeyword)) {
166-
let reValue = reValues[property]
167+
let reValueList = reValues[property]
167168

168-
if (!reValue) {
169-
const ignoreKeyword = getIgnoredValues(ignoreValues, property)
169+
if (!reValueList) {
170+
const ignoreValue = getIgnoredValues(ignoreValues, property)
170171

171-
if (ignoreKeyword) {
172-
reValue = new RegExp(ignoreValues.map(mapIgnoreValue).join('|'))
173-
reValues[property] = reValue
172+
if (ignoreValue) {
173+
reValueList = ignoreValue.map(mapIgnoreValue)
174+
reValues[property] = reValueList
174175
}
175176
}
176177

177-
if (reValue) {
178-
validValue = reValue.test(value)
178+
if (reValueList) {
179+
validValue = reValueList.filter((reValue) => reValue.test(value)).length > 0
179180
}
180181
}
181182

0 commit comments

Comments
 (0)