chordsheetjs 5.1.2 → 6.0.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.
Files changed (34) hide show
  1. package/d7b54993c4ea66c07a35bd36690482ab620f836e.patch +105 -0
  2. package/lib/chord.js +155 -43
  3. package/lib/chord_sheet/chord_lyrics_pair.js +1 -1
  4. package/lib/chord_sheet/chord_pro/composite.js +1 -1
  5. package/lib/chord_sheet/chord_pro/evaluation_error.js +7 -3
  6. package/lib/chord_sheet/chord_pro/literal.js +1 -1
  7. package/lib/chord_sheet/chord_pro/ternary.js +1 -1
  8. package/lib/chord_sheet/comment.js +1 -1
  9. package/lib/chord_sheet/line.js +1 -1
  10. package/lib/chord_sheet/metadata.js +1 -1
  11. package/lib/chord_sheet/paragraph.js +1 -1
  12. package/lib/chord_sheet/song.js +2 -2
  13. package/lib/chord_sheet/tag.js +1 -1
  14. package/lib/chord_sheet_serializer.js +1 -1
  15. package/lib/constants.js +6 -2
  16. package/lib/formatter/chord_pro_formatter.js +1 -1
  17. package/lib/formatter/html_div_formatter.js +4 -4
  18. package/lib/formatter/html_formatter.js +1 -1
  19. package/lib/formatter/html_table_formatter.js +4 -4
  20. package/lib/formatter/text_formatter.js +4 -2
  21. package/lib/index.js +1 -1
  22. package/lib/key.js +101 -26
  23. package/lib/normalize_mappings/enharmonic-normalize.js +124 -0
  24. package/lib/normalize_mappings/generate-suffix-normalize-mapping.js +36 -0
  25. package/lib/normalize_mappings/suffix-normalize-mapping.js +914 -0
  26. package/lib/note.js +161 -29
  27. package/lib/parser/chord_pro_parser.js +1 -1
  28. package/lib/parser/chord_pro_peg_parser.js +22 -13
  29. package/lib/parser/chord_sheet_parser.js +1 -1
  30. package/lib/parser/parser_warning.js +1 -1
  31. package/lib/parser/ultimate_guitar_parser.js +3 -3
  32. package/lib/{handlebars_helpers.js → template_helpers.js} +16 -1
  33. package/lib/utilities.js +2 -16
  34. package/package.json +11 -8
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- 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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -9,7 +9,7 @@ exports["default"] = void 0;
9
9
 
10
10
  var _handlebars = _interopRequireDefault(require("handlebars"));
11
11
 
12
- require("../handlebars_helpers");
12
+ require("../template_helpers");
13
13
 
14
14
  var _html_formatter = _interopRequireDefault(require("./html_formatter"));
15
15
 
@@ -23,9 +23,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
23
23
 
24
24
  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); } }
25
25
 
26
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
26
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
27
 
28
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
28
+ 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); }
29
29
 
30
30
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
31
31
 
@@ -9,7 +9,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
9
9
 
10
10
  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); } }
11
11
 
12
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
13
 
