chordsheetjs 5.2.0 → 5.3.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/lib/chord.js CHANGED
@@ -42,6 +42,18 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
42
42
 
43
43
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
44
44
 
45
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
46
+
47
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
48
+
49
+ 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); }
50
+
51
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
52
+
53
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
54
+
55
+ 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; }
56
+
45
57
  function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, void 0, groups); }; var _super = RegExp.prototype, _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); return _groups.set(_this, groups || _groups.get(re)), _setPrototypeOf(_this, BabelRegExp.prototype); } function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { return groups[name] = result[g[name]], groups; }, Object.create(null)); } return _inherits(BabelRegExp, RegExp), BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); return result && (result.groups = buildGroups(result, this)), result; }, BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if ("string" == typeof substitution) { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } if ("function" == typeof substitution) { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; return "object" != _typeof(args[args.length - 1]) && (args = [].slice.call(args)).push(buildGroups(args, _this)), substitution.apply(this, args); }); } return _super[Symbol.replace].call(this, str, substitution); }, _wrapRegExp.apply(this, arguments); }
46
58
 
47
59
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
@@ -83,7 +95,16 @@ var numericChordRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?([1-7])((?:(?![\t-\r \/
83
95
  bassBase: 6
84
96
  });
85
97
 
86
- var regexes = [numericChordRegex, chordRegex];
98
+ var sortedNumerals = _toConsumableArray(_constants.ROMAN_NUMERALS).sort(function (numeralA, numeralB) {
99
+ return numeralB.length - numeralA.length;
100
+ });
101
+
102
+ var numerals = [].concat(_toConsumableArray(sortedNumerals), _toConsumableArray(sortedNumerals.map(function (numeral) {
103
+ return numeral.toLowerCase();
104
+ }))).join('|');
105
+ var numeralChordRegex = // eslint-disable-next-line max-len
106
+ new RegExp("^(?<modifier>#|b)?(?<base>".concat(numerals, ")(?<suffix>[^/\\s]*)(\\/(?<bassModifier>#|b)?(?<bassBase>").concat(numerals, "))?$"));
107
+ var regexes = [numericChordRegex, numeralChordRegex, chordRegex];
87
108
  /**
88
109
  * Represents a Chord, consisting of a root, suffix (quality) and bass
89
110
  */
@@ -162,11 +183,17 @@ var Chord = /*#__PURE__*/function () {
162
183
 
163
184
  var keyObj = _key["default"].wrap(key);
164
185
 
165
- return new Chord({
186
+ var chordSymbolChord = new Chord({
166
187
  suffix: chordSuffix(_classPrivateFieldGet(this, _rootNote), this.suffix),
167
188
  root: this.root.toChordSymbol(keyObj),
168
189
  bass: (_this$bass = this.bass) === null || _this$bass === void 0 ? void 0 : _this$bass.toChordSymbol(keyObj)
169
190
  });
191
+
192
+ if (this.root.isMinor()) {
193
+ chordSymbolChord = chordSymbolChord.makeMinor();
194
+ }
195
+
196
+ return chordSymbolChord;
170
197
  }
171
198
  /**
172
199
  * Converts the chord to a chord symbol string, using the supplied key as a reference.
@@ -193,7 +220,7 @@ var Chord = /*#__PURE__*/function () {
193
220
  return _classPrivateMethodGet(this, _is, _is2).call(this, _constants.SYMBOL);
194
221
  }
195
222
  /**
196
- * Converts the chord to a numeric chord, using the supplied kye as a reference.
223
+ * Converts the chord to a numeric chord, using the supplied key as a reference.
197
224
  * For example, a chord symbol A# with reference key E will return the numeric chord #4.
198
225
  * @param {Key|string} key the reference key
199
226
  * @returns {Chord} the numeric chord
@@ -202,20 +229,77 @@ var Chord = /*#__PURE__*/function () {
202
229
  }, {
203
230
  key: "toNumeric",
204
231
  value: function toNumeric(key) {
205
- var _this$bass2;
232
+ var _this$bass3;
206
233
 
207
234
  if (this.isNumeric()) {
208
235
  return this.clone();
209
236
  }
210
237
 
238
+ if (this.isNumeral()) {
239
+ var _this$bass2;
240
+
241
+ return this.set({
242
+ root: this.root.toNumeric(),
243
+ bass: (_this$bass2 = this.bass) === null || _this$bass2 === void 0 ? void 0 : _this$bass2.toNumeric()
244
+ });
245
+ }
246
+
211
247
  var keyObj = _key["default"].wrap(key);
212
248
 
213
249
  return new Chord({
214
250
  suffix: chordSuffix(_classPrivateFieldGet(this, _rootNote), this.suffix),
215
251
  root: this.root.toNumeric(keyObj),
216
- bass: (_this$bass2 = this.bass) === null || _this$bass2 === void 0 ? void 0 : _this$bass2.toNumeric(keyObj)
252
+ bass: (_this$bass3 = this.bass) === null || _this$bass3 === void 0 ? void 0 : _this$bass3.toNumeric(keyObj)
253
+ });
254
+ }
255
+ /**
256
+ * Converts the chord to a numeral chord, using the supplied key as a reference.
257
+ * For example, a chord symbol A# with reference key E will return the numeral chord #IV.
258
+ * @param {Key|string|null} key the reference key. The key is required when converting a chord symbol
259
+ * @returns {Chord} the numeral chord
260
+ */
261
+
262
+ }, {
263
+ key: "toNumeral",
264
+ value: function toNumeral() {
265
+ var _this$bass5;
266
+
267
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
268
+
269
+ if (this.isNumeral()) {
270
+ return this.clone();
271
+ }
272
+
273
+ if (this.isNumeric()) {
274
+ var _this$bass4;
275
+
276
+ return this.set({
277
+ root: this.root.toNumeral(),
278
+ bass: (_this$bass4 = this.bass) === null || _this$bass4 === void 0 ? void 0 : _this$bass4.toNumeral()
279
+ });
280
+ }
281
+
282
+ var keyObj = _key["default"].wrap(key);
283
+
284
+ return new Chord({
285
+ suffix: chordSuffix(_classPrivateFieldGet(this, _rootNote), this.suffix),
286
+ root: this.root.toNumeral(keyObj),
287
+ bass: (_this$bass5 = this.bass) === null || _this$bass5 === void 0 ? void 0 : _this$bass5.toNumeral(keyObj)
217
288
  });
218
289
  }
290
+ /**
291
+ * Converts the chord to a numeral chord string, using the supplied kye as a reference.
292
+ * For example, a chord symbol A# with reference key E will return the numeral chord #4.
293
+ * @param {Key|string} key the reference key
294
+ * @returns {string} the numeral chord string
295
+ * @see {toNumeral}
296
+ */
297
+
298
+ }, {
299
+ key: "toNumeralString",
300
+ value: function toNumeralString(key) {
301
+ return this.toNumeral(key).toString();
302
+ }
219
303
  /**
220
304
  * Determines whether the chord is numeric
221
305
  * @returns {boolean}
@@ -239,6 +323,16 @@ var Chord = /*#__PURE__*/function () {
239
323
  value: function toNumericString(key) {
240
324
  return this.toNumeric(key).toString();
241
325
  }
326
+ /**
327
+ * Determines whether the chord is a numeral
328
+ * @returns {boolean}
329
+ */
330
+
331
+ }, {
332
+ key: "isNumeral",
333
+ value: function isNumeral() {
334
+ return _classPrivateMethodGet(this, _is, _is2).call(this, _constants.NUMERAL);
335
+ }
242
336
  /**
243
337
  * Converts the chord to a string, eg `Esus4/G#` or `1sus4/#3`
244
338
  * @returns {string} the chord string
@@ -317,15 +411,26 @@ var Chord = /*#__PURE__*/function () {
317
411
  value: function transpose(delta) {
318
412
  return _classPrivateMethodGet(this, _process, _process2).call(this, 'transpose', delta);
319
413
  }
414
+ }, {
415
+ key: "makeMinor",
416
+ value: function makeMinor() {
417
+ if (!this.suffix || this.suffix[0] !== 'm') {
418
+ return this.set({
419
+ suffix: "m".concat(this.suffix || '')
420
+ });
421
+ }
422
+
423
+ return this.clone();
424
+ }
320
425
  }, {
321
426
  key: "set",
322
427
  value: function set(properties) {
323
- var _this$bass3;
428
+ var _this$bass6;
324
429
 
325
430
  return new this.constructor(_objectSpread({
326
431
  root: this.root.clone(),
327
432
  suffix: this.suffix,
328
- bass: (_this$bass3 = this.bass) === null || _this$bass3 === void 0 ? void 0 : _this$bass3.clone()
433
+ bass: (_this$bass6 = this.bass) === null || _this$bass6 === void 0 ? void 0 : _this$bass6.clone()
329
434
  }, properties));
330
435
  }
331
436
  }], [{
package/lib/constants.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.VERSE = exports.TAB = exports.SYMBOL = exports.NUMERIC = exports.NONE = exports.INDETERMINATE = exports.CHORUS = void 0;
6
+ exports.VERSE = exports.TAB = exports.SYMBOL = exports.ROMAN_NUMERALS = exports.NUMERIC = exports.NUMERAL = exports.NONE = exports.INDETERMINATE = exports.CHORUS = void 0;
7
7
 
8
8
  /**
9
9
  * Used to mark a paragraph as verse
@@ -47,4 +47,8 @@ exports.TAB = TAB;
47
47
  var SYMBOL = 'symbol';
48
48
  exports.SYMBOL = SYMBOL;
49
49
  var NUMERIC = 'numeric';
50
- exports.NUMERIC = NUMERIC;
50
+ exports.NUMERIC = NUMERIC;
51
+ var NUMERAL = 'numeral';
52
+ exports.NUMERAL = NUMERAL;
53
+ var ROMAN_NUMERALS = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII'];
54
+ exports.ROMAN_NUMERALS = ROMAN_NUMERALS;
package/lib/key.js CHANGED
@@ -53,7 +53,12 @@ var numericKeyRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?([1-7])$/, {
53
53
  note: 2
54
54
  });
55
55
 
56
- var regexes = [symbolKeyRegex, numericKeyRegex];
56
+ var numeralKeyRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?(I{1,3}|IV|VI{0,2}|i{1,3}|iv|vi{0,2})$/, {
57
+ modifier: 1,
58
+ note: 2
59
+ });
60
+
61
+ var regexes = [symbolKeyRegex, numericKeyRegex, numeralKeyRegex];
57
62
 
58
63
  var _set = /*#__PURE__*/new WeakSet();
59
64
 
@@ -67,7 +72,7 @@ var Key = /*#__PURE__*/function () {
67
72
 
68
73
  _classPrivateMethodInitSpec(this, _set);
69
74
 
70
- this.note = note instanceof _note["default"] ? note : new _note["default"](note);
75
+ this.note = note instanceof _note["default"] ? note : _note["default"].parse(note);
71
76
  this.modifier = modifier || null;
72
77
  }
73
78
 
@@ -85,26 +90,16 @@ var Key = /*#__PURE__*/function () {
85
90
 
86
91
  return delta;
87
92
  }
93
+ }, {
94
+ key: "isMinor",
95
+ value: function isMinor() {
96
+ return this.note.isMinor();
97
+ }
88
98
  }, {
89
99
  key: "clone",
90
100
  value: function clone() {
91
101
  return _classPrivateMethodGet(this, _set, _set2).call(this, {});
92
102
  }
93
- }, {
94
- key: "toChordSymbol",
95
- value: function toChordSymbol(key) {
96
- if (this.is(_constants.SYMBOL)) {
97
- return this.clone();
98
- }
99
-
100
- var transposeDistance = this.note.getTransposeDistance() + (MODIFIER_TRANSPOSITION[this.modifier] || 0);
101
- return key.transpose(transposeDistance).normalize().useModifier(key.modifier);
102
- }
103
- }, {
104
- key: "toChordSymbolString",
105
- value: function toChordSymbolString(key) {
106
- return this.toChordSymbol(key).toString();
107
- }
108
103
  }, {
109
104
  key: "is",
110
105
  value: function is(type) {
@@ -120,6 +115,33 @@ var Key = /*#__PURE__*/function () {
120
115
  value: function isChordSymbol() {
121
116
  return this.is(_constants.SYMBOL);
122
117
  }
118
+ }, {
119
+ key: "isNumeral",
120
+ value: function isNumeral() {
121
+ return this.is(_constants.NUMERAL);
122
+ }
123
+ }, {
124
+ key: "equals",
125
+ value: function equals(_ref2) {
126
+ var note = _ref2.note,
127
+ modifier = _ref2.modifier;
128
+ return this.note.equals(note) && this.modifier === modifier;
129
+ }
130
+ }, {
131
+ key: "toChordSymbol",
132
+ value: function toChordSymbol(key) {
133
+ if (this.is(_constants.SYMBOL)) {
134
+ return this.clone();
135
+ }
136
+
137
+ var transposeDistance = this.note.getTransposeDistance() + (MODIFIER_TRANSPOSITION[this.modifier] || 0);
138
+ return key.transpose(transposeDistance).normalize().useModifier(key.modifier);
139
+ }
140
+ }, {
141
+ key: "toChordSymbolString",
142
+ value: function toChordSymbolString(key) {
143
+ return this.toChordSymbol(key).toString();
144
+ }
123
145
  }, {
124
146
  key: "toNumeric",
125
147
  value: function toNumeric(key) {
@@ -127,6 +149,12 @@ var Key = /*#__PURE__*/function () {
127
149
  return this.clone();
128
150
  }
129
151
 
152
+ if (this.isNumeral()) {
153
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
154
+ note: this.note.toNumeric()
155
+ });
156
+ }
157
+
130
158
  var numericKey = new Key({
131
159
  note: 1
132
160
  });
@@ -140,26 +168,50 @@ var Key = /*#__PURE__*/function () {
140
168
 
141
169
  return numericKey;
142
170
  }
143
- }, {
144
- key: "equals",
145
- value: function equals(_ref2) {
146
- var note = _ref2.note,
147
- modifier = _ref2.modifier;
148
- return this.note.equals(note) && this.modifier === modifier;
149
- }
150
171
  }, {
151
172
  key: "toNumericString",
152
173
  value: function toNumericString(key) {
153
174
  return this.toNumeric(key).toString();
154
175
  }
176
+ }, {
177
+ key: "toNumeral",
178
+ value: function toNumeral(key) {
179
+ if (this.isNumeral()) {
180
+ return this.clone();
181
+ }
182
+
183
+ if (this.isNumeric()) {
184
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
185
+ note: this.note.toNumeral()
186
+ });
187
+ }
188
+
189
+ var numeralKey = new Key({
190
+ note: 'I'
191
+ });
192
+ var symbolKey = key.clone();
193
+ var reference = this.clone().normalize().useModifier(key.modifier);
194
+
195
+ while (!symbolKey.equals(reference)) {
196
+ numeralKey = numeralKey.transposeUp().useModifier(key.modifier);
197
+ symbolKey = symbolKey.transposeUp().normalize().useModifier(key.modifier);
198
+ }
199
+
200
+ return numeralKey;
201
+ }
202
+ }, {
203
+ key: "toNumeralString",
204
+ value: function toNumeralString(key) {
205
+ return this.toNumeral(key).toString();
206
+ }
155
207
  }, {
156
208
  key: "toString",
157
209
  value: function toString() {
158
- if (this.is(_constants.NUMERIC)) {
159
- return "".concat(this.modifier || '').concat(this.note);
210
+ if (this.isChordSymbol()) {
211
+ return "".concat(this.note).concat(this.modifier || '');
160
212
  }
161
213
 
162
- return "".concat(this.note).concat(this.modifier || '');
214
+ return "".concat(this.modifier || '').concat(this.note);
163
215
  }
164
216
  }, {
165
217
  key: "transpose",
package/lib/note.js CHANGED
@@ -7,12 +7,24 @@ exports["default"] = void 0;
7
7
 
8
8
  var _constants = require("./constants");
9
9
 
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
+
14
+ 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; }
15
+
10
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
17
 
12
18
  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); } }
13
19
 
14
20
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
21
 
22
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
23
+
24
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
25
+
26
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
27
+
16
28
  var A = 'A'.charCodeAt(0);
17
29
  var G = 'G'.charCodeAt(0);
18
30
  var TRANSPOSE_DISTANCE = [null, 0, 2, 4, 5, 7, 9, 11];
@@ -33,30 +45,84 @@ function clamp(note, min, max) {
33
45
  return newNote;
34
46
  }
35
47
 
48
+ function numeralToNumber(numeral) {
49
+ for (var i = 0, count = _constants.ROMAN_NUMERALS.length; i < count; i += 1) {
50
+ var romanNumeral = _constants.ROMAN_NUMERALS[i];
51
+
52
+ if (romanNumeral === numeral || romanNumeral.toLowerCase() === numeral) {
53
+ return i + 1;
54
+ }
55
+ }
56
+
57
+ return null;
58
+ }
59
+
60
+ function numberToNumeral(number) {
61
+ return _constants.ROMAN_NUMERALS[number - 1];
62
+ }
63
+
64
+ var _set = /*#__PURE__*/new WeakSet();
65
+
36
66
  var Note = /*#__PURE__*/function () {
37
- function Note(note) {
67
+ function Note(_ref) {
68
+ var note = _ref.note,
69
+ type = _ref.type,
70
+ _ref$minor = _ref.minor,
71
+ minor = _ref$minor === void 0 ? false : _ref$minor;
72
+
38
73
  _classCallCheck(this, Note);
39
74
 
40
- if (/^[A-Ga-g]$/.test(note)) {
41
- this.note = note.toUpperCase();
42
- this.type = _constants.SYMBOL;
43
- } else if (/^[1-7]$/.test(note)) {
44
- this.note = parseInt(note, 10);
45
- this.type = _constants.NUMERIC;
46
- } else {
47
- throw new Error("Invalid note ".concat(note));
48
- }
75
+ _classPrivateMethodInitSpec(this, _set);
76
+
77
+ this._note = note;
78
+ this.type = type;
79
+ this.minor = minor;
49
80
  }
50
81
 
51
82
  _createClass(Note, [{
83
+ key: "toNumeral",
84
+ value: function toNumeral() {
85
+ if (this.isNumeral()) {
86
+ return this.clone();
87
+ }
88
+
89
+ if (this.isNumeric()) {
90
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
91
+ type: _constants.NUMERAL
92
+ });
93
+ }
94
+
95
+ throw new Error("Converting a ".concat(this.type, " note to numeral is not supported"));
96
+ }
97
+ }, {
98
+ key: "toNumeric",
99
+ value: function toNumeric() {
100
+ if (this.isNumeric()) {
101
+ return this.clone();
102
+ }
103
+
104
+ if (this.isNumeral()) {
105
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
106
+ type: _constants.NUMERIC
107
+ });
108
+ }
109
+
110
+ throw new Error("Converting a ".concat(this.type, " note to numeric is not supported"));
111
+ }
112
+ }, {
113
+ key: "isMinor",
114
+ value: function isMinor() {
115
+ return this.minor;
116
+ }
117
+ }, {
52
118
  key: "equals",
53
119
  value: function equals(otherNote) {
54
- return this.note === otherNote.note && this.type === otherNote.type;
120
+ return this._note === otherNote._note && this.type === otherNote.type && this.minor === otherNote.minor;
55
121
  }
56
122
  }, {
57
123
  key: "clone",
58
124
  value: function clone() {
59
- return new this.constructor(this.note);
125
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {});
60
126
  }
61
127
  }, {
62
128
  key: "up",
@@ -75,7 +141,7 @@ var Note = /*#__PURE__*/function () {
75
141
  options[_key] = arguments[_key];
76
142
  }
77
143
 
78
- return options.includes(this.note);
144
+ return options.includes(this._note);
79
145
  }
80
146
  }, {
81
147
  key: "isNumeric",
@@ -87,6 +153,11 @@ var Note = /*#__PURE__*/function () {
87
153
  value: function isChordSymbol() {
88
154
  return this.is(_constants.SYMBOL);
89
155
  }
156
+ }, {
157
+ key: "isNumeral",
158
+ value: function isNumeral() {
159
+ return this.is(_constants.NUMERAL);
160
+ }
90
161
  }, {
91
162
  key: "is",
92
163
  value: function is(noteType) {
@@ -95,38 +166,94 @@ var Note = /*#__PURE__*/function () {
95
166
  }, {
96
167
  key: "getTransposeDistance",
97
168
  value: function getTransposeDistance() {
98
- return TRANSPOSE_DISTANCE[this.note];
169
+ return TRANSPOSE_DISTANCE[this._note];
99
170
  }
100
171
  }, {
101
172
  key: "change",
102
173
  value: function change(delta) {
103
- if (this.isNumeric()) {
104
- var newNote = clamp(this.note + delta, 1, 7);
174
+ if (this.isChordSymbol()) {
175
+ var charCode;
176
+ charCode = keyToCharCode(this._note);
177
+ charCode += delta;
178
+ charCode = clamp(charCode, A, G);
179
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
180
+ note: String.fromCharCode(charCode)
181
+ });
182
+ }
183
+
184
+ var newNote = clamp(this._note + delta, 1, 7);
185
+
186
+ if (newNote < 1) {
187
+ newNote += 7;
188
+ } else if (newNote > 7) {
189
+ newNote -= 7;
190
+ }
105
191
 
106
- if (newNote < 1) {
107
- newNote += 7;
108
- } else if (newNote > 7) {
109
- newNote -= 7;
192
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
193
+ note: newNote
194
+ });
195
+ }
196
+ }, {
197
+ key: "note",
198
+ get: function get() {
199
+ if (this.isNumeral()) {
200
+ var numeral = numberToNumeral(this._note);
201
+
202
+ if (this.isMinor()) {
203
+ return numeral.toLowerCase();
110
204
  }
111
205
 
112
- return new Note(newNote);
206
+ return numeral;
113
207
  }
114
208
 
115
- var charCode;
116
- charCode = keyToCharCode(this.note);
117
- charCode += delta;
118
- charCode = clamp(charCode, A, G);
119
- return new Note(String.fromCharCode(charCode));
209
+ return this._note;
120
210
  }
121
211
  }, {
122
212
  key: "toString",
123
213
  value: function toString() {
124
214
  return "".concat(this.note);
125
215
  }
216
+ }], [{
217
+ key: "parse",
218
+ value: function parse(note) {
219
+ if (/^[A-Ga-g]$/.test(note)) {
220
+ return new Note({
221
+ note: note.toUpperCase(),
222
+ type: _constants.SYMBOL
223
+ });
224
+ }
225
+
226
+ if (/^[1-7]$/.test(note)) {
227
+ return new Note({
228
+ note: parseInt(note, 10),
229
+ type: _constants.NUMERIC
230
+ });
231
+ }
232
+
233
+ var romanNumeralValue = numeralToNumber(note);
234
+
235
+ if (romanNumeralValue) {
236
+ return new Note({
237
+ note: romanNumeralValue,
238
+ type: _constants.NUMERAL,
239
+ minor: note.toLowerCase() === note
240
+ });
241
+ }
242
+
243
+ throw new Error("Invalid note ".concat(note));
244
+ }
126
245
  }]);
127
246
 
128
247
  return Note;
129
248
  }();
130
249
 
250
+ function _set2(attributes) {
251
+ return new this.constructor(_objectSpread({
252
+ note: this._note,
253
+ type: this.type,
254
+ minor: this.minor
255
+ }, attributes));
256
+ }
257
+
131
258
  var _default = Note;
132
259
  exports["default"] = _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "chordsheetjs",
3
3
  "author": "Martijn Versluis",
4
- "version": "5.2.0",
4
+ "version": "5.3.0",
5
5
  "description": "A JavaScript library for parsing and formatting chord sheets",
6
6
  "main": "lib/index.js",
7
7
  "repository": {