chordsheetjs 4.10.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -139
- package/d7b54993c4ea66c07a35bd36690482ab620f836e.patch +105 -0
- package/lib/chord.js +341 -35
- package/lib/chord_sheet/chord_lyrics_pair.js +1 -1
- package/lib/chord_sheet/chord_pro/composite.js +1 -1
- package/lib/chord_sheet/chord_pro/evaluation_error.js +7 -3
- package/lib/chord_sheet/chord_pro/literal.js +1 -1
- package/lib/chord_sheet/chord_pro/ternary.js +1 -1
- package/lib/chord_sheet/comment.js +1 -1
- package/lib/chord_sheet/line.js +1 -1
- package/lib/chord_sheet/metadata.js +4 -4
- package/lib/chord_sheet/paragraph.js +1 -1
- package/lib/chord_sheet/song.js +9 -5
- package/lib/chord_sheet/tag.js +10 -3
- package/lib/chord_sheet_serializer.js +1 -1
- package/lib/constants.js +6 -2
- package/lib/formatter/chord_pro_formatter.js +1 -1
- package/lib/formatter/html_div_formatter.js +4 -4
- package/lib/formatter/html_formatter.js +3 -2
- package/lib/formatter/html_table_formatter.js +4 -4
- package/lib/formatter/templates/html_div_formatter.js +31 -32
- package/lib/formatter/templates/html_table_formatter.js +7 -6
- package/lib/formatter/text_formatter.js +25 -17
- package/lib/helpers.js +32 -0
- package/lib/index.js +26 -10
- package/lib/key.js +311 -0
- package/lib/note.js +132 -0
- package/lib/parser/chord_pro_parser.js +1 -1
- package/lib/parser/chord_pro_peg_parser.js +22 -13
- package/lib/parser/chord_sheet_parser.js +1 -1
- package/lib/parser/parser_warning.js +1 -1
- package/lib/parser/ultimate_guitar_parser.js +4 -4
- package/lib/{handlebars_helpers.js → template_helpers.js} +21 -2
- package/lib/utilities.js +22 -23
- package/package.json +6 -5
- package/lib/chord_helpers.js +0 -222
- package/lib/chord_symbol.js +0 -139
- package/lib/numeric_chord.js +0 -138
- package/lib/parse_chord.js +0 -74
- package/lib/to_chord_symbol.js +0 -93
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ChordSheetJS ](https://travis-ci.org/martijnversluis/ChordSheetJS) [](https://badge.fury.io/js/chordsheetjs) [](https://codeclimate.com/github/martijnversluis/ChordSheetJS)
|
|
2
2
|
|
|
3
3
|
A JavaScript library for parsing and formatting chord sheets
|
|
4
4
|
|
|
@@ -396,17 +396,11 @@ PDF conversion.</p>
|
|
|
396
396
|
Inherits from <a href="#ChordSheetParser">ChordSheetParser</a></p>
|
|
397
397
|
</dd>
|
|
398
398
|
<dt><a href="#Chord">Chord</a></dt>
|
|
399
|
-
<dd><p>
|
|
399
|
+
<dd><p>Represents a Chord, consisting of a root, suffix (quality) and bass</p>
|
|
400
400
|
</dd>
|
|
401
401
|
<dt><a href="#ChordSheetSerializer">ChordSheetSerializer</a></dt>
|
|
402
402
|
<dd><p>Serializes a song into een plain object, and deserializes the serialized object back into a <a href="#Song">Song</a></p>
|
|
403
403
|
</dd>
|
|
404
|
-
<dt><a href="#ChordSymbol">ChordSymbol</a></dt>
|
|
405
|
-
<dd><p>Represents a chord symbol, such as Esus4</p>
|
|
406
|
-
</dd>
|
|
407
|
-
<dt><a href="#NumericChord">NumericChord</a></dt>
|
|
408
|
-
<dd><p>Represents a numeric chord, such as b3sus4</p>
|
|
409
|
-
</dd>
|
|
410
404
|
</dl>
|
|
411
405
|
|
|
412
406
|
## Constants
|
|
@@ -436,6 +430,9 @@ Inherits from <a href="#ChordSheetParser">ChordSheetParser</a></p>
|
|
|
436
430
|
<dt><a href="#END_OF_CHORUS">END_OF_CHORUS</a> : <code>string</code></dt>
|
|
437
431
|
<dd><p>End of chorus directive. See <a href="https://www.chordpro.org/chordpro/directives-env_chorus/">https://www.chordpro.org/chordpro/directives-env_chorus/</a></p>
|
|
438
432
|
</dd>
|
|
433
|
+
<dt><a href="#END_OF_TAB">END_OF_TAB</a> : <code>string</code></dt>
|
|
434
|
+
<dd><p>End of tab directive. See <a href="https://www.chordpro.org/chordpro/directives-env_tab/">https://www.chordpro.org/chordpro/directives-env_tab/</a></p>
|
|
435
|
+
</dd>
|
|
439
436
|
<dt><a href="#END_OF_VERSE">END_OF_VERSE</a> : <code>string</code></dt>
|
|
440
437
|
<dd><p>End of verse directive. See <a href="https://www.chordpro.org/chordpro/directives-env_verse/">https://www.chordpro.org/chordpro/directives-env_verse/</a></p>
|
|
441
438
|
</dd>
|
|
@@ -451,6 +448,9 @@ Inherits from <a href="#ChordSheetParser">ChordSheetParser</a></p>
|
|
|
451
448
|
<dt><a href="#START_OF_CHORUS">START_OF_CHORUS</a> : <code>string</code></dt>
|
|
452
449
|
<dd><p>Start of chorus directive. See <a href="https://www.chordpro.org/chordpro/directives-env_chorus/">https://www.chordpro.org/chordpro/directives-env_chorus/</a></p>
|
|
453
450
|
</dd>
|
|
451
|
+
<dt><a href="#START_OF_TAB">START_OF_TAB</a> : <code>string</code></dt>
|
|
452
|
+
<dd><p>Start of tab directive. See <a href="https://www.chordpro.org/chordpro/directives-env_tab/">https://www.chordpro.org/chordpro/directives-env_tab/</a></p>
|
|
453
|
+
</dd>
|
|
454
454
|
<dt><a href="#START_OF_VERSE">START_OF_VERSE</a> : <code>string</code></dt>
|
|
455
455
|
<dd><p>Start of verse directive. See <a href="https://www.chordpro.org/chordpro/directives-env_verse/">https://www.chordpro.org/chordpro/directives-env_verse/</a></p>
|
|
456
456
|
</dd>
|
|
@@ -485,6 +485,9 @@ For a CSS string see <a href="#scopedCss">scopedCss</a></p>
|
|
|
485
485
|
<dt><a href="#INDETERMINATE">INDETERMINATE</a> : <code>string</code></dt>
|
|
486
486
|
<dd><p>Used to mark a paragraph as containing lines with both verse and chorus type</p>
|
|
487
487
|
</dd>
|
|
488
|
+
<dt><a href="#TAB">TAB</a> : <code>string</code></dt>
|
|
489
|
+
<dd><p>Used to mark a paragraph as tab</p>
|
|
490
|
+
</dd>
|
|
488
491
|
</dl>
|
|
489
492
|
|
|
490
493
|
## Functions
|
|
@@ -493,12 +496,9 @@ For a CSS string see <a href="#scopedCss">scopedCss</a></p>
|
|
|
493
496
|
<dt><a href="#scopedCss">scopedCss(scope)</a> ⇒ <code>string</code></dt>
|
|
494
497
|
<dd><p>Generates basic CSS, scoped within the provided selector, to use with output generated by <a href="#HtmlTableFormatter">HtmlTableFormatter</a></p>
|
|
495
498
|
</dd>
|
|
496
|
-
<dt><a href="#parseChord">parseChord(chordString)</a> ⇒ <code>null</code> | <code><a href="#
|
|
499
|
+
<dt><del><a href="#parseChord">parseChord(chordString)</a> ⇒ <code>null</code> | <code><a href="#Chord">Chord</a></code></del></dt>
|
|
497
500
|
<dd><p>Tries to parse a chord string into a chord</p>
|
|
498
501
|
</dd>
|
|
499
|
-
<dt><a href="#toChordSymbol">toChordSymbol(numericChord, key)</a> ⇒ <code><a href="#ChordSymbol">ChordSymbol</a></code></dt>
|
|
500
|
-
<dd><p>Converts a numeric chord into a chord symbol, using the provided key</p>
|
|
501
|
-
</dd>
|
|
502
502
|
</dl>
|
|
503
503
|
|
|
504
504
|
<a name="ChordLyricsPair"></a>
|
|
@@ -1165,186 +1165,205 @@ Inherits from [ChordSheetParser](#ChordSheetParser)
|
|
|
1165
1165
|
<a name="Chord"></a>
|
|
1166
1166
|
|
|
1167
1167
|
## Chord
|
|
1168
|
-
|
|
1168
|
+
Represents a Chord, consisting of a root, suffix (quality) and bass
|
|
1169
1169
|
|
|
1170
1170
|
**Kind**: global class
|
|
1171
|
+
|
|
1172
|
+
* [Chord](#Chord)
|
|
1173
|
+
* _instance_
|
|
1174
|
+
* [.clone()](#Chord+clone) ⇒ [<code>Chord</code>](#Chord)
|
|
1175
|
+
* [.toChordSymbol(key)](#Chord+toChordSymbol) ⇒ [<code>Chord</code>](#Chord)
|
|
1176
|
+
* [.toChordSymbolString(key)](#Chord+toChordSymbolString) ⇒ <code>string</code>
|
|
1177
|
+
* [.isChordSymbol()](#Chord+isChordSymbol) ⇒ <code>boolean</code>
|
|
1178
|
+
* [.toNumeric(key)](#Chord+toNumeric) ⇒ [<code>Chord</code>](#Chord)
|
|
1179
|
+
* [.isNumeric()](#Chord+isNumeric) ⇒ <code>boolean</code>
|
|
1180
|
+
* [.toNumericString(key)](#Chord+toNumericString) ⇒ <code>string</code>
|
|
1181
|
+
* [.toString()](#Chord+toString) ⇒ <code>string</code>
|
|
1182
|
+
* [.normalize()](#Chord+normalize) ⇒ [<code>Chord</code>](#Chord)
|
|
1183
|
+
* [.useModifier(newModifier)](#Chord+useModifier) ⇒ [<code>Chord</code>](#Chord)
|
|
1184
|
+
* [.transposeUp()](#Chord+transposeUp) ⇒ [<code>Chord</code>](#Chord)
|
|
1185
|
+
* [.transposeDown()](#Chord+transposeDown) ⇒ [<code>Chord</code>](#Chord)
|
|
1186
|
+
* [.transpose(delta)](#Chord+transpose) ⇒ [<code>Chord</code>](#Chord)
|
|
1187
|
+
* _static_
|
|
1188
|
+
* [.parse(chordString)](#Chord.parse) ⇒ <code>null</code> \| [<code>Chord</code>](#Chord)
|
|
1189
|
+
|
|
1171
1190
|
<a name="Chord+clone"></a>
|
|
1172
1191
|
|
|
1173
1192
|
### chord.clone() ⇒ [<code>Chord</code>](#Chord)
|
|
1174
1193
|
Returns a deep copy of the chord
|
|
1175
1194
|
|
|
1176
1195
|
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1177
|
-
<a name="
|
|
1196
|
+
<a name="Chord+toChordSymbol"></a>
|
|
1178
1197
|
|
|
1179
|
-
|
|
1180
|
-
|
|
1198
|
+
### chord.toChordSymbol(key) ⇒ [<code>Chord</code>](#Chord)
|
|
1199
|
+
Converts the chord to a chord symbol, using the supplied key as a reference.
|
|
1200
|
+
For example, a numeric chord `#4` with reference key `E` will return the chord symbol `A#`.
|
|
1201
|
+
When the chord is already a chord symbol, it will return a clone of the object.
|
|
1181
1202
|
|
|
1182
|
-
**Kind**:
|
|
1203
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1204
|
+
**Returns**: [<code>Chord</code>](#Chord) - the chord symbol
|
|
1183
1205
|
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1206
|
+
| Param | Type | Description |
|
|
1207
|
+
| --- | --- | --- |
|
|
1208
|
+
| key | <code>Key</code> \| <code>string</code> | the reference key |
|
|
1187
1209
|
|
|
1188
|
-
<a name="
|
|
1210
|
+
<a name="Chord+toChordSymbolString"></a>
|
|
1189
1211
|
|
|
1190
|
-
###
|
|
1191
|
-
|
|
1192
|
-
|
|
1212
|
+
### chord.toChordSymbolString(key) ⇒ <code>string</code>
|
|
1213
|
+
Converts the chord to a chord symbol string, using the supplied key as a reference.
|
|
1214
|
+
For example, a numeric chord `#4` with reference key `E` will return the chord symbol `A#`.
|
|
1215
|
+
When the chord is already a chord symbol, it will return a string version of the chord.
|
|
1193
1216
|
|
|
1194
|
-
**Kind**: instance method of [<code>
|
|
1195
|
-
**Returns**:
|
|
1196
|
-
|
|
1217
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1218
|
+
**Returns**: <code>string</code> - the chord symbol string
|
|
1219
|
+
**See**: {toChordSymbol}
|
|
1197
1220
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1221
|
+
| Param | Type | Description |
|
|
1222
|
+
| --- | --- | --- |
|
|
1223
|
+
| key | <code>Key</code> \| <code>string</code> | the reference key |
|
|
1200
1224
|
|
|
1201
|
-
|
|
1202
|
-
|
|
1225
|
+
<a name="Chord+isChordSymbol"></a>
|
|
1226
|
+
|
|
1227
|
+
### chord.isChordSymbol() ⇒ <code>boolean</code>
|
|
1228
|
+
Determines whether the chord is a chord symbol
|
|
1229
|
+
|
|
1230
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1231
|
+
<a name="Chord+toNumeric"></a>
|
|
1232
|
+
|
|
1233
|
+
### chord.toNumeric(key) ⇒ [<code>Chord</code>](#Chord)
|
|
1234
|
+
Converts the chord to a numeric chord, using the supplied kye as a reference.
|
|
1235
|
+
For example, a chord symbol A# with reference key E will return the numeric chord #4.
|
|
1236
|
+
|
|
1237
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1238
|
+
**Returns**: [<code>Chord</code>](#Chord) - the numeric chord
|
|
1203
1239
|
|
|
1204
1240
|
| Param | Type | Description |
|
|
1205
1241
|
| --- | --- | --- |
|
|
1206
|
-
|
|
|
1242
|
+
| key | <code>Key</code> \| <code>string</code> | the reference key |
|
|
1207
1243
|
|
|
1208
|
-
<a name="
|
|
1244
|
+
<a name="Chord+isNumeric"></a>
|
|
1209
1245
|
|
|
1210
|
-
|
|
1211
|
-
|
|
1246
|
+
### chord.isNumeric() ⇒ <code>boolean</code>
|
|
1247
|
+
Determines whether the chord is numeric
|
|
1212
1248
|
|
|
1213
|
-
**Kind**:
|
|
1249
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1250
|
+
<a name="Chord+toNumericString"></a>
|
|
1251
|
+
|
|
1252
|
+
### chord.toNumericString(key) ⇒ <code>string</code>
|
|
1253
|
+
Converts the chord to a numeric chord string, using the supplied kye as a reference.
|
|
1254
|
+
For example, a chord symbol A# with reference key E will return the numeric chord #4.
|
|
1255
|
+
|
|
1256
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1257
|
+
**Returns**: <code>string</code> - the numeric chord string
|
|
1258
|
+
**See**: {toNumeric}
|
|
1259
|
+
|
|
1260
|
+
| Param | Type | Description |
|
|
1261
|
+
| --- | --- | --- |
|
|
1262
|
+
| key | <code>Key</code> \| <code>string</code> | the reference key |
|
|
1214
1263
|
|
|
1215
|
-
|
|
1216
|
-
* [.normalize()](#ChordSymbol+normalize) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1217
|
-
* [.switchModifier()](#ChordSymbol+switchModifier) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1218
|
-
* [.useModifier(newModifier)](#ChordSymbol+useModifier) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1219
|
-
* [.transposeUp()](#ChordSymbol+transposeUp) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1220
|
-
* [.transposeDown()](#ChordSymbol+transposeDown) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1221
|
-
* [.transpose(delta)](#ChordSymbol+transpose) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1222
|
-
* [.toString()](#ChordSymbol+toString) ⇒ <code>string</code> \| <code>\*</code>
|
|
1264
|
+
<a name="Chord+toString"></a>
|
|
1223
1265
|
|
|
1224
|
-
<
|
|
1266
|
+
### chord.toString() ⇒ <code>string</code>
|
|
1267
|
+
Converts the chord to a string, eg `Esus4/G#` or `1sus4/#3`
|
|
1225
1268
|
|
|
1226
|
-
|
|
1269
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1270
|
+
**Returns**: <code>string</code> - the chord string
|
|
1271
|
+
<a name="Chord+normalize"></a>
|
|
1272
|
+
|
|
1273
|
+
### chord.normalize() ⇒ [<code>Chord</code>](#Chord)
|
|
1227
1274
|
Normalizes the chord:
|
|
1228
1275
|
- Fb becomes E
|
|
1229
1276
|
- Cb becomes B
|
|
1230
1277
|
- B# becomes C
|
|
1231
1278
|
- E# becomes F
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
<a name="ChordSymbol+switchModifier"></a>
|
|
1279
|
+
- 4b becomes 3
|
|
1280
|
+
- 1b becomes 7
|
|
1281
|
+
- 7# becomes 1
|
|
1282
|
+
- 3# becomes 4
|
|
1237
1283
|
|
|
1238
|
-
|
|
1239
|
-
Switches between '#' and 'b' as modifiers. If
|
|
1284
|
+
If the chord is already normalized, this will return a copy.
|
|
1240
1285
|
|
|
1241
|
-
**Kind**: instance method of [<code>
|
|
1242
|
-
**Returns**: [<code>
|
|
1243
|
-
<a name="
|
|
1286
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1287
|
+
**Returns**: [<code>Chord</code>](#Chord) - the normalized chord
|
|
1288
|
+
<a name="Chord+useModifier"></a>
|
|
1244
1289
|
|
|
1245
|
-
###
|
|
1290
|
+
### chord.useModifier(newModifier) ⇒ [<code>Chord</code>](#Chord)
|
|
1246
1291
|
Switches to the specified modifier
|
|
1247
1292
|
|
|
1248
|
-
**Kind**: instance method of [<code>
|
|
1249
|
-
**Returns**: [<code>
|
|
1293
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1294
|
+
**Returns**: [<code>Chord</code>](#Chord) - the new, changed chord
|
|
1250
1295
|
|
|
1251
1296
|
| Param | Description |
|
|
1252
1297
|
| --- | --- |
|
|
1253
1298
|
| newModifier | the modifier to use: `'#'` or `'b'` |
|
|
1254
1299
|
|
|
1255
|
-
<a name="
|
|
1300
|
+
<a name="Chord+transposeUp"></a>
|
|
1256
1301
|
|
|
1257
|
-
###
|
|
1302
|
+
### chord.transposeUp() ⇒ [<code>Chord</code>](#Chord)
|
|
1258
1303
|
Transposes the chord up by 1 semitone. Eg. A becomes A#, Eb becomes E
|
|
1259
1304
|
|
|
1260
|
-
**Kind**: instance method of [<code>
|
|
1261
|
-
**Returns**: [<code>
|
|
1262
|
-
<a name="
|
|
1305
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1306
|
+
**Returns**: [<code>Chord</code>](#Chord) - the new, transposed chord
|
|
1307
|
+
<a name="Chord+transposeDown"></a>
|
|
1263
1308
|
|
|
1264
|
-
###
|
|
1309
|
+
### chord.transposeDown() ⇒ [<code>Chord</code>](#Chord)
|
|
1265
1310
|
Transposes the chord down by 1 semitone. Eg. A# becomes A, E becomes Eb
|
|
1266
1311
|
|
|
1267
|
-
**Kind**: instance method of [<code>
|
|
1268
|
-
**Returns**: [<code>
|
|
1269
|
-
<a name="
|
|
1312
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1313
|
+
**Returns**: [<code>Chord</code>](#Chord) - the new, transposed chord
|
|
1314
|
+
<a name="Chord+transpose"></a>
|
|
1270
1315
|
|
|
1271
|
-
###
|
|
1316
|
+
### chord.transpose(delta) ⇒ [<code>Chord</code>](#Chord)
|
|
1272
1317
|
Transposes the chord by the specified number of semitones
|
|
1273
1318
|
|
|
1274
|
-
**Kind**: instance method of [<code>
|
|
1275
|
-
**Returns**: [<code>
|
|
1319
|
+
**Kind**: instance method of [<code>Chord</code>](#Chord)
|
|
1320
|
+
**Returns**: [<code>Chord</code>](#Chord) - the new, transposed chord
|
|
1276
1321
|
|
|
1277
1322
|
| Param | Description |
|
|
1278
1323
|
| --- | --- |
|
|
1279
1324
|
| delta | de number of semitones |
|
|
1280
1325
|
|
|
1281
|
-
<a name="
|
|
1282
|
-
|
|
1283
|
-
### chordSymbol.toString() ⇒ <code>string</code> \| <code>\*</code>
|
|
1284
|
-
Convert the chord to a string, eg. `'Esus4/G#'`
|
|
1285
|
-
|
|
1286
|
-
**Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1287
|
-
<a name="NumericChord"></a>
|
|
1288
|
-
|
|
1289
|
-
## NumericChord
|
|
1290
|
-
Represents a numeric chord, such as b3sus4
|
|
1291
|
-
|
|
1292
|
-
**Kind**: global class
|
|
1293
|
-
|
|
1294
|
-
* [NumericChord](#NumericChord)
|
|
1295
|
-
* [.normalize()](#NumericChord+normalize) ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1296
|
-
* [.switchModifier()](#NumericChord+switchModifier) ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1297
|
-
* [.useModifier()](#NumericChord+useModifier) ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1298
|
-
* [.transposeUp()](#NumericChord+transposeUp) ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1299
|
-
* [.transposeDown()](#NumericChord+transposeDown) ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1300
|
-
* [.transpose(delta)](#NumericChord+transpose) ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1326
|
+
<a name="Chord.parse"></a>
|
|
1301
1327
|
|
|
1302
|
-
<
|
|
1303
|
-
|
|
1304
|
-
### numericChord.normalize() ⇒ [<code>NumericChord</code>](#NumericChord)
|
|
1305
|
-
Normalizes the chord - this is a noop for numeric chords.
|
|
1328
|
+
### Chord.parse(chordString) ⇒ <code>null</code> \| [<code>Chord</code>](#Chord)
|
|
1329
|
+
Tries to parse a chord string into a chord
|
|
1306
1330
|
|
|
1307
|
-
**Kind**:
|
|
1308
|
-
**Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
|
|
1309
|
-
<a name="NumericChord+switchModifier"></a>
|
|
1331
|
+
**Kind**: static method of [<code>Chord</code>](#Chord)
|
|
1310
1332
|
|
|
1311
|
-
|
|
1312
|
-
|
|
1333
|
+
| Param | Description |
|
|
1334
|
+
| --- | --- |
|
|
1335
|
+
| chordString | the chord string, eg `Esus4/G#` or `1sus4/#3` |
|
|
1313
1336
|
|
|
1314
|
-
|
|
1315
|
-
**Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
|
|
1316
|
-
<a name="NumericChord+useModifier"></a>
|
|
1337
|
+
<a name="ChordSheetSerializer"></a>
|
|
1317
1338
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1339
|
+
## ChordSheetSerializer
|
|
1340
|
+
Serializes a song into een plain object, and deserializes the serialized object back into a [Song](#Song)
|
|
1320
1341
|
|
|
1321
|
-
**Kind**:
|
|
1322
|
-
**Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
|
|
1323
|
-
<a name="NumericChord+transposeUp"></a>
|
|
1342
|
+
**Kind**: global class
|
|
1324
1343
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1344
|
+
* [ChordSheetSerializer](#ChordSheetSerializer)
|
|
1345
|
+
* [.serialize()](#ChordSheetSerializer+serialize) ⇒
|
|
1346
|
+
* [.deserialize(serializedSong)](#ChordSheetSerializer+deserialize) ⇒ [<code>Song</code>](#Song)
|
|
1327
1347
|
|
|
1328
|
-
|
|
1329
|
-
**Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
|
|
1330
|
-
<a name="NumericChord+transposeDown"></a>
|
|
1348
|
+
<a name="ChordSheetSerializer+serialize"></a>
|
|
1331
1349
|
|
|
1332
|
-
###
|
|
1333
|
-
|
|
1350
|
+
### chordSheetSerializer.serialize() ⇒
|
|
1351
|
+
Serializes the chord sheet to a plain object, which can be converted to any format like JSON, XML etc
|
|
1352
|
+
Can be deserialized using [deserialize](deserialize)
|
|
1334
1353
|
|
|
1335
|
-
**Kind**: instance method of [<code>
|
|
1336
|
-
**Returns**:
|
|
1337
|
-
<a name="
|
|
1354
|
+
**Kind**: instance method of [<code>ChordSheetSerializer</code>](#ChordSheetSerializer)
|
|
1355
|
+
**Returns**: object A plain JS object containing all chord sheet data
|
|
1356
|
+
<a name="ChordSheetSerializer+deserialize"></a>
|
|
1338
1357
|
|
|
1339
|
-
###
|
|
1340
|
-
|
|
1358
|
+
### chordSheetSerializer.deserialize(serializedSong) ⇒ [<code>Song</code>](#Song)
|
|
1359
|
+
Deserializes a song that has been serialized using [serialize](serialize)
|
|
1341
1360
|
|
|
1342
|
-
**Kind**: instance method of [<code>
|
|
1343
|
-
**Returns**: [<code>
|
|
1361
|
+
**Kind**: instance method of [<code>ChordSheetSerializer</code>](#ChordSheetSerializer)
|
|
1362
|
+
**Returns**: [<code>Song</code>](#Song) - The deserialized song
|
|
1344
1363
|
|
|
1345
|
-
| Param | Description |
|
|
1346
|
-
| --- | --- |
|
|
1347
|
-
|
|
|
1364
|
+
| Param | Type | Description |
|
|
1365
|
+
| --- | --- | --- |
|
|
1366
|
+
| serializedSong | <code>object</code> | The serialized song |
|
|
1348
1367
|
|
|
1349
1368
|
<a name="ALBUM"></a>
|
|
1350
1369
|
|
|
@@ -1393,6 +1412,12 @@ Duration meta directive. See https://www.chordpro.org/chordpro/directives-durati
|
|
|
1393
1412
|
## END\_OF\_CHORUS : <code>string</code>
|
|
1394
1413
|
End of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
|
|
1395
1414
|
|
|
1415
|
+
**Kind**: global constant
|
|
1416
|
+
<a name="END_OF_TAB"></a>
|
|
1417
|
+
|
|
1418
|
+
## END\_OF\_TAB : <code>string</code>
|
|
1419
|
+
End of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
|
|
1420
|
+
|
|
1396
1421
|
**Kind**: global constant
|
|
1397
1422
|
<a name="END_OF_VERSE"></a>
|
|
1398
1423
|
|
|
@@ -1423,6 +1448,12 @@ Lyricist meta directive. See https://www.chordpro.org/chordpro/directives-lyrici
|
|
|
1423
1448
|
## START\_OF\_CHORUS : <code>string</code>
|
|
1424
1449
|
Start of chorus directive. See https://www.chordpro.org/chordpro/directives-env_chorus/
|
|
1425
1450
|
|
|
1451
|
+
**Kind**: global constant
|
|
1452
|
+
<a name="START_OF_TAB"></a>
|
|
1453
|
+
|
|
1454
|
+
## START\_OF\_TAB : <code>string</code>
|
|
1455
|
+
Start of tab directive. See https://www.chordpro.org/chordpro/directives-env_tab/
|
|
1456
|
+
|
|
1426
1457
|
**Kind**: global constant
|
|
1427
1458
|
<a name="START_OF_VERSE"></a>
|
|
1428
1459
|
|
|
@@ -1490,6 +1521,12 @@ Used to mark a paragraph as not containing a line marked with a type
|
|
|
1490
1521
|
## INDETERMINATE : <code>string</code>
|
|
1491
1522
|
Used to mark a paragraph as containing lines with both verse and chorus type
|
|
1492
1523
|
|
|
1524
|
+
**Kind**: global constant
|
|
1525
|
+
<a name="TAB"></a>
|
|
1526
|
+
|
|
1527
|
+
## TAB : <code>string</code>
|
|
1528
|
+
Used to mark a paragraph as tab
|
|
1529
|
+
|
|
1493
1530
|
**Kind**: global constant
|
|
1494
1531
|
<a name="scopedCss"></a>
|
|
1495
1532
|
|
|
@@ -1505,7 +1542,9 @@ Generates basic CSS, scoped within the provided selector, to use with output gen
|
|
|
1505
1542
|
|
|
1506
1543
|
<a name="parseChord"></a>
|
|
1507
1544
|
|
|
1508
|
-
## parseChord(chordString) ⇒ <code>null</code> \| [<code>
|
|
1545
|
+
## ~~parseChord(chordString) ⇒ <code>null</code> \| [<code>Chord</code>](#Chord)~~
|
|
1546
|
+
***Deprecated***
|
|
1547
|
+
|
|
1509
1548
|
Tries to parse a chord string into a chord
|
|
1510
1549
|
|
|
1511
1550
|
**Kind**: global function
|
|
@@ -1514,16 +1553,3 @@ Tries to parse a chord string into a chord
|
|
|
1514
1553
|
| --- | --- |
|
|
1515
1554
|
| chordString | the chord string, eg Esus4/G# or 1sus4/#3 |
|
|
1516
1555
|
|
|
1517
|
-
<a name="toChordSymbol"></a>
|
|
1518
|
-
|
|
1519
|
-
## toChordSymbol(numericChord, key) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
|
|
1520
|
-
Converts a numeric chord into a chord symbol, using the provided key
|
|
1521
|
-
|
|
1522
|
-
**Kind**: global function
|
|
1523
|
-
**Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the resulting chord symbol
|
|
1524
|
-
|
|
1525
|
-
| Param | Type | Description |
|
|
1526
|
-
| --- | --- | --- |
|
|
1527
|
-
| numericChord | [<code>NumericChord</code>](#NumericChord) | |
|
|
1528
|
-
| key | <code>string</code> | the to use, sp anything between Ab and G# |
|
|
1529
|
-
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
commit d7b54993c4ea66c07a35bd36690482ab620f836e
|
|
2
|
+
Author: Martijn Versluis <martijnversluis@users.noreply.github.com>
|
|
3
|
+
Date: Sun Jan 30 16:35:24 2022 +0100
|
|
4
|
+
|
|
5
|
+
Do not rely on contructor name
|
|
6
|
+
|
|
7
|
+
Due to build tools scrambling constructor names, we can not rely on those
|
|
8
|
+
for type checking. Thus we have to use `instanceof`. This change removes
|
|
9
|
+
usages of `constructor.name` and solves the cyclic dependency by moving around
|
|
10
|
+
some functions.
|
|
11
|
+
|
|
12
|
+
Resolves #421
|
|
13
|
+
|
|
14
|
+
diff --git a/src/formatter/html_div_formatter.js b/src/formatter/html_div_formatter.js
|
|
15
|
+
index f92f532..b1de230 100644
|
|
16
|
+
--- a/src/formatter/html_div_formatter.js
|
|
17
|
+
+++ b/src/formatter/html_div_formatter.js
|
|
18
|
+
@@ -1,6 +1,6 @@
|
|
19
|
+
import Handlebars from 'handlebars';
|
|
20
|
+
|
|
21
|
+
-import '../handlebars_helpers';
|
|
22
|
+
+import '../template_helpers';
|
|
23
|
+
import HtmlFormatter from './html_formatter';
|
|
24
|
+
import './templates/html_div_formatter';
|
|
25
|
+
import { scopeCss } from '../utilities';
|
|
26
|
+
diff --git a/src/formatter/html_table_formatter.js b/src/formatter/html_table_formatter.js
|
|
27
|
+
index 4883fef..7d7e8ea 100644
|
|
28
|
+
--- a/src/formatter/html_table_formatter.js
|
|
29
|
+
+++ b/src/formatter/html_table_formatter.js
|
|
30
|
+
@@ -1,6 +1,6 @@
|
|
31
|
+
import Handlebars from 'handlebars';
|
|
32
|
+
|
|
33
|
+
-import '../handlebars_helpers';
|
|
34
|
+
+import '../template_helpers';
|
|
35
|
+
import HtmlFormatter from './html_formatter';
|
|
36
|
+
import './templates/html_table_formatter';
|
|
37
|
+
import { scopeCss } from '../utilities';
|
|
38
|
+
diff --git a/src/formatter/text_formatter.js b/src/formatter/text_formatter.js
|
|
39
|
+
index 61385f1..81fe226 100644
|
|
40
|
+
--- a/src/formatter/text_formatter.js
|
|
41
|
+
+++ b/src/formatter/text_formatter.js
|
|
42
|
+
@@ -1,10 +1,10 @@
|
|
43
|
+
import ChordLyricsPair from '../chord_sheet/chord_lyrics_pair';
|
|
44
|
+
import Tag from '../chord_sheet/tag';
|
|
45
|
+
import { renderChord } from '../helpers';
|
|
46
|
+
+import { hasTextContents } from '../template_helpers';
|
|
47
|
+
|
|
48
|
+
import {
|
|
49
|
+
hasChordContents,
|
|
50
|
+
- hasTextContents,
|
|
51
|
+
padLeft,
|
|
52
|
+
} from '../utilities';
|
|
53
|
+
|
|
54
|
+
diff --git a/src/handlebars_helpers.js b/src/template_helpers.js
|
|
55
|
+
similarity index 87%
|
|
56
|
+
rename from src/handlebars_helpers.js
|
|
57
|
+
rename to src/template_helpers.js
|
|
58
|
+
index 0e5ff98..b330f87 100644
|
|
59
|
+
--- a/src/handlebars_helpers.js
|
|
60
|
+
+++ b/src/template_helpers.js
|
|
61
|
+
@@ -7,12 +7,20 @@ import { renderChord } from './helpers';
|
|
62
|
+
|
|
63
|
+
import {
|
|
64
|
+
hasChordContents,
|
|
65
|
+
- hasTextContents,
|
|
66
|
+
isEvaluatable,
|
|
67
|
+
} from './utilities';
|
|
68
|
+
|
|
69
|
+
const lineHasContents = (line) => line.items.some((item) => item.isRenderable());
|
|
70
|
+
|
|
71
|
+
+/* eslint import/prefer-default-export: 0 */
|
|
72
|
+
+export const hasTextContents = (line) => (
|
|
73
|
+
+ line.items.some((item) => (
|
|
74
|
+
+ (item instanceof ChordLyricsPair && item.lyrics)
|
|
75
|
+
+ || (item instanceof Tag && item.isRenderable())
|
|
76
|
+
+ || isEvaluatable(item)
|
|
77
|
+
+ ))
|
|
78
|
+
+);
|
|
79
|
+
+
|
|
80
|
+
HandleBars.registerHelper('isChordLyricsPair', (item) => item instanceof ChordLyricsPair);
|
|
81
|
+
|
|
82
|
+
HandleBars.registerHelper('isTag', (item) => item instanceof Tag);
|
|
83
|
+
diff --git a/src/utilities.js b/src/utilities.js
|
|
84
|
+
index 03c69cc..503c811 100644
|
|
85
|
+
--- a/src/utilities.js
|
|
86
|
+
+++ b/src/utilities.js
|
|
87
|
+
@@ -8,18 +8,6 @@ export const hasChordContents = (line) => line.items.some((item) => !!item.chord
|
|
88
|
+
|
|
89
|
+
export const isEvaluatable = (item) => typeof item.evaluate === 'function';
|
|
90
|
+
|
|
91
|
+
-function isInstanceOf(object, constructorName) {
|
|
92
|
+
- return object?.constructor?.name === constructorName;
|
|
93
|
+
-}
|
|
94
|
+
-
|
|
95
|
+
-export const hasTextContents = (line) => (
|
|
96
|
+
- line.items.some((item) => (
|
|
97
|
+
- (isInstanceOf(item, 'ChordLyricsPair') && item.lyrics)
|
|
98
|
+
- || (isInstanceOf(item, 'Tag') && item.isRenderable())
|
|
99
|
+
- || isEvaluatable(item)
|
|
100
|
+
- ))
|
|
101
|
+
-);
|
|
102
|
+
-
|
|
103
|
+
export const padLeft = (str, length) => {
|
|
104
|
+
let paddedString = str;
|
|
105
|
+
for (let l = str.length; l < length; l += 1, paddedString += ' ');
|