chordsheetjs 4.8.1 → 5.1.2

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.
@@ -1,222 +0,0 @@
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
- }
@@ -1,139 +0,0 @@
1
- "use strict";
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); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _chord_helpers = require("./chord_helpers");
11
-
12
- var _chord = _interopRequireDefault(require("./chord"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
-
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); } }
19
-
20
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
21
-
22
- 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); }
23
-
24
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
-
26
- 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); }; }
27
-
28
- 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); }
29
-
30
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
-
32
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
33
-
34
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
35
-
36
- /**
37
- * Represents a chord symbol, such as Esus4
38
- */
39
- var ChordSymbol = /*#__PURE__*/function (_Chord) {
40
- _inherits(ChordSymbol, _Chord);
41
-
42
- var _super = _createSuper(ChordSymbol);
43
-
44
- function ChordSymbol() {
45
- _classCallCheck(this, ChordSymbol);
46
-
47
- return _super.apply(this, arguments);
48
- }
49
-
50
- _createClass(ChordSymbol, [{
51
- key: "normalize",
52
- value:
53
- /**
54
- * Normalizes the chord:
55
- * - Fb becomes E
56
- * - Cb becomes B
57
- * - B# becomes C
58
- * - E# becomes F
59
- * If the chord is already normalized, this will return a copy.
60
- * @returns {ChordSymbol} the normalized chord
61
- */
62
- function normalize() {
63
- return (0, _chord_helpers.processChord)(this, _chord_helpers.normalize);
64
- }
65
- /**
66
- * Switches between '#' and 'b' as modifiers. If
67
- * @returns {ChordSymbol} the changed chord
68
- */
69
-
70
- }, {
71
- key: "switchModifier",
72
- value: function switchModifier() {
73
- return (0, _chord_helpers.processChord)(this, _chord_helpers.switchModifier);
74
- }
75
- /**
76
- * Switches to the specified modifier
77
- * @param newModifier the modifier to use: `'#'` or `'b'`
78
- * @returns {ChordSymbol} the changed chord
79
- */
80
-
81
- }, {
82
- key: "useModifier",
83
- value: function useModifier(newModifier) {
84
- return (0, _chord_helpers.processChord)(this, _chord_helpers.useModifier, newModifier);
85
- }
86
- /**
87
- * Transposes the chord up by 1 semitone. Eg. A becomes A#, Eb becomes E
88
- * @returns {ChordSymbol} the transposed chord
89
- */
90
-
91
- }, {
92
- key: "transposeUp",
93
- value: function transposeUp() {
94
- return (0, _chord_helpers.processChord)(this, _chord_helpers.transposeUp);
95
- }
96
- /**
97
- * Transposes the chord down by 1 semitone. Eg. A# becomes A, E becomes Eb
98
- * @returns {ChordSymbol} the transposed chord
99
- */
100
-
101
- }, {
102
- key: "transposeDown",
103
- value: function transposeDown() {
104
- return (0, _chord_helpers.processChord)(this, _chord_helpers.transposeDown);
105
- }
106
- /**
107
- * Transposes the chord by the specified number of semitones
108
- * @param delta de number of semitones
109
- * @returns {ChordSymbol} the transposed chord
110
- */
111
-
112
- }, {
113
- key: "transpose",
114
- value: function transpose(delta) {
115
- return (0, _chord_helpers.processChord)(this, _chord_helpers.transpose, delta);
116
- }
117
- /**
118
- * Convert the chord to a string, eg. `'Esus4/G#'`
119
- * @returns {string|*}
120
- */
121
-
122
- }, {
123
- key: "toString",
124
- value: function toString() {
125
- var chordString = this.base + (this.modifier || '') + (this.suffix || '');
126
-
127
- if (this.bassBase) {
128
- return "".concat(chordString, "/").concat(this.bassBase).concat(this.bassModifier || '');
129
- }
130
-
131
- return chordString;
132
- }
133
- }]);
134
-
135
- return ChordSymbol;
136
- }(_chord["default"]);
137
-
138
- var _default = ChordSymbol;
139
- exports["default"] = _default;
@@ -1,138 +0,0 @@
1
- "use strict";
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); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _chord = _interopRequireDefault(require("./chord"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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
- 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); }
21
-
22
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
-
24
- 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); }; }
25
-
26
- 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); }
27
-
28
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
29
-
30
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
31
-
32
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
-
34
- /**
35
- * Represents a numeric chord, such as b3sus4
36
- */
37
- var NumericChord = /*#__PURE__*/function (_Chord) {
38
- _inherits(NumericChord, _Chord);
39
-
40
- var _super = _createSuper(NumericChord);
41
-
42
- function NumericChord(_ref) {
43
- var base = _ref.base,
44
- modifier = _ref.modifier,
45
- suffix = _ref.suffix,
46
- bassBase = _ref.bassBase,
47
- bassModifier = _ref.bassModifier;
48
-
49
- _classCallCheck(this, NumericChord);
50
-
51
- return _super.call(this, {
52
- base: parseInt(base, 10),
53
- modifier: modifier,
54
- suffix: suffix,
55
- bassBase: parseInt(bassBase, 10),
56
- bassModifier: bassModifier
57
- });
58
- }
59
-
60
- _createClass(NumericChord, [{
61
- key: "toString",
62
- value: function toString() {
63
- var chordString = (this.modifier || '') + this.base + (this.suffix || '');
64
-
65
- if (this.bassBase) {
66
- return "".concat(chordString, "/").concat(this.bassModifier || '').concat(this.bassBase);
67
- }
68
-
69
- return chordString;
70
- }
71
- /**
72
- * Normalizes the chord - this is a noop for numeric chords.
73
- * @returns {NumericChord} a copy of the chord object
74
- */
75
-
76
- }, {
77
- key: "normalize",
78
- value: function normalize() {
79
- return this.clone();
80
- }
81
- /**
82
- * Switches between '#' and 'b' as modifiers - this is a noop for numeric chords.
83
- * @returns {NumericChord} a copy of the chord object
84
- */
85
-
86
- }, {
87
- key: "switchModifier",
88
- value: function switchModifier() {
89
- return this.clone();
90
- }
91
- /**
92
- * Switches to the specified modifier - this is a noop for numeric chords.
93
- * @returns {NumericChord} a copy of the chord object
94
- */
95
-
96
- }, {
97
- key: "useModifier",
98
- value: function useModifier() {
99
- return this.clone();
100
- }
101
- /**
102
- * Transposes the chord up by 1 semitone - this is a noop for numeric chords.
103
- * @returns {NumericChord} a copy of the chord object
104
- */
105
-
106
- }, {
107
- key: "transposeUp",
108
- value: function transposeUp() {
109
- return this.clone();
110
- }
111
- /**
112
- * Transposes the chord down by 1 semitone - this is a noop for numeric chords.
113
- * @returns {NumericChord} a copy of the chord object
114
- */
115
-
116
- }, {
117
- key: "transposeDown",
118
- value: function transposeDown() {
119
- return this.clone();
120
- }
121
- /**
122
- * Transposes the chord by the specified number of semitones - this is a noop for numeric chords.
123
- * @param delta de number of semitones
124
- * @returns {NumericChord} a copy of the chord object
125
- */
126
-
127
- }, {
128
- key: "transpose",
129
- value: function transpose() {
130
- return this.clone();
131
- }
132
- }]);
133
-
134
- return NumericChord;
135
- }(_chord["default"]);
136
-
137
- var _default = NumericChord;
138
- exports["default"] = _default;
@@ -1,74 +0,0 @@
1
- "use strict";
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); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _chord_symbol = _interopRequireDefault(require("./chord_symbol"));
11
-
12
- var _numeric_chord = _interopRequireDefault(require("./numeric_chord"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
-
18
- 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."); }
19
-
20
- 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); }
21
-
22
- 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; }
23
-
24
- 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; }
25
-
26
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
-
28
- 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); }
29
-
30
- 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); }
31
-
32
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
-
34
- var chordRegex = /*#__PURE__*/_wrapRegExp(/^([A-G])(#|b)?((?:(?![\t-\r \/\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])[\s\S])*)(\/([A-G])(#|b)?)?$/i, {
35
- base: 1,
36
- modifier: 2,
37
- suffix: 3,
38
- bassBase: 5,
39
- bassModifier: 6
40
- });
41
-
42
- var numericChordRegex = /*#__PURE__*/_wrapRegExp(/^(#|b)?([1-7])((?:(?![\t-\r \/\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF])[\s\S])*)(\/(#|b)?([0-7]))?$/, {
43
- modifier: 1,
44
- base: 2,
45
- suffix: 3,
46
- bassModifier: 5,
47
- bassBase: 6
48
- });
49
-
50
- var classMapping = [[numericChordRegex, _numeric_chord["default"]], [chordRegex, _chord_symbol["default"]]];
51
- /**
52
- * Tries to parse a chord string into a chord
53
- * @param chordString the chord string, eg Esus4/G# or 1sus4/#3
54
- * @returns {null|ChordSymbol|NumericChord}
55
- */
56
-
57
- function parseChord(chordString) {
58
- for (var i = 0, count = classMapping.length; i < count; i += 1) {
59
- var _classMapping$i = _slicedToArray(classMapping[i], 2),
60
- regex = _classMapping$i[0],
61
- Klass = _classMapping$i[1];
62
-
63
- var match = chordString.match(regex);
64
-
65
- if (match) {
66
- return new Klass(match.groups);
67
- }
68
- }
69
-
70
- return null;
71
- }
72
-
73
- var _default = parseChord;
74
- exports["default"] = _default;
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _parse_chord = _interopRequireDefault(require("./parse_chord"));
9
-
10
- var _chord_symbol = _interopRequireDefault(require("./chord_symbol"));
11
-
12
- var _chord_helpers = require("./chord_helpers");
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- var TRANSPOSE_DISTANCE = [null, 0, 2, 4, 5, 7, 9, 11];
17
- var MAJOR_SCALE = [null, 'M', 'm', 'm', 'M', 'M', 'm', 'dim'];
18
- var MODIFIER_TRANSPOSITION = {
19
- '#': 1,
20
- b: -1
21
- };
22
-
23
- function transposeDistance(chordNumber, modifier) {
24
- return TRANSPOSE_DISTANCE[chordNumber] + (MODIFIER_TRANSPOSITION[modifier] || 0);
25
- }
26
-
27
- function normalizeSuffix(suffix) {
28
- if (suffix === 'M') {
29
- return '';
30
- }
31
-
32
- return suffix;
33
- }
34
-
35
- function chordSuffix(_ref) {
36
- var base = _ref.base,
37
- suffix = _ref.suffix;
38
-
39
- if ((0, _chord_helpers.isEmptyString)(suffix)) {
40
- var defaultSuffix = MAJOR_SCALE[base];
41
- return normalizeSuffix(defaultSuffix);
42
- }
43
-
44
- return normalizeSuffix(suffix);
45
- }
46
-
47
- function chordModifier(keyChord, numericChord) {
48
- if (keyChord.modifier === 'b' || numericChord.modifier === 'b') {
49
- return 'b';
50
- }
51
-
52
- return '#';
53
- }
54
- /**
55
- * Converts a numeric chord into a chord symbol, using the provided key
56
- * @param {NumericChord} numericChord
57
- * @param {string} key the to use, sp anything between Ab and G#
58
- * @returns {ChordSymbol} the resulting chord symbol
59
- */
60
-
61
-
62
- function toChordSymbol(numericChord, key) {
63
- var _bassChord, _bassChord2;
64
-
65
- var keyChord = (0, _parse_chord["default"])(key);
66
-
67
- if (keyChord.suffix === 'm') {
68
- keyChord = keyChord.transpose(3).set({
69
- suffix: null
70
- });
71
- }
72
-
73
- var modifier = chordModifier(keyChord, numericChord);
74
- var baseTransposeDistance = transposeDistance(numericChord.base, numericChord.modifier);
75
- var baseChord = keyChord.transpose(baseTransposeDistance).useModifier(modifier);
76
- var bassChord = null;
77
-
78
- if (numericChord.bassBase) {
79
- bassChord = keyChord.transpose(transposeDistance(numericChord.bassBase, numericChord.bassModifier));
80
- }
81
-
82
- var suffix = chordSuffix(numericChord);
83
- return new _chord_symbol["default"]({
84
- base: baseChord.base,
85
- modifier: baseChord.modifier,
86
- suffix: suffix,
87
- bassBase: (_bassChord = bassChord) === null || _bassChord === void 0 ? void 0 : _bassChord.base,
88
- bassModifier: (_bassChord2 = bassChord) === null || _bassChord2 === void 0 ? void 0 : _bassChord2.modifier
89
- });
90
- }
91
-
92
- var _default = toChordSymbol;
93
- exports["default"] = _default;