chordsheetjs 4.7.1 → 4.10.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 CHANGED
@@ -1,4 +1,4 @@
1
- # ChordSheetJS [![Build Status](https://travis-ci.org/martijnversluis/ChordSheetJS.svg?branch=master)](https://travis-ci.org/martijnversluis/ChordSheetJS) [![npm version](https://badge.fury.io/js/chordsheetjs.svg)](https://badge.fury.io/js/chordsheetjs) [![Code Climate](https://codeclimate.com/github/martijnversluis/ChordSheetJS/badges/gpa.svg)](https://codeclimate.com/github/martijnversluis/ChordSheetJS)
1
+ # ChordSheetJS ![example branch parameter](https://github.com/martijnversluis/ChordSheetJS/actions/workflows/ci.yml/badge.svg?branch=master) [![npm version](https://badge.fury.io/js/chordsheetjs.svg)](https://badge.fury.io/js/chordsheetjs) [![Code Climate](https://codeclimate.com/github/martijnversluis/ChordSheetJS/badges/gpa.svg)](https://codeclimate.com/github/martijnversluis/ChordSheetJS)
2
2
 
3
3
  A JavaScript library for parsing and formatting chord sheets
4
4
 
@@ -138,6 +138,113 @@ HtmlTableFormatter.cssObject();
138
138
  // }
