chordsheetjs 4.10.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -139
- package/d7b54993c4ea66c07a35bd36690482ab620f836e.patch +105 -0
- package/lib/chord.js +341 -35
- package/lib/chord_sheet/chord_lyrics_pair.js +1 -1
- package/lib/chord_sheet/chord_pro/composite.js +1 -1
- package/lib/chord_sheet/chord_pro/evaluation_error.js +7 -3
- package/lib/chord_sheet/chord_pro/literal.js +1 -1
- package/lib/chord_sheet/chord_pro/ternary.js +1 -1
- package/lib/chord_sheet/comment.js +1 -1
- package/lib/chord_sheet/line.js +1 -1
- package/lib/chord_sheet/metadata.js +4 -4
- package/lib/chord_sheet/paragraph.js +1 -1
- package/lib/chord_sheet/song.js +9 -5
- package/lib/chord_sheet/tag.js +10 -3
- package/lib/chord_sheet_serializer.js +1 -1
- package/lib/constants.js +6 -2
- package/lib/formatter/chord_pro_formatter.js +1 -1
- package/lib/formatter/html_div_formatter.js +4 -4
- package/lib/formatter/html_formatter.js +3 -2
- package/lib/formatter/html_table_formatter.js +4 -4
- package/lib/formatter/templates/html_div_formatter.js +31 -32
- package/lib/formatter/templates/html_table_formatter.js +7 -6
- package/lib/formatter/text_formatter.js +25 -17
- package/lib/helpers.js +32 -0
- package/lib/index.js +26 -10
- package/lib/key.js +311 -0
- package/lib/note.js +132 -0
- package/lib/parser/chord_pro_parser.js +1 -1
- package/lib/parser/chord_pro_peg_parser.js +22 -13
- package/lib/parser/chord_sheet_parser.js +1 -1
- package/lib/parser/parser_warning.js +1 -1
- package/lib/parser/ultimate_guitar_parser.js +4 -4
- package/lib/{handlebars_helpers.js → template_helpers.js} +21 -2
- package/lib/utilities.js +22 -23
- package/package.json +6 -5
- package/lib/chord_helpers.js +0 -222
- package/lib/chord_symbol.js +0 -139
- package/lib/numeric_chord.js +0 -138
- package/lib/parse_chord.js +0 -74
- package/lib/to_chord_symbol.js +0 -93
package/lib/parse_chord.js
DELETED
|
@@ -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;
|
package/lib/to_chord_symbol.js
DELETED
|
@@ -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;
|