[web] Use named capture groups

This commit is contained in:
Alain Nussbaumer 2024-04-26 22:54:32 +02:00
parent 7826b36634
commit ea947df50a
2 changed files with 8 additions and 7 deletions

View File

@ -32,7 +32,6 @@ export default [
'no-undef': 'off', 'no-undef': 'off',
'no-unused-vars': ['error', { args: 'none', caughtErrors: 'none' }], 'no-unused-vars': ['error', { args: 'none', caughtErrors: 'none' }],
'one-var': 'off', 'one-var': 'off',
'prefer-named-capture-group': 'off',
'sort-keys': 'off', 'sort-keys': 'off',
'vue/html-self-closing': 'off', 'vue/html-self-closing': 'off',
'vue/max-attributes-per-line': 'off', 'vue/max-attributes-per-line': 'off',

View File

@ -55,13 +55,15 @@ export default {
const parsed = [] const parsed = []
if (raw) { if (raw) {
// Parse the lyrics // Parse the lyrics
const regex = /(\[(\d+):(\d+)(?:\.\d+)?\] ?)?(.*)/u const regex =
raw.split('\n').forEach((item, index) => { /\[(?<minutes>\d+):(?<seconds>\d+)(?:\.(?<hundredths>\d+))?\] ?(?<text>.*)/u
const matches = regex.exec(item) raw.split('\n').forEach((item) => {
if (matches && matches[4]) { const { text, minutes, seconds, hundredths } = regex.exec(line).groups
if (text) {
const verse = { const verse = {
text: matches[4], text,
time: matches[2] * 60 + Number(matches[3]) time:
minutes * 60 + Number(seconds) + Number(`.${hundredths || 0}`)
} }
parsed.push(verse) parsed.push(verse)
} }