139
139
  ```
140
140
 
141
+ ### Parsing and modifying chords
142
+
143
+ ```javascript
144
+ import { parseChord } from 'chordsheetjs';
145
+ ```
146
+
147
+ #### Parse
148
+
149
+ ```javascript
150
+ const chord = parseChord('Ebsus4/Bb');
151
+ ```
152
+
153
+ Parse numeric chords (Nashville system):
154
+
155
+ ```javascript
156
+ const chord = parseChord('b1sus4/#3');
157
+ ```
158
+
159
+ #### Display with #toString
160
+
161
+ Use #toString() to convert the chord to a chord string (eg Dsus/F#)
162
+
163
+ ```javascript
164
+ const chord = parseChord('Ebsus4/Bb');
165
+ chord.toString(); // --> "Ebsus4/Bb"
166
+ ```
167
+
168
+ #### Clone
169
+
170
+ ```javascript
171
+ var chord2 = chord.clone();
172
+ ```
173
+
174
+ #### Normalize
175
+
176
+ Normalizes keys B#, E#, Cb and Fb to C, F, B and E
177
+
178
+ ```javascript
179
+ const chord = parseChord('E#/B#'),
180
+ normalizedChord = chord.normalize();
181
+ normalizedChord.toString(); // --> "F/C"
182
+ ```
183
+
184
+ #### Switch modifier
185
+
186
+ Convert # to b and vice versa
187
+
188
+ ```javascript
189
+ const chord = parseChord('Eb/Bb');
190
+ const chord2 = chord.switchModifier();
191
+ chord2.toString(); // --> "D#/A#"
192
+ ```
193
+
194
+ #### Use specific modifier
195
+
196
+ Set the chord to a specific modifier (# or b)
197
+
198
+ ```javascript
199
+ const chord = parseChord('Eb/Bb');
200
+ const chord2 = chord.useModifier('#');
201
+ chord2.toString(); // --> "D#/A#"
202
+ ```
203
+
204
+ ```javascript
205
+ const chord = parseChord('Eb/Bb');
206
+ const chord2 = chord.useModifier('b');
207
+ chord2.toString(); // --> "Eb/Bb"
208
+ ```
209
+
210
+ #### Transpose up
211
+
212
+ ```javascript
213
+ const chord = parseChord('Eb/Bb');
214
+ const chord2 = chord.transposeUp();
215
+ chord2.toString(); // -> "E/B"
216
+ ```
217
+
218
+ #### Transpose down
219
+
220
+ ```javascript
221
+ const chord = parseChord('Eb/Bb');
222
+ const chord2 = chord.transposeDown();
223
+ chord2.toString(); // -> "D/A"
224
+ ```
225
+
226
+ #### Transpose
227
+
228
+ ```javascript
229
+ const chord = parseChord('C/E');
230
+ const chord2 = chord.transpose(4);
231
+ chord2.toString(); // -> "E/G#"
232
+ ```
233
+
234
+ ```javascript
235
+ const chord = parseChord('C/E');
236
+ const chord2 = chord.transpose(-4);
237
+ chord2.toString(); // -> "Ab/C"
238
+ ```
239
+
240
+ #### Convert numeric chord to chord symbol
241
+
242
+ ```javascript
243
+ const numericChord = parseChord('2/4');
244
+ const chordSymbol = toChordSymbol(numericChord, 'E');
245
+ chordSymbol.toString(); // -> "F#m/A"
246
+ ```
247
+
141
248
  ## Supported ChordPro directives
142
249
 
143
250
  :heavy_check_mark: = supported
@@ -288,9 +395,18 @@ PDF conversion.</p>
288
395
  <dd><p>Parses an Ultimate Guitar chord sheet with metadata
289
396
  Inherits from <a href="#ChordSheetParser">ChordSheetParser</a></p>
290
397
  </dd>
398
+ <dt><a href="#Chord">Chord</a></dt>
399
+ <dd><p>Base class for <a href="#ChordSymbol">ChordSymbol</a> and <a href="#NumericChord">NumericChord</a></p>
400
+ </dd>
291
401
  <dt><a href="#ChordSheetSerializer">ChordSheetSerializer</a></dt>
292
402
  <dd><p>Serializes a song into een plain object, and deserializes the serialized object back into a <a href="#Song">Song</a></p>
293
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>
294
410
  </dl>
295
411
 
296
412
  ## Constants
@@ -326,6 +442,9 @@ Inherits from <a href="#ChordSheetParser">ChordSheetParser</a></p>
326
442
  <dt><a href="#KEY">KEY</a> : <code>string</code></dt>
327
443
  <dd><p>Key meta directive. See <a href="https://www.chordpro.org/chordpro/directives-key/">https://www.chordpro.org/chordpro/directives-key/</a></p>
328
444
  </dd>
445
+ <dt><a href="#_KEY">_KEY</a> : <code>string</code></dt>
446
+ <dd><p>Key meta directive. See <a href="https://www.chordpro.org/chordpro/directives-key/">https://www.chordpro.org/chordpro/directives-key/</a></p>
447
+ </dd>
329
448
  <dt><a href="#LYRICIST">LYRICIST</a> : <code>string</code></dt>
330
449
  <dd><p>Lyricist meta directive. See <a href="https://www.chordpro.org/chordpro/directives-lyricist/">https://www.chordpro.org/chordpro/directives-lyricist/</a></p>
331
450
  </dd>
@@ -372,7 +491,13 @@ For a CSS string see <a href="#scopedCss">scopedCss</a></p>
372
491
 
373
492
  <dl>
374
493
  <dt><a href="#scopedCss">scopedCss(scope)</a> ⇒ <code>string</code></dt>
375
- <dd><p>Generates basic CSS, scoped within the provided selector, to use with output generated by {@link }HtmlTableFormatter}</p>
494
+ <dd><p>Generates basic CSS, scoped within the provided selector, to use with output generated by <a href="#HtmlTableFormatter">HtmlTableFormatter</a></p>
495
+ </dd>
496
+ <dt><a href="#parseChord">parseChord(chordString)</a> ⇒ <code>null</code> | <code><a href="#ChordSymbol">ChordSymbol</a></code> | <code><a href="#NumericChord">NumericChord</a></code></dt>
497
+ <dd><p>Tries to parse a chord string into a chord</p>
498
+ </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>
376
501
  </dd>
377
502
  </dl>
378
503
 
@@ -1037,6 +1162,18 @@ Parses an Ultimate Guitar chord sheet with metadata
1037
1162
  Inherits from [ChordSheetParser](#ChordSheetParser)
1038
1163
 
1039
1164
  **Kind**: global class
1165
+ <a name="Chord"></a>
1166
+
1167
+ ## Chord
1168
+ Base class for [ChordSymbol](#ChordSymbol) and [NumericChord](#NumericChord)
1169
+
1170
+ **Kind**: global class
1171
+ <a name="Chord+clone"></a>
1172
+
1173
+ ### chord.clone() ⇒ [<code>Chord</code>](#Chord)
1174
+ Returns a deep copy of the chord
1175
+
1176
+ **Kind**: instance method of [<code>Chord</code>](#Chord)
1040
1177
  <a name="ChordSheetSerializer"></a>
1041
1178
 
1042
1179
  ## ChordSheetSerializer
@@ -1068,6 +1205,147 @@ Deserializes a song that has been serialized using [serialize](serialize)
1068
1205
  | --- | --- | --- |
1069
1206
  | serializedSong | <code>object</code> | The serialized song |
1070
1207
 
1208
+ <a name="ChordSymbol"></a>
1209
+
1210
+ ## ChordSymbol
1211
+ Represents a chord symbol, such as Esus4
1212
+
1213
+ **Kind**: global class
1214
+
1215
+ * [ChordSymbol](#ChordSymbol)
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>
1223
+
1224
+ <a name="ChordSymbol+normalize"></a>
1225
+
1226
+ ### chordSymbol.normalize() ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
1227
+ Normalizes the chord:
1228
+ - Fb becomes E
1229
+ - Cb becomes B
1230
+ - B# becomes C
1231
+ - E# becomes F
1232
+ If the chord is already normalized, this will return a copy.
1233
+
1234
+ **Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
1235
+ **Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the normalized chord
1236
+ <a name="ChordSymbol+switchModifier"></a>
1237
+
1238
+ ### chordSymbol.switchModifier() ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
1239
+ Switches between '#' and 'b' as modifiers. If
1240
+
1241
+ **Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
1242
+ **Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the changed chord
1243
+ <a name="ChordSymbol+useModifier"></a>
1244
+
1245
+ ### chordSymbol.useModifier(newModifier) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
1246
+ Switches to the specified modifier
1247
+
1248
+ **Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
1249
+ **Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the changed chord
1250
+
1251
+ | Param | Description |
1252
+ | --- | --- |
1253
+ | newModifier | the modifier to use: `'#'` or `'b'` |
1254
+
1255
+ <a name="ChordSymbol+transposeUp"></a>
1256
+
1257
+ ### chordSymbol.transposeUp() ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
1258
+ Transposes the chord up by 1 semitone. Eg. A becomes A#, Eb becomes E
1259
+
1260
+ **Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
1261
+ **Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the transposed chord
1262
+ <a name="ChordSymbol+transposeDown"></a>
1263
+
1264
+ ### chordSymbol.transposeDown() ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
1265
+ Transposes the chord down by 1 semitone. Eg. A# becomes A, E becomes Eb
1266
+
1267
+ **Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
1268
+ **Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the transposed chord
1269
+ <a name="ChordSymbol+transpose"></a>
1270
+
1271
+ ### chordSymbol.transpose(delta) ⇒ [<code>ChordSymbol</code>](#ChordSymbol)
1272
+ Transposes the chord by the specified number of semitones
1273
+
1274
+ **Kind**: instance method of [<code>ChordSymbol</code>](#ChordSymbol)
1275
+ **Returns**: [<code>ChordSymbol</code>](#ChordSymbol) - the transposed chord
1276
+
1277
+ | Param | Description |
1278
+ | --- | --- |
1279
+ | delta | de number of semitones |
1280
+
1281
+ <a name="ChordSymbol+toString"></a>
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)
1301
+
1302
+ <a name="NumericChord+normalize"></a>
1303
+
1304
+ ### numericChord.normalize() ⇒ [<code>NumericChord</code>](#NumericChord)
1305
+ Normalizes the chord - this is a noop for numeric chords.
1306
+
1307
+ **Kind**: instance method of [<code>NumericChord</code>](#NumericChord)
1308
+ **Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
1309
+ <a name="NumericChord+switchModifier"></a>
1310
+
1311
+ ### numericChord.switchModifier() ⇒ [<code>NumericChord</code>](#NumericChord)
1312
+ Switches between '#' and 'b' as modifiers - this is a noop for numeric chords.
1313
+
1314
+ **Kind**: instance method of [<code>NumericChord</code>](#NumericChord)
1315
+ **Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
1316
+ <a name="NumericChord+useModifier"></a>
1317
+
1318
+ ### numericChord.useModifier() ⇒ [<code>NumericChord</code>](#NumericChord)
1319
+ Switches to the specified modifier - this is a noop for numeric chords.
1320
+
1321
+ **Kind**: instance method of [<code>NumericChord</code>](#NumericChord)
1322
+ **Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
1323
+ <a name="NumericChord+transposeUp"></a>
1324
+
1325
+ ### numericChord.transposeUp() ⇒ [<code>NumericChord</code>](#NumericChord)
1326
+ Transposes the chord up by 1 semitone - this is a noop for numeric chords.
1327
+
1328
+ **Kind**: instance method of [<code>NumericChord</code>](#NumericChord)
1329
+ **Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
1330
+ <a name="NumericChord+transposeDown"></a>
1331
+
1332
+ ### numericChord.transposeDown() ⇒ [<code>NumericChord</code>](#NumericChord)
1333
+ Transposes the chord down by 1 semitone - this is a noop for numeric chords.
1334
+
1335
+ **Kind**: instance method of [<code>NumericChord</code>](#NumericChord)
1336
+ **Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
1337
+ <a name="NumericChord+transpose"></a>
1338
+
1339
+ ### numericChord.transpose(delta) ⇒ [<code>NumericChord</code>](#NumericChord)
1340
+ Transposes the chord by the specified number of semitones - this is a noop for numeric chords.
1341
+
1342
+ **Kind**: instance method of [<code>NumericChord</code>](#NumericChord)
1343
+ **Returns**: [<code>NumericChord</code>](#NumericChord) - a copy of the chord object
1344
+
1345
+ | Param | Description |
1346
+ | --- | --- |
1347
+ | delta | de number of semitones |
1348
+
1071
1349
  <a name="ALBUM"></a>
1072
1350
 
1073
1351
  ## ALBUM : <code>string</code>
@@ -1127,6 +1405,12 @@ End of verse directive. See https://www.chordpro.org/chordpro/directives-env_ver
1127
1405
  ## KEY : <code>string</code>
1128
1406
  Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
1129
1407
 
1408
+ **Kind**: global constant
1409
+ <a name="_KEY"></a>
1410
+
1411
+ ## \_KEY : <code>string</code>
1412
+ Key meta directive. See https://www.chordpro.org/chordpro/directives-key/
1413
+
1130
1414
  **Kind**: global constant
1131
1415
  <a name="LYRICIST"></a>
1132
1416
 
@@ -1210,7 +1494,7 @@ Used to mark a paragraph as containing lines with both verse and chorus type
1210
1494
  <a name="scopedCss"></a>
1211
1495
 
1212
1496
  ## scopedCss(scope) ⇒ <code>string</code>
1213
- Generates basic CSS, scoped within the provided selector, to use with output generated by {@link }HtmlTableFormatter}
1497
+ Generates basic CSS, scoped within the provided selector, to use with output generated by [HtmlTableFormatter](#HtmlTableFormatter)
1214
1498
 
1215
1499
  **Kind**: global function
1216
1500
  **Returns**: <code>string</code> - the CSS string
@@ -1219,3 +1503,27 @@ Generates basic CSS, scoped within the provided selector, to use with output gen
1219
1503
  | --- | --- |
1220
1504
  | scope | the CSS scope to use, for example `.chordSheetViewer` |
1221
1505
 
1506
+ <a name="parseChord"></a>
1507
+
1508
+ ## parseChord(chordString) ⇒ <code>null</code> \| [<code>ChordSymbol</code>](#ChordSymbol) \| [<code>NumericChord</code>](#NumericChord)
1509
+ Tries to parse a chord string into a chord
1510
+
1511
+ **Kind**: global function
1512
+
1513
+ | Param | Description |
1514
+ | --- | --- |
1515
+ | chordString | the chord string, eg Esus4/G# or 1sus4/#3 |
1516
+
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
+
package/lib/chord.js ADDED
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
9
+
10
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
11
+
12
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+
14
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
+
16
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
17
+
18
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
19
+
20
+ /**
21
+ * Base class for {@link ChordSymbol} and {@link NumericChord}
22
+ */
23
+ var Chord = /*#__PURE__*/function () {
24
+ function Chord(_ref) {
25
+ var base = _ref.base,
26
+ modifier = _ref.modifier,
27
+ suffix = _ref.suffix,
28
+ bassBase = _ref.bassBase,
29
+ bassModifier = _ref.bassModifier;
30
+
31
+ _classCallCheck(this, Chord);
32
+
33
+ this.base = base || null;
34
+ this.modifier = modifier || null;
35
+ this.suffix = suffix || null;
36
+ this.bassBase = bassBase || null;
37
+ this.bassModifier = bassModifier || null;
38
+ }
39
+ /**
40
+ * Returns a deep copy of the chord
41
+ * @returns {Chord}
42
+ */
43
+
44
+
45
+ _createClass(Chord, [{
46
+ key: "clone",
47
+ value: function clone() {
48
+ var base = this.base,
49
+ modifier = this.modifier,
50
+ suffix = this.suffix,
51
+ bassBase = this.bassBase,
52
+ bassModifier = this.bassModifier;
53
+ return new this.constructor({
54
+ base: base,
55
+ modifier: modifier,
56
+ suffix: suffix,
57
+ bassBase: bassBase,
58
+ bassModifier: bassModifier
59
+ });
60
+ }
61
+ }, {
62
+ key: "set",
63
+ value: function set(properties) {
64
+ return new this.constructor(_objectSpread({
65
+ base: this.base,
66
+ modifier: this.modifier,
67
+ suffix: this.suffix,
68
+ bassBase: this.bassBase,
69
+ bassModifier: this.bassModifier
70
+ }, properties));
71
+ }
72
+ }]);
73
+
74
+ return Chord;
75
+ }();
76
+
77
+ var _default = Chord;
78
+ exports["default"] = _default;
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.deprecate = deprecate;
7
+ exports.internalSwitchModifier = internalSwitchModifier;
8
+ exports.isEmptyString = isEmptyString;
9
+ exports.keyDown = keyDown;
10
+ exports.keyUp = keyUp;
11
+ exports.normalize = normalize;
12
+ exports.processChord = processChord;
13
+ exports.switchModifier = switchModifier;
14
+ exports.transpose = transpose;
15
+ exports.transposeDown = transposeDown;
16
+ exports.transposeUp = transposeUp;
17
+ exports.useModifier = useModifier;
18
+
19
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
20
+
21
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
22
+
23
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+
25
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
26
+
27
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
28
+
29
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
30
+
31
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
+
33
+ var A = 'A'.charCodeAt(0);
34
+ var G = 'G'.charCodeAt(0);
35
+
36
+ function keyChange(key, delta) {
37
+ var charCode;
38
+ charCode = key.toUpperCase().charCodeAt(0);
39
+ charCode += delta;
40
+
41
+ if (charCode > G) {
42
+ charCode = A;
43
+ }
44
+
45
+ if (charCode < A) {
46
+ charCode = G;
47
+ }
48
+
49
+ return String.fromCharCode(charCode);
50
+ }
51
+
52
+ function keyUp(key) {
53
+ return keyChange(key, 1);
54
+ }
55
+
56
+ function keyDown(key) {
57
+ return keyChange(key, -1);
58
+ }
59
+
60
+ function normalize(base, modifier) {
61
+ if (modifier === '#' && /^(B|E)$/.test(base)) {
62
+ return [keyUp(base), null];
63
+ }
64
+
65
+ if (modifier === 'b' && /^(C|F)$/.test(base)) {
66
+ return [keyDown(base), null];
67
+ }
68
+
69
+ return [base, modifier];
70
+ }
71
+
72
+ function internalSwitchModifier(base, modifier) {
73
+ if (modifier === '#') {
74
+ return [keyUp(base), 'b'];
75
+ }
76
+
77
+ if (modifier === 'b') {
78
+ return [keyDown(base), '#'];
79
+ }
80
+
81
+ throw new Error("Unexpected modifier ".concat(modifier));
82
+ }
83
+
84
+ function switchModifier(base, modifier) {
85
+ var _normalize = normalize(base, modifier),
86
+ _normalize2 = _slicedToArray(_normalize, 2),
87
+ normalizedBase = _normalize2[0],
88
+ normalizedModifier = _normalize2[1];
89
+
90
+ if (modifier) {
91
+ return internalSwitchModifier(normalizedBase, normalizedModifier);
92
+ }
93
+
94
+ return [normalizedBase, normalizedModifier];
95
+ }
96
+
97
+ function useModifier(base, modifier, newModifier) {
98
+ if (modifier && modifier !== newModifier) {
99
+ return internalSwitchModifier(base, modifier);
100
+ }
101
+
102
+ return [base, modifier];
103
+ }
104
+
105
+ function repeatProcessor(base, modifier, processor, amount) {
106
+ var processedBase = base,
107
+ processedModifier = modifier;
108
+
109
+ for (var i = 0; i < amount; i += 1) {
110
+ var _processor = processor(processedBase, processedModifier);
111
+
112
+ var _processor2 = _slicedToArray(_processor, 2);
113
+
114
+ processedBase = _processor2[0];
115
+ processedModifier = _processor2[1];
116
+ }
117
+
118
+ return [processedBase, processedModifier];
119
+ }
120
+
121
+ function transposeUp(base, modifier) {
122
+ var _normalize3 = normalize(base, modifier),
123
+ _normalize4 = _slicedToArray(_normalize3, 2),
124
+ normalizedBase = _normalize4[0],
125
+ normalizedModifier = _normalize4[1];
126
+
127
+ if (normalizedModifier === 'b') {
128
+ return [normalizedBase, null];
129
+ }
130
+
131
+ if (normalizedModifier === '#') {
132
+ return [keyUp(normalizedBase), null];
133
+ }
134
+
135
+ if (/^(B|E)$/.test(normalizedBase)) {
136
+ return [keyUp(normalizedBase), null];
137
+ }
138
+
139
+ return [normalizedBase, '#'];
140
+ }
141
+
142
+ function transposeDown(base, modifier) {
143
+ var _normalize5 = normalize(base, modifier),
144
+ _normalize6 = _slicedToArray(_normalize5, 2),
145
+ normalizedBase = _normalize6[0],
146
+ normalizedModifier = _normalize6[1];
147
+
148
+ if (normalizedModifier === 'b') {
149
+ return [keyDown(normalizedBase), null];
150
+ }
151
+
152
+ if (normalizedModifier === '#') {
153
+ return [normalizedBase, null];
154
+ }
155
+
156
+ if (/^(C|F)$/.test(normalizedBase)) {
157
+ return [keyDown(normalizedBase), null];
158
+ }
159
+
160
+ return [normalizedBase, 'b'];
161
+ }
162
+
163
+ function transpose(base, modifier, delta) {
164
+ var newBase = base,
165
+ newModifier = modifier;
166
+
167
+ if (delta < 0) {
168
+ var _repeatProcessor = repeatProcessor(base, modifier, transposeDown, Math.abs(delta));
169
+
170
+ var _repeatProcessor2 = _slicedToArray(_repeatProcessor, 2);
171
+
172
+ newBase = _repeatProcessor2[0];
173
+ newModifier = _repeatProcessor2[1];
174
+ } else if (delta > 0) {
175
+ var _repeatProcessor3 = repeatProcessor(base, modifier, transposeUp, delta);
176
+
177
+ var _repeatProcessor4 = _slicedToArray(_repeatProcessor3, 2);
178
+
179
+ newBase = _repeatProcessor4[0];
180
+ newModifier = _repeatProcessor4[1];
181
+ }
182
+
183
+ return useModifier(newBase, newModifier, modifier);
184
+ }
185
+
186
+ function processChord(sourceChord, processor, processorArg) {
187
+ var chord = sourceChord.clone();
188
+
189
+ var _processor3 = processor(sourceChord.base, sourceChord.modifier, processorArg);
190
+
191
+ var _processor4 = _slicedToArray(_processor3, 2);
192
+
193
+ chord.base = _processor4[0];
194
+ chord.modifier = _processor4[1];
195
+
196
+ if (sourceChord.bassBase) {
197
+ var _processor5 = processor(sourceChord.bassBase, sourceChord.bassModifier, processorArg);
198
+
199
+ var _processor6 = _slicedToArray(_processor5, 2);
200
+
201
+ chord.bassBase = _processor6[0];
202
+ chord.bassModifier = _processor6[1];
203
+ }
204
+
205
+ return chord;
206
+ }
207
+
208
+ function deprecate(message) {
209
+ try {
210
+ throw new Error("DEPRECATION: ".concat(message));
211
+ } catch (e) {
212
+ if ((typeof process === "undefined" ? "undefined" : _typeof(process)) === 'object' && typeof process.emitWarning === 'function') {
213
+ process.emitWarning("".concat(message, "\n").concat(e.stack));
214
+ } else {
215
+ console.warn("".concat(message, "\n").concat(e.stack));
216
+ }
217
+ }
218
+ }
219
+
220
+ function isEmptyString(string) {
221
+ return string === null || string === undefined || string === '';
222
+ }
@@ -13,7 +13,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
13
13
 
14
14
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
15
 
16
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
16
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
17
17
 
18
18
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
19