Skip to content

Commit

Permalink
feat: use alternative of str.match
Browse files Browse the repository at this point in the history
  • Loading branch information
MellowCo committed Apr 5, 2024
1 parent ff38db3 commit 3357fd7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/rules/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const cssProperty: Rule[] = [

const [prop, ...rest] = body.split(':')
const value = rest.join(':')
if (!isURI(body) && prop.match(/^[a-z-]+$/) && isValidCSSBody(value)) {
if (!isURI(body) && /^[a-z-]+$/.test(prop) && isValidCSSBody(value)) {
const parsed = h.bracket(`[${value}]`)
if (parsed)
return { [prop]: parsed }
Expand Down
8 changes: 4 additions & 4 deletions src/utils/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function auto(str: string) {
export function rem(str: string) {
if (!str)
return
if (str.match(unitOnlyRE))
if (unitOnlyRE.test(str))
return `1${str}`
const match = str.match(numberWithUnitRE)
if (!match)
Expand All @@ -60,7 +60,7 @@ export function rem(str: string) {
}

export function remToRpx(str: string) {
if (str.match(unitOnlyRE))
if (unitOnlyRE.test(str))
return `1${str}`
const match = str.match(numberWithUnitRE)
if (!match)
Expand All @@ -78,7 +78,7 @@ export function remToRpx(str: string) {

// 小程序 rpx
export function rpx(str: string) {
if (str.match(unitOnlyRE))
if (unitOnlyRE.test(str))
return `${unitOnlyMap[str]}${str}`
const match = str.match(numberWithUnitRE)
if (!match)
Expand All @@ -93,7 +93,7 @@ export function rpx(str: string) {
}

export function px(str: string) {
if (str.match(unitOnlyRE))
if (unitOnlyRE.test(str))
return `${unitOnlyMap[str]}${str}`
const match = str.match(numberWithUnitRE)
if (!match)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function parseColor(body: string, theme: Theme, key?: ThemeColorKeys): Pa
if (!color) {
let colorData
const [scale] = colors.slice(-1)
if (scale.match(/^\d+$/)) {
if (/^\d+$/.test(scale)) {
no = scale
colorData = getThemeColor(theme, colors.slice(0, -1))
if (!colorData || typeof colorData === 'string')
Expand Down

0 comments on commit 3357fd7

Please sign in to comment.