Skip to content

Commit

Permalink
fix: fix gradient formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Dec 8, 2024
1 parent 99d47f2 commit 07bd368
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions stores/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@ import {
} from '~/stores/form-data'

let formatGradientString = (gradientValue: string): string => {
let parts = gradientValue.match(/linear-gradient\((?<content>.*?)\)/u)
let match = gradientValue.match(/(linear-gradient\()(?<content>.*?)(\))/u)

Check failure on line 12 in stores/code.ts

View workflow job for this annotation

GitHub Actions / JS

Capture group '(linear-gradient\()' should be converted to a named or non-capturing group

Check failure on line 12 in stores/code.ts

View workflow job for this annotation

GitHub Actions / JS

Capture group '(\))' should be converted to a named or non-capturing group

Check failure on line 12 in stores/code.ts

View workflow job for this annotation

GitHub Actions / JS

Capture group '(linear-gradient\()' should be converted to a named or non-capturing group

Check failure on line 12 in stores/code.ts

View workflow job for this annotation

GitHub Actions / JS

Capture group '(\))' should be converted to a named or non-capturing group

if (!parts) {
if (!match || !match.groups) {

Check failure on line 14 in stores/code.ts

View workflow job for this annotation

GitHub Actions / JS

Prefer using an optional chain expression instead, as it's more concise and easier to read

Check failure on line 14 in stores/code.ts

View workflow job for this annotation

GitHub Actions / JS

Prefer using an optional chain expression instead, as it's more concise and easier to read
throw new Error('Invalid gradient string')
}

let directionAndColors =
parts.groups?.content.split(',').map(part => part.trim()) ?? []
let { content } = match.groups
let directionAndColors = content.split(',').map(part => part.trim())

let formattedDirectionAndColors = directionAndColors.join(',\n ')

return `${parts[1]}\n ${formattedDirectionAndColors}\n ${parts[3]}`
return `${match[1]}\n ${formattedDirectionAndColors}\n${match[3]}`
}

export let firstLoad = atom(true)
Expand Down

0 comments on commit 07bd368

Please sign in to comment.