14
14
  /**
15
15
  * Acts as a base class for HTML formatters, taking care of whitelisting prototype property access.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- 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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -10,7 +10,7 @@ exports.scopedCss = scopedCss;
10
10
 
11
11
  var _handlebars = _interopRequireDefault(require("handlebars"));
12
12
 
13
- require("../handlebars_helpers");
13
+ require("../template_helpers");
14
14
 
15
15
  var _html_formatter = _interopRequireDefault(require("./html_formatter"));
16
16
 
@@ -24,9 +24,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
24
24
 
25
25
  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); } }
26
26
 
27
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
27
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
28
28
 
29
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
+ 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); }
30
30
 
31
31
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
32
32
 
@@ -11,6 +11,8 @@ var _tag = _interopRequireDefault(require("../chord_sheet/tag"));
11
11
 
12
12
  var _helpers = require("../helpers");
13
13
 
14
+ var _template_helpers = require("../template_helpers");
15
+
14
16
  var _utilities = require("../utilities");
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -19,7 +21,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
19
21
 
20
22
  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); } }
21
23
 
22
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
24
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
25
 
24
26
  /**
25
27
  * Formats a song into a plain text chord sheet
@@ -141,7 +143,7 @@ var TextFormatter = /*#__PURE__*/function () {
141
143
  }, {
142
144
  key: "formatLineBottom",
143
145
  value: function formatLineBottom(line, metadata) {
144
- if ((0, _utilities.hasTextContents)(line)) {
146
+ if ((0, _template_helpers.hasTextContents)(line)) {
145
147
  return this.formatLineWithFormatter(line, this.formatItemBottom, metadata);
146
148
  }
147
149
 
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- 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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
package/lib/key.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
 
3
- 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); }
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
@@ -11,19 +11,21 @@ var _note = _interopRequireDefault(require("./note"));
11
11
 
12
12
  var _constants = require("./constants");
13
13
 
14
+ var _enharmonicNormalize = _interopRequireDefault(require("./normalize_mappings/enharmonic-normalize"));
15
+
14
16
  var _MODIFIER_TRANSPOSITI;
15
17
 
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
19
 
18
- 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; }
20
+ 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; }
19
21
 
20
- 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; }
22
+ 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; }
21
23
 
22
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
25
 
24
26
  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); } }
25
27
 
26
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
28
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
29
 
28
30
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
29
31
 
@@ -31,9 +33,9 @@ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollect
31
33
 
32
34
  function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
33
35
 
34
- function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (_typeof(args[args.length - 1]) !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
36
+ 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); }
35
37
 
36
- 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 } }); if (superClass) _setPrototypeOf(subClass, superClass); }
38
+ 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); }
37
39
 
38
40
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
41
 
@@ -43,17 +45,24 @@ var FLAT = 'b';
43
45
  var SHARP = '#';
44
46
  var MODIFIER_TRANSPOSITION = (_MODIFIER_TRANSPOSITI = {}, _defineProperty(_MODIFIER_TRANSPOSITI, SHARP, 1), _defineProperty(_MODIFIER_TRANSPOSITI, FLAT, -1), _MODIFIER_TRANSPOSITI);
45
47
 
