From 4f4a9ab20fe828a84268429eeb097c9a494e8892 Mon Sep 17 00:00:00 2001 From: Christophe Noel Date: Wed, 18 Sep 2024 14:51:30 +0200 Subject: [PATCH 1/2] add 1 beat time signatures --- .../chord-mark/src/parser/matchers/isTimeSignatureString.js | 2 ++ .../tests/unit/parser/matchers/isTimeSignatureString.spec.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js b/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js index 06f5ae76..a7cb5d4c 100644 --- a/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js +++ b/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js @@ -1,7 +1,9 @@ const allowedTimeSignatures = [ + '1/2', '2/2', '3/2', '4/2', + '1/4', '2/4', '3/4', '4/4', diff --git a/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js b/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js index af315fae..56ef5078 100644 --- a/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js +++ b/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js @@ -7,10 +7,12 @@ describe('isTimeSignatureString', () => { }); describe.each([ + ['1/2', true], ['2/2', true], ['3/2', true], ['4/2', true], + ['1/4', true], ['2/4', true], ['3/4', true], ['4/4', true], From fd114c82fc0e22f9d80d10b51d86bb97d7181cfc Mon Sep 17 00:00:00 2001 From: Christophe Noel Date: Wed, 18 Sep 2024 14:56:01 +0200 Subject: [PATCH 2/2] rename isTimeSignatureString to isTimeSignature --- packages/chord-mark/src/parser/matchers/isChordLine.js | 5 ++--- .../{isTimeSignatureString.js => isTimeSignature.js} | 2 +- packages/chord-mark/src/parser/parseChordLine.js | 4 ++-- packages/chord-mark/src/parser/parseTimeSignature.js | 4 ++-- packages/chord-mark/src/parser/songLinesFactory.js | 2 +- .../unit/parser/matchers/isTimeSignatureString.spec.js | 8 ++++---- 6 files changed, 12 insertions(+), 13 deletions(-) rename packages/chord-mark/src/parser/matchers/{isTimeSignatureString.js => isTimeSignature.js} (81%) diff --git a/packages/chord-mark/src/parser/matchers/isChordLine.js b/packages/chord-mark/src/parser/matchers/isChordLine.js index b98ea3b6..40049131 100644 --- a/packages/chord-mark/src/parser/matchers/isChordLine.js +++ b/packages/chord-mark/src/parser/matchers/isChordLine.js @@ -3,7 +3,7 @@ import clearSpaces from '../helper/clearSpaces'; import syntax from '../syntax'; import isChord from './isChord'; -import isTimeSignatureString from './isTimeSignatureString'; +import isTimeSignature from './isTimeSignature'; const chordBeatCountSymbols = new RegExp( _escapeRegExp(syntax.chordBeatCount) + '*$', @@ -30,8 +30,7 @@ export default function isChordLine(line = '') { isChord(clean) || (potentialChordToken.match(barRepeatSymbols) && index > 0) || clean === syntax.noChord || - (isTimeSignatureString(potentialChordToken) && - allTokens.length > 1) + (isTimeSignature(potentialChordToken) && allTokens.length > 1) ); }); } diff --git a/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js b/packages/chord-mark/src/parser/matchers/isTimeSignature.js similarity index 81% rename from packages/chord-mark/src/parser/matchers/isTimeSignatureString.js rename to packages/chord-mark/src/parser/matchers/isTimeSignature.js index a7cb5d4c..112e9aaa 100644 --- a/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js +++ b/packages/chord-mark/src/parser/matchers/isTimeSignature.js @@ -21,6 +21,6 @@ const allowedTimeSignatures = [ '12/8', ]; -export default function isTimeSignatureString(string) { +export default function isTimeSignature(string) { return allowedTimeSignatures.includes(string); } diff --git a/packages/chord-mark/src/parser/parseChordLine.js b/packages/chord-mark/src/parser/parseChordLine.js index 82e73e40..0a3845d6 100644 --- a/packages/chord-mark/src/parser/parseChordLine.js +++ b/packages/chord-mark/src/parser/parseChordLine.js @@ -6,7 +6,7 @@ import _cloneDeep from 'lodash/cloneDeep'; import syntax, { defaultTimeSignature } from './syntax'; import clearSpaces from './helper/clearSpaces'; -import isTimeSignatureString from './matchers/isTimeSignatureString'; +import isTimeSignature from './matchers/isTimeSignature'; import parseChord from './parseChord'; import parseTimeSignature from './parseTimeSignature'; @@ -90,7 +90,7 @@ export default function parseChordLine( allTokens.forEach((token, tokenIndex) => { if (token.match(barRepeatSymbols)) { repeatPreviousBars(token); - } else if (isTimeSignatureString(token)) { + } else if (isTimeSignature(token)) { changeTimeSignature(token); } else { parseChordToken(token); diff --git a/packages/chord-mark/src/parser/parseTimeSignature.js b/packages/chord-mark/src/parser/parseTimeSignature.js index 376289d8..780aa8c3 100644 --- a/packages/chord-mark/src/parser/parseTimeSignature.js +++ b/packages/chord-mark/src/parser/parseTimeSignature.js @@ -1,4 +1,4 @@ -import isTimeSignatureString from './matchers/isTimeSignatureString'; +import isTimeSignature from './matchers/isTimeSignature'; /** * @typedef {Object} TimeSignature @@ -14,7 +14,7 @@ import isTimeSignatureString from './matchers/isTimeSignatureString'; * @returns {TimeSignature} */ export default function parseTimeSignature(string) { - if (!isTimeSignatureString(string)) { + if (!isTimeSignature(string)) { throw new TypeError( 'Expected time signature string, received: ' + string ); diff --git a/packages/chord-mark/src/parser/songLinesFactory.js b/packages/chord-mark/src/parser/songLinesFactory.js index e61d3531..0195111e 100644 --- a/packages/chord-mark/src/parser/songLinesFactory.js +++ b/packages/chord-mark/src/parser/songLinesFactory.js @@ -6,7 +6,7 @@ import isChordLine from './matchers/isChordLine'; import isChordLineRepeater from './matchers/isChordLineRepeater'; import isEmptyLine from './matchers/isEmptyLine'; import isSectionLabel from './matchers/isSectionLabel'; -import isTimeSignature from './matchers/isTimeSignatureString'; +import isTimeSignature from './matchers/isTimeSignature'; import parseChordLine from './parseChordLine'; import parseKeyDeclaration from './parseKeyDeclaration'; diff --git a/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js b/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js index 56ef5078..737e35a0 100644 --- a/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js +++ b/packages/chord-mark/tests/unit/parser/matchers/isTimeSignatureString.spec.js @@ -1,8 +1,8 @@ -import isTimeSignatureString from '../../../../src/parser/matchers/isTimeSignatureString'; +import isTimeSignature from '../../../../src/parser/matchers/isTimeSignature'; -describe('isTimeSignatureString', () => { +describe('isTimeSignatureS', () => { test('Module', () => { - expect(isTimeSignatureString).toBeInstanceOf(Function); + expect(isTimeSignature).toBeInstanceOf(Function); }); }); @@ -37,6 +37,6 @@ describe.each([ ['13/8', false], ])('Time signature string %s', (tsString, result) => { test('Correctly detect time signature', () => { - expect(isTimeSignatureString(tsString)).toEqual(result); + expect(isTimeSignature(tsString)).toEqual(result); }); });