chordsheetjs 6.1.0 → 6.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.
Files changed (42) hide show
  1. package/README.md +481 -572
  2. package/lib/bundle.js +15393 -0
  3. package/lib/index.js +6290 -216
  4. package/lib/index.js.map +1 -0
  5. package/lib/main.d.ts +1095 -0
  6. package/lib/main.d.ts.map +1 -0
  7. package/package.json +43 -21
  8. package/.husky/pre-commit +0 -5
  9. package/lib/chord.js +0 -496
  10. package/lib/chord_sheet/chord_lyrics_pair.js +0 -80
  11. package/lib/chord_sheet/chord_pro/composite.js +0 -54
  12. package/lib/chord_sheet/chord_pro/evaluation_error.js +0 -58
  13. package/lib/chord_sheet/chord_pro/literal.js +0 -42
  14. package/lib/chord_sheet/chord_pro/ternary.js +0 -126
  15. package/lib/chord_sheet/comment.js +0 -55
  16. package/lib/chord_sheet/line.js +0 -207
  17. package/lib/chord_sheet/metadata.js +0 -216
  18. package/lib/chord_sheet/paragraph.js +0 -88
  19. package/lib/chord_sheet/song.js +0 -531
  20. package/lib/chord_sheet/tag.js +0 -359
  21. package/lib/chord_sheet_serializer.js +0 -278
  22. package/lib/constants.js +0 -54
  23. package/lib/formatter/chord_pro_formatter.js +0 -184
  24. package/lib/formatter/html_div_formatter.js +0 -130
  25. package/lib/formatter/html_formatter.js +0 -44
  26. package/lib/formatter/html_table_formatter.js +0 -154
  27. package/lib/formatter/templates/html_div_formatter.js +0 -544
  28. package/lib/formatter/templates/html_table_formatter.js +0 -731
  29. package/lib/formatter/text_formatter.js +0 -184
  30. package/lib/helpers.js +0 -56
  31. package/lib/key.js +0 -386
  32. package/lib/normalize_mappings/enharmonic-normalize.js +0 -124
  33. package/lib/normalize_mappings/generate-suffix-normalize-mapping.js +0 -36
  34. package/lib/normalize_mappings/suffix-normalize-mapping.js +0 -914
  35. package/lib/note.js +0 -264
  36. package/lib/parser/chord_pro_parser.js +0 -64
  37. package/lib/parser/chord_pro_peg_parser.js +0 -2069
  38. package/lib/parser/chord_sheet_parser.js +0 -175
  39. package/lib/parser/parser_warning.js +0 -62
  40. package/lib/parser/ultimate_guitar_parser.js +0 -154
  41. package/lib/template_helpers.js +0 -98
  42. package/lib/utilities.js +0 -110