46
- var symbolKeyRegex = /*#__PURE__*/_wrapRegExp(/^([A-G])(#|b)?$/i, {
48
+ var symbolKeyRegex = /*#__PURE__*/_wrapRegExp(/^([A-G])(#|b)?(m)?$/i, {
47
49
  note: 1,
48
- modifier: 2
50
+ modifier: 2,
51
+ minor: 3
52
+ });
53
+
54
+ var numericKeyRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?([1-7])(m)?$/, {
55
+ modifier: 1,
56
+ note: 2,
57
+ minor: 3
49
58
  });
50
59
 
51
- var numericKeyRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?([1-7])$/, {
60
+ var numeralKeyRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?(I{1,3}|IV|VI{0,2}|i{1,3}|iv|vi{0,2})$/, {
52
61
  modifier: 1,
53
62
  note: 2
54
63
  });
55
64
 
56
- var regexes = [symbolKeyRegex, numericKeyRegex];
65
+ var regexes = [symbolKeyRegex, numericKeyRegex, numeralKeyRegex];
57
66
 
58
67
  var _set = /*#__PURE__*/new WeakSet();
59
68
 
@@ -61,14 +70,17 @@ var Key = /*#__PURE__*/function () {
61
70
  function Key(_ref) {
62
71
  var note = _ref.note,
63
72
  _ref$modifier = _ref.modifier,
64
- modifier = _ref$modifier === void 0 ? null : _ref$modifier;
73
+ modifier = _ref$modifier === void 0 ? null : _ref$modifier,
74
+ _ref$minor = _ref.minor,
75
+ minor = _ref$minor === void 0 ? false : _ref$minor;
65
76
 
66
77
  _classCallCheck(this, Key);
67
78
 
68
79
  _classPrivateMethodInitSpec(this, _set);
69
80
 
70
- this.note = note instanceof _note["default"] ? note : new _note["default"](note);
81
+ this.note = note instanceof _note["default"] ? note : _note["default"].parse(note);
71
82
  this.modifier = modifier || null;
83
+ this.minor = !!minor || false;
72
84
  }
73
85
 
74
86
  _createClass(Key, [{
@@ -85,6 +97,11 @@ var Key = /*#__PURE__*/function () {
85
97
 
86
98
  return delta;
87
99
  }
100
+ }, {
101
+ key: "isMinor",
102
+ value: function isMinor() {
103
+ return this.note.isMinor();
104
+ }
88
105
  }, {
89
106
  key: "clone",
90
107
  value: function clone() {
@@ -97,7 +114,7 @@ var Key = /*#__PURE__*/function () {
97
114
  return this.clone();
98
115
  }
99
116
 
100
- var transposeDistance = this.note.getTransposeDistance() + (MODIFIER_TRANSPOSITION[this.modifier] || 0);
117
+ var transposeDistance = this.note.getTransposeDistance(key.minor) + (MODIFIER_TRANSPOSITION[this.modifier] || 0);
101
118
  return key.transpose(transposeDistance).normalize().useModifier(key.modifier);
102
119
  }
103
120
  }, {
@@ -120,6 +137,18 @@ var Key = /*#__PURE__*/function () {
120
137
  value: function isChordSymbol() {
121
138
  return this.is(_constants.SYMBOL);
122
139
  }
140
+ }, {
141
+ key: "isNumeral",
142
+ value: function isNumeral() {
143
+ return this.is(_constants.NUMERAL);
144
+ }
145
+ }, {
146
+ key: "equals",
147
+ value: function equals(_ref2) {
148
+ var note = _ref2.note,
149
+ modifier = _ref2.modifier;
150
+ return this.note.equals(note) && this.modifier === modifier;
151
+ }
123
152
  }, {
124
153
  key: "toNumeric",
125
154
  value: function toNumeric(key) {
@@ -127,39 +156,69 @@ var Key = /*#__PURE__*/function () {
127
156
  return this.clone();
128
157
  }
129
158
 
159
+ if (this.isNumeral()) {
160
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
161
+ note: this.note.toNumeric()
162
+ });
163
+ }
164
+
130
165
  var numericKey = new Key({
131
166
  note: 1
132
167
  });
133
168
  var symbolKey = key.clone();
134
- var reference = this.clone().normalize().useModifier(key.modifier);
169
+ var reference = this.clone().normalize().useModifier(key.modifier).normalizeEnharmonics(key);
135
170
 
136
171
  while (!symbolKey.equals(reference)) {
137
172
  numericKey = numericKey.transposeUp().useModifier(key.modifier);
138
- symbolKey = symbolKey.transposeUp().normalize().useModifier(key.modifier);
173
+ symbolKey = symbolKey.transposeUp().normalize().useModifier(key.modifier).normalizeEnharmonics(key);
139
174
  }
140
175
 
141
176
  return numericKey;
142
177
  }
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
178
  }, {
151
179
  key: "toNumericString",
152
180
  value: function toNumericString(key) {
153
181
  return this.toNumeric(key).toString();
154
182
  }
183
+ }, {
184
+ key: "toNumeral",
185
+ value: function toNumeral(key) {
186
+ if (this.isNumeral()) {
187
+ return this.clone();
188
+ }
189
+
190
+ if (this.isNumeric()) {
191
+ return _classPrivateMethodGet(this, _set, _set2).call(this, {
192
+ note: this.note.toNumeral()
193
+ });
194
+ }
195
+
196
+ var numeralKey = new Key({
197
+ note: 'I'
198
+ });
199
+ var symbolKey = key.clone();
200
+ var reference = this.clone().normalize().useModifier(key.modifier).normalizeEnharmonics(key);
201
+
202
+ while (!symbolKey.equals(reference)) {
203
+ numeralKey = numeralKey.transposeUp().useModifier(key.modifier);
204
+ symbolKey = symbolKey.transposeUp().normalize().useModifier(key.modifier).normalizeEnharmonics(key);
205
+ }
206
+
207
+ return numeralKey;
208
+ }
209
+ }, {
210
+ key: "toNumeralString",
211
+ value: function toNumeralString(key) {
212
+ return this.toNumeral(key).toString();
213
+ }
155
214
  }, {
156
215
  key: "toString",
157
216
  value: function toString() {
158
- if (this.is(_constants.NUMERIC)) {
159
- return "".concat(this.modifier || '').concat(this.note);
217
+ if (this.isChordSymbol()) {
218
+ return "".concat(this.note).concat(this.modifier || '');
160
219
  }
161
220
 
162
- return "".concat(this.note).concat(this.modifier || '');
221
+ return "".concat(this.modifier || '').concat(this.note);
163
222
  }
164
223
  }, {
165
224
  key: "transpose",
@@ -266,6 +325,21 @@ var Key = /*#__PURE__*/function () {
266
325
  });
267
326
  }
268
327
 
328
+ return this.clone();
329
+ }
330
+ }, {
331
+ key: "normalizeEnharmonics",
332
+ value: function normalizeEnharmonics(key) {
333
+ if (key) {
334
+ var rootKeyString = key.minor ? "".concat(key, "m") : key.toString();
335
+ var enharmonics = _enharmonicNormalize["default"][rootKeyString];
336
+ var thisKeyString = this.toString();
337
+
338
+ if (enharmonics && enharmonics[thisKeyString]) {
339
+ return Key.parse(enharmonics[thisKeyString]);
340
+ }
341
+ }
342
+
269
343
  return this.clone();
270
344
  }
271
345
  }], [{
@@ -303,7 +377,8 @@ var Key = /*#__PURE__*/function () {
303
377
  function _set2(attributes) {
304
378
  return new this.constructor(_objectSpread({
305
379
  note: this.note.clone(),
306
- modifier: this.modifier
380
+ modifier: this.modifier,
381
+ minor: !!this.minor
307
382
  }, attributes));
308
383
  }
309
384
 
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ var _default = {
8
+ 'Ab': {
9
+ 'B': 'Cb'
10
+ },
11
+ 'Cb': {
12
+ 'B': 'Cb',
13
+ 'A#': 'Bb',
14
+ 'E': 'Fb'
15
+ },
16
+ 'C': {
17
+ 'C#': 'Db',
18
+ 'D#': 'Eb',
19
+ 'F#': 'Gb',
20
+ 'G#': 'Ab',
21
+ 'A#': 'Bb'
22
+ },
23
+ 'C#': {
24
+ 'D#': 'Eb',
25
+ 'A#': 'Bb'
26
+ },
27
+ 'Db': {
28
+ 'B': 'Cb'
29
+ },
30
+ 'D': {
31
+ 'D#': 'Eb',
32
+ 'A#': 'Bb'
33
+ },
34
+ 'E': {
35
+ 'Ab': 'G#',
36
+ 'A#': 'Bb',
37
+ 'D#': 'Eb'
38
+ },
39
+ 'F': {
40
+ 'A#': 'Bb',
41
+ 'F#': 'Gb',
42
+ 'C#': 'Db',
43
+ 'D#': 'Eb',
44
+ 'G#': 'Ab'
45
+ },
46
+ 'F#': {
47
+ 'A#': 'Bb',
48
+ 'D#': 'Eb'
49
+ },
50
+ 'Gb': {
51
+ 'A#': 'Bb',
52
+ 'D#': 'Eb',
53
+ 'G#': 'Ab',
54
+ 'B': 'Cb',
55
+ 'E': 'Fb'
56
+ },
57
+ 'G': {
58
+ 'A#': 'Bb',
59
+ 'D#': 'Eb',
60
+ 'G#': 'Ab'
61
+ },
62
+ 'G#': {
63
+ 'A#': 'Bb',
64
+ 'D#': 'Eb'
65
+ },
66
+ 'Am': {
67
+ 'Gb': 'G',
68
+ 'G#': 'Ab',
69
+ 'F#': 'Gb',
70
+ 'C#': 'Db',
71
+ 'D#': 'Eb',
72
+ 'A#': 'Bb'
73
+ },
74
+ 'Bbm': {
75
+ 'Cb': 'B'
76
+ },
77
+ 'Bm': {
78
+ 'A#': 'Bb',
79
+ 'D#': 'Eb'
80
+ },
81
+ 'C#m': {
82
+ 'A#': 'Bb',
83
+ 'D#': 'Eb'
84
+ },
85
+ 'Cm': {
86
+ 'G#': 'Ab',
87
+ 'A#': 'Bb',
88
+ 'D#': 'Eb',
89
+ 'F#': 'Gb',
90
+ 'C#': 'Db'
91
+ },
92
+ 'Dm': {
93
+ 'A#': 'Bb',
94
+ 'D#': 'Eb'
95
+ },
96
+ 'Em': {
97
+ 'A#': 'Bb',
98
+ 'D#': 'Eb'
99
+ },
100
+ 'F#m': {
101
+ 'A#': 'Bb',
102
+ 'D#': 'Eb',
103
+ 'Gb': 'F#',
104
+ 'Ab': 'G#',
105
+ 'Db': 'C#'
106
+ },
107
+ 'Fm': {
108
+ 'G#': 'Ab',
109
+ 'A#': 'Bb',
110
+ 'D#': 'Eb',
111
+ 'F#': 'Gb',
112
+ 'C#': 'Db'
113
+ },
114
+ 'Gm': {
115
+ 'G#': 'Ab',
116
+ 'A#': 'Bb',
117
+ 'D#': 'Eb'
118
+ },
119
+ 'G#m': {
120
+ 'A#': 'Bb',
121
+ 'D#': 'Eb'
122
+ }
123
+ };
124
+ exports["default"] = _default;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ 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; }
4
+
5
+ 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; }
6
+
7
+ 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; }
8
+
9
+ var fs = require('fs');
10
+
11
+ console.warn('\x1b[34m', '👷 Building suffix normalize mapping from suffix-mapping.txt');
12
+ fs.readFile('src/normalize_mappings/suffix-mapping.txt', function (err, data) {
13
+ if (err) throw err;
14
+ var suffixs = [];
15
+ data.toString().split('\n').map(function (line) {
16
+ var items = line.split(',');
17
+ var cleanStringsArray = [];
18
+ items.forEach(function (item) {
19
+ cleanStringsArray.push(item.trim());
20
+ });
21
+ suffixs.push(cleanStringsArray);
22
+ return suffixs;
23
+ });
24
+ var flatObject = {};
25
+ suffixs.forEach(function (line) {
26
+ line.forEach(function (item) {
27
+ flatObject = _objectSpread(_defineProperty({}, item, line[0]), flatObject);
28
+ });
29
+ });
30
+ var suffixMappingJson = JSON.stringify(flatObject, null, 2);
31
+ var suffixMappingJs = "export default ".concat(suffixMappingJson, ";\n");
32
+ fs.writeFile('src/normalize_mappings/suffix-normalize-mapping.js', suffixMappingJs, 'utf-8', function (error) {
33
+ if (error) throw error;
34
+ console.warn('\x1b[32m', '✨ Sucessfully built suffix-normalize-mapping.js');
35
+ });
36
+ });