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 77% rename from packages/chord-mark/src/parser/matchers/isTimeSignatureString.js rename to packages/chord-mark/src/parser/matchers/isTimeSignature.js index 06f5ae76..112e9aaa 100644 --- a/packages/chord-mark/src/parser/matchers/isTimeSignatureString.js +++ b/packages/chord-mark/src/parser/matchers/isTimeSignature.js @@ -1,7 +1,9 @@ const allowedTimeSignatures = [ + '1/2', '2/2', '3/2', '4/2', + '1/4', '2/4', '3/4', '4/4', @@ -19,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 af315fae..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,16 +1,18 @@ -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); }); }); 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], @@ -35,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); }); });