package/lib/note.js DELETED
@@ -1,264 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _constants = require("./constants");
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
-
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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
-
28
- var A = 'A'.charCodeAt(0);
29
- var G = 'G'.charCodeAt(0);
30
- var TRANSPOSE_DISTANCE_MAJOR = [null, 0, 2, 4, 5, 7, 9, 11];
31
- var TRANSPOSE_DISTANCE_MINOR = [null, 0, 2, 3, 5, 7, 8, 11];
32
-
33
- function keyToCharCode(key) {
34
- return key.toUpperCase().charCodeAt(0);
35
- }
36
-
37
- function clamp(note, min, max) {
38
- var newNote = note;
39
-
40
- if (newNote < min) {
41
- newNote += 7;
42
- } else if (newNote > max) {
43
- newNote -= 7;
44
- }
45
-
46
- return newNote;
47
- }
48
-
49
- function numeralToNumber(numeral) {
50
- for (var i = 0, count = _constants.ROMAN_NUMERALS.length; i < count; i += 1) {
51
- var romanNumeral = _constants.ROMAN_NUMERALS[i];
52
-
53
- if (romanNumeral === numeral || romanNumeral.toLowerCase() === numeral) {
54
- return i + 1;
55
- }
56
- }
57
-
58
- return null;
59
- }
60
-
61
- function numberToNumeral(number) {
62
- return _constants.ROMAN_NUMERALS[number - 1];
63
- }
64
-
65
- var _set = /*#__PURE__*/new WeakSet();
66
-
67
- var Note = /*#__PURE__*/function () {
68
- function Note(_ref) {
69
- var note = _ref.note,
70
- type = _ref.type,
71
- _ref$minor = _ref.minor,
72
- minor = _ref$minor === void 0 ? false : _ref$minor;
73
-
74
- _classCallCheck(this, Note);
75
-
76
- _classPrivateMethodInitSpec(this, _set);
77
-
78
- this._note = note;
79
- this.type = type;
80
- this.minor = minor;
81
- }
82
-
83
- _createClass(Note, [{
84
- key: "toNumeral",
85
- value: function toNumeral() {
86
- if (this.isNumeral()) {
87
- return this.clone();
88
- }
89
-
90
- if (this.isNumeric()) {
91
- return _classPrivateMethodGet(this, _set, _set2).call(this, {
92
- type: _constants.NUMERAL
93
- });
94
- }
95
-
96
- throw new Error("Converting a ".concat(this.type, " note to numeral is not supported"));
97
- }
98
- }, {
99
- key: "toNumeric",
100
- value: function toNumeric() {
101
- if (this.isNumeric()) {
102
- return this.clone();
103
- }
104
-
105
- if (this.isNumeral()) {
106
- return _classPrivateMethodGet(this, _set, _set2).call(this, {
107
- type: _constants.NUMERIC
108
- });
109
- }
110
-
111
- throw new Error("Converting a ".concat(this.type, " note to numeric is not supported"));
112
- }
113
- }, {
114
- key: "isMinor",
115
- value: function isMinor() {
116
- return this.minor;
117
- }
118
- }, {
119
- key: "equals",
120
- value: function equals(otherNote) {
121
- return this._note === otherNote._note && this.type === otherNote.type && this.minor === otherNote.minor;
122
- }
123
- }, {
124
- key: "clone",
125
- value: function clone() {
126
- return _classPrivateMethodGet(this, _set, _set2).call(this, {});
127
- }
128
- }, {
129
- key: "up",
130
- value: function up() {
131
- return this.change(1);
132
- }
133
- }, {
134
- key: "down",
135
- value: function down() {
136
- return this.change(-1);
137
- }
138
- }, {
139
- key: "isOneOf",
140
- value: function isOneOf() {
141
- for (var _len = arguments.length, options = new Array(_len), _key = 0; _key < _len; _key++) {
142
- options[_key] = arguments[_key];
143
- }
144
-
145
- return options.includes(this._note);
146
- }
147
- }, {
148
- key: "isNumeric",
149
- value: function isNumeric() {
150
- return this.is(_constants.NUMERIC);
151
- }
152
- }, {
153
- key: "isChordSymbol",
154
- value: function isChordSymbol() {
155
- return this.is(_constants.SYMBOL);
156
- }
157
- }, {
158
- key: "isNumeral",
159
- value: function isNumeral() {
160
- return this.is(_constants.NUMERAL);
161
- }
162
- }, {
163
- key: "is",
164
- value: function is(noteType) {
165
- return this.type === noteType;
166
- }
167
- }, {
168
- key: "getTransposeDistance",
169
- value: function getTransposeDistance(minorKey) {
170
- if (minorKey) {
171
- return TRANSPOSE_DISTANCE_MINOR[this._note];
172
- }
173
-
174
- return TRANSPOSE_DISTANCE_MAJOR[this._note];
175
- }
176
- }, {
177
- key: "change",
178
- value: function change(delta) {
179
- if (this.isChordSymbol()) {
180
- var charCode;
181
- charCode = keyToCharCode(this._note);
182
- charCode += delta;
183
- charCode = clamp(charCode, A, G);
184
- return _classPrivateMethodGet(this, _set, _set2).call(this, {
185
- note: String.fromCharCode(charCode)
186
- });
187
- }
188
-
189
- var newNote = clamp(this._note + delta, 1, 7);
190
-
191
- if (newNote < 1) {
192
- newNote += 7;
193
- } else if (newNote > 7) {
194
- newNote -= 7;
195
- }
196
-
197
- return _classPrivateMethodGet(this, _set, _set2).call(this, {
198
- note: newNote
199
- });
200
- }
201
- }, {
202
- key: "note",
203
- get: function get() {
204
- if (this.isNumeral()) {
205
- var numeral = numberToNumeral(this._note);
206
-
207
- if (this.isMinor()) {
208
- return numeral.toLowerCase();
209
- }
210
-
211
- return numeral;
212
- }
213
-
214
- return this._note;
215
- }
216
- }, {
217
- key: "toString",
218
- value: function toString() {
219
- return "".concat(this.note);
220
- }
221
- }], [{
222
- key: "parse",
223
- value: function parse(note) {
224
- if (/^[A-Ga-g]$/.test(note)) {
225
- return new Note({
226
- note: note.toUpperCase(),
227
- type: _constants.SYMBOL
228
- });
229
- }
230
-
231
- if (/^[1-7]$/.test(note)) {
232
- return new Note({
233
- note: parseInt(note, 10),
234
- type: _constants.NUMERIC
235
- });
236
- }
237
-
238
- var romanNumeralValue = numeralToNumber(note);
239
-
240
- if (romanNumeralValue) {
241
- return new Note({
242
- note: romanNumeralValue,
243
- type: _constants.NUMERAL,
244
- minor: note.toLowerCase() === note
245
- });
246
- }
247
-
248
- throw new Error("Invalid note ".concat(note));
249
- }
250
- }]);
251
-
252
- return Note;
253
- }();
254
-
255
- function _set2(attributes) {
256
- return new this.constructor(_objectSpread({
257
- note: this._note,
258
- type: this.type,
259
- minor: this.minor
260
- }, attributes));
261
- }
262
-
263
- var _default = Note;
264
- exports["default"] = _default;
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _chord_pro_peg_parser = _interopRequireDefault(require("./chord_pro_peg_parser"));
9
-
10
- var _chord_sheet_serializer = _interopRequireDefault(require("../chord_sheet_serializer"));
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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
19
-
20
- /**
21
- * Parses a ChordPro chord sheet
22
- */
23
- var ChordProParser = /*#__PURE__*/function () {
24
- function ChordProParser() {
25
- _classCallCheck(this, ChordProParser);
26
- }
27
-
28
- _createClass(ChordProParser, [{
29
- key: "parse",
30
- value:
31
- /**
32
- * Parses a ChordPro chord sheet into a song
33
- * @param {string} chordProChordSheet the ChordPro chord sheet
34
- * @returns {Song} The parsed song
35
- */
36
- function parse(chordProChordSheet) {
37
- /**
38
- * All warnings raised during parsing the ChordPro chord sheet
39
- * @member
40
- * @type {Array<ParserWarning>}
41
- */
42
- var ast = _chord_pro_peg_parser["default"].parse(chordProChordSheet);
43
-
44
- this.song = new _chord_sheet_serializer["default"]().deserialize(ast);
45
- return this.song;
46
- }
47
- /**
48
- * All warnings raised during parsing the ChordPro chord sheet
49
- * @member
50
- * @type {ParserWarning[]}
51
- */
52
-
53
- }, {
54
- key: "warnings",
55
- get: function get() {
56
- return this.song.warnings;
57
- }
58
- }]);
59
-
60
- return ChordProParser;
61
- }();
62
-
63
- var _default = ChordProParser;
64
- exports["default"] = _default;