chordsheetjs 7.1.0 → 7.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 CHANGED
@@ -639,6 +639,9 @@ If not, it returns [INDETERMINATE](#INDETERMINATE)</p>
639
639
  * [.clone()](#Song+clone) ⇒ [<code>Song</code>](#Song)
640
640
  * [.setKey(key)](#Song+setKey) ⇒ [<code>Song</code>](#Song)
641
641
  * [.setCapo(capo)](#Song+setCapo) ⇒ [<code>Song</code>](#Song)
642
+ * [.transpose(delta)](#Song+transpose) ⇒ [<code>Song</code>](#Song)
643
+ * [.transposeUp()](#Song+transposeUp) ⇒ [<code>Song</code>](#Song)
644
+ * [.transposeDown()](#Song+transposeDown) ⇒ [<code>Song</code>](#Song)
642
645
  * [.changeKey(newKey)](#Song+changeKey) ⇒ [<code>Song</code>](#Song)
643
646
  * [.changeMetadata(name, value)](#Song+changeMetadata)
644
647
  * [.mapItems(func)](#Song+mapItems) ⇒ [<code>Song</code>](#Song)
@@ -697,7 +700,7 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
697
700
  ### song.setKey(key) ⇒ [<code>Song</code>](#Song)
698
701
  <p>Returns a copy of the song with the key value set to the specified key. It changes:</p>
699
702
  <ul>
700
- <li>the value for <code>key</code> in the <code>metadata</code> set</li>
703
+ <li>the value for <code>key</code> in the [metadata](metadata) set</li>
701
704
  <li>any existing <code>key</code> directive</li>
702
705
  </ul>
703
706
 
@@ -706,14 +709,14 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
706
709
 
707
710
  | Param | Type | Description |
708
711
  | --- | --- | --- |
709
- | key | <code>number</code> \| <code>null</code> | <p>the key. Passing <code>null</code> will:</p> <ul> <li>remove the current key from <code>metadata</code></li> <li>remove any <code>key</code> directive</li> </ul> |
712
+ | key | <code>number</code> \| <code>null</code> | <p>the key. Passing <code>null</code> will:</p> <ul> <li>remove the current key from [metadata](metadata)</li> <li>remove any <code>key</code> directive</li> </ul> |
710
713
 
711
714
  <a name="Song+setCapo"></a>
712
715
 
713
716
  ### song.setCapo(capo) ⇒ [<code>Song</code>](#Song)
714
717
  <p>Returns a copy of the song with the key value set to the specified capo. It changes:</p>
715
718
  <ul>
716
- <li>the value for <code>capo</code> in the <code>metadata</code> set</li>
719
+ <li>the value for <code>capo</code> in the [metadata](metadata) set</li>
717
720
  <li>any existing <code>capo</code> directive</li>
718
721
  </ul>
719
722
 
@@ -722,14 +725,55 @@ if you want to skip the &quot;header lines&quot;: the lines that only contain me
722
725
 
723
726
  | Param | Type | Description |
724
727
  | --- | --- | --- |
725
- | capo | <code>number</code> \| <code>null</code> | <p>the capo. Passing <code>null</code> will:</p> <ul> <li>remove the current key from <code>metadata</code></li> <li>remove any <code>capo</code> directive</li> </ul> |
728
+ | capo | <code>number</code> \| <code>null</code> | <p>the capo. Passing <code>null</code> will:</p> <ul> <li>remove the current key from [metadata](metadata)</li> <li>remove any <code>capo</code> directive</li> </ul> |
726
729
 
730
+ <a name="Song+transpose"></a>
731
+
732
+ ### song.transpose(delta) ⇒ [<code>Song</code>](#Song)
733
+ <p>Transposes the song by the specified delta. It will:</p>
734
+ <ul>
735
+ <li>transpose all chords, see: [transpose](#Chord+transpose)</li>
736
+ <li>transpose the song key in [metadata](metadata)</li>
737
+ <li>update any existing <code>key</code> directive</li>
738
+ </ul>
739
+
740
+ **Kind**: instance method of [<code>Song</code>](#Song)
741
+ **Returns**: [<code>Song</code>](#Song) - <p>The transposed song</p>
742
+
743
+ | Param | Type | Description |
744
+ | --- | --- | --- |
745
+ | delta | <code>number</code> | <p>The number of semitones (positive or negative) to transpose with</p> |
746
+
747
+ <a name="Song+transposeUp"></a>
748
+
749
+ ### song.transposeUp() ⇒ [<code>Song</code>](#Song)
750
+ <p>Transposes the song up by one semitone. It will:</p>
751
+ <ul>
752
+ <li>transpose all chords, see: [transpose](#Chord+transpose)</li>
753
+ <li>transpose the song key in [metadata](metadata)</li>
754
+ <li>update any existing <code>key</code> directive</li>
755
+ </ul>
756
+
757
+ **Kind**: instance method of [<code>Song</code>](#Song)
758
+ **Returns**: [<code>Song</code>](#Song) - <p>The transposed song</p>
759
+ <a name="Song+transposeDown"></a>
760
+
761
+ ### song.transposeDown() ⇒ [<code>Song</code>](#Song)
762
+ <p>Transposes the song down by one semitone. It will:</p>
763
+ <ul>
764
+ <li>transpose all chords, see: [transpose](#Chord+transpose)</li>
765
+ <li>transpose the song key in [metadata](metadata)</li>
766
+ <li>update any existing <code>key</code> directive</li>
767
+ </ul>
768
+
769
+ **Kind**: instance method of [<code>Song</code>](#Song)
770
+ **Returns**: [<code>Song</code>](#Song) - <p>The transposed song</p>
727
771
  <a name="Song+changeKey"></a>
728
772
 
729
773
  ### song.changeKey(newKey) ⇒ [<code>Song</code>](#Song)
730
774
  <p>Returns a copy of the song with the key set to the specified key. It changes:</p>
731
775
  <ul>
732
- <li>the value for <code>key</code> in the <code>metadata</code> set</li>
776
+ <li>the value for <code>key</code> in the [metadata](metadata) set</li>
733
777
  <li>any existing <code>key</code> directive</li>
734
778
  <li>all chords, those are transposed according to the distance between the current and the new key</li>
735
779
  </ul>
package/lib/bundle.js CHANGED
@@ -3376,11 +3376,15 @@ var $26f57998457eb2d4$export$2e2bcd8739ae039 = $26f57998457eb2d4$var$Chord;
3376
3376
  lyrics: lyrics
3377
3377
  });
3378
3378
  }
3379
- transpose(delta, key) {
3379
+ transpose(delta, key = null) {
3380
3380
  const chordObj = (0, $26f57998457eb2d4$export$2e2bcd8739ae039).parse(this.chords);
3381
- if (chordObj) return this.set({
3382
- chords: chordObj.transpose(delta).normalize(key).toString()
3383
- });
3381
+ if (chordObj) {
3382
+ let transposedChord = chordObj.transpose(delta);
3383
+ if (key) transposedChord = transposedChord.normalize(key);
3384
+ return this.set({
3385
+ chords: transposedChord.toString()
3386
+ });
3387
+ }
3384
3388
  return this.clone();
3385
3389
  }
3386
3390
  }
@@ -4107,21 +4111,21 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4107
4111
  }
4108
4112
  /**
4109
4113
  * Returns a copy of the song with the key value set to the specified key. It changes:
4110
- * - the value for `key` in the `metadata` set
4114
+ * - the value for `key` in the {@link metadata} set
4111
4115
  * - any existing `key` directive
4112
4116
  * @param {number|null} key the key. Passing `null` will:
4113
- * - remove the current key from `metadata`
4117
+ * - remove the current key from {@link metadata}
4114
4118
  * - remove any `key` directive
4115
4119
  * @returns {Song} The changed song
4116
4120
  */ setKey(key) {
4117
- return this.changeMetadata((0, $5e9ede69210ec54a$export$7167c830cefcb6b5), key);
4121
+ return this.changeMetadata((0, $5e9ede69210ec54a$export$7167c830cefcb6b5), key ? key.toString() : key);
4118
4122
  }
4119
4123
  /**
4120
4124
  * Returns a copy of the song with the key value set to the specified capo. It changes:
4121
- * - the value for `capo` in the `metadata` set
4125
+ * - the value for `capo` in the {@link metadata} set
4122
4126
  * - any existing `capo` directive
4123
4127
  * @param {number|null} capo the capo. Passing `null` will:
4124
- * - remove the current key from `metadata`
4128
+ * - remove the current key from {@link metadata}
4125
4129
  * - remove any `capo` directive
4126
4130
  * @returns {Song} The changed song
4127
4131
  */ setCapo(capo) {
@@ -4134,8 +4138,46 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4134
4138
  }), (song)=>song.insertDirective(name, value));
4135
4139
  }
4136
4140
  /**
4141
+ * Transposes the song by the specified delta. It will:
4142
+ * - transpose all chords, see: {@link Chord#transpose}
4143
+ * - transpose the song key in {@link metadata}
4144
+ * - update any existing `key` directive
4145
+ * @param {number} delta The number of semitones (positive or negative) to transpose with
4146
+ * @returns {Song} The transposed song
4147
+ */ transpose(delta) {
4148
+ const wrappedKey = (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039).wrap(this.key);
4149
+ let transposedKey = null;
4150
+ let song = this;
4151
+ if (wrappedKey) {
4152
+ transposedKey = wrappedKey.transpose(delta);
4153
+ song = song.setKey(transposedKey);
4154
+ }
4155
+ return song.mapItems((item)=>{
4156
+ if (item instanceof (0, $d454f4215ba01af2$export$2e2bcd8739ae039)) return item.transpose(delta, transposedKey);
4157
+ return item;
4158
+ });
4159
+ }
4160
+ /**
4161
+ * Transposes the song up by one semitone. It will:
4162
+ * - transpose all chords, see: {@link Chord#transpose}
4163
+ * - transpose the song key in {@link metadata}
4164
+ * - update any existing `key` directive
4165
+ * @returns {Song} The transposed song
4166
+ */ transposeUp() {
4167
+ return this.transpose(1);
4168
+ }
4169
+ /**
4170
+ * Transposes the song down by one semitone. It will:
4171
+ * - transpose all chords, see: {@link Chord#transpose}
4172
+ * - transpose the song key in {@link metadata}
4173
+ * - update any existing `key` directive
4174
+ * @returns {Song} The transposed song
4175
+ */ transposeDown() {
4176
+ return this.transpose(-1);
4177
+ }
4178
+ /**
4137
4179
  * Returns a copy of the song with the key set to the specified key. It changes:
4138
- * - the value for `key` in the `metadata` set
4180
+ * - the value for `key` in the {@link metadata} set
4139
4181
  * - any existing `key` directive
4140
4182
  * - all chords, those are transposed according to the distance between the current and the new key
4141
4183
  * @param {string} newKey The new key.
@@ -4149,7 +4191,7 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4149
4191
  if (item instanceof (0, $d454f4215ba01af2$export$2e2bcd8739ae039)) return item.transpose(transpose, newKey);
4150
4192
  return item;
4151
4193
  });
4152
- updatedSong.metadata.set("key", newKey);
4194
+ this.setKey(newKey);
4153
4195
  return updatedSong;
4154
4196
  }
4155
4197
  getTransposeDistance(newKey) {
package/lib/index.js CHANGED
@@ -3375,11 +3375,15 @@ var $26f57998457eb2d4$export$2e2bcd8739ae039 = $26f57998457eb2d4$var$Chord;
3375
3375
  lyrics: lyrics
3376
3376
  });
3377
3377
  }
3378
- transpose(delta, key) {
3378
+ transpose(delta, key = null) {
3379
3379
  const chordObj = (0, $26f57998457eb2d4$export$2e2bcd8739ae039).parse(this.chords);
3380
- if (chordObj) return this.set({
3381
- chords: chordObj.transpose(delta).normalize(key).toString()
3382
- });
3380
+ if (chordObj) {
3381
+ let transposedChord = chordObj.transpose(delta);
3382
+ if (key) transposedChord = transposedChord.normalize(key);
3383
+ return this.set({
3384
+ chords: transposedChord.toString()
3385
+ });
3386
+ }
3383
3387
  return this.clone();
3384
3388
  }
3385
3389
  }
@@ -4106,21 +4110,21 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4106
4110
  }
4107
4111
  /**
4108
4112
  * Returns a copy of the song with the key value set to the specified key. It changes:
4109
- * - the value for `key` in the `metadata` set
4113
+ * - the value for `key` in the {@link metadata} set
4110
4114
  * - any existing `key` directive
4111
4115
  * @param {number|null} key the key. Passing `null` will:
4112
- * - remove the current key from `metadata`
4116
+ * - remove the current key from {@link metadata}
4113
4117
  * - remove any `key` directive
4114
4118
  * @returns {Song} The changed song
4115
4119
  */ setKey(key) {
4116
- return this.changeMetadata((0, $5e9ede69210ec54a$export$7167c830cefcb6b5), key);
4120
+ return this.changeMetadata((0, $5e9ede69210ec54a$export$7167c830cefcb6b5), key ? key.toString() : key);
4117
4121
  }
4118
4122
  /**
4119
4123
  * Returns a copy of the song with the key value set to the specified capo. It changes:
4120
- * - the value for `capo` in the `metadata` set
4124
+ * - the value for `capo` in the {@link metadata} set
4121
4125
  * - any existing `capo` directive
4122
4126
  * @param {number|null} capo the capo. Passing `null` will:
4123
- * - remove the current key from `metadata`
4127
+ * - remove the current key from {@link metadata}
4124
4128
  * - remove any `capo` directive
4125
4129
  * @returns {Song} The changed song
4126
4130
  */ setCapo(capo) {
@@ -4133,8 +4137,46 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4133
4137
  }), (song)=>song.insertDirective(name, value));
4134
4138
  }
4135
4139
  /**
4140
+ * Transposes the song by the specified delta. It will:
4141
+ * - transpose all chords, see: {@link Chord#transpose}
4142
+ * - transpose the song key in {@link metadata}
4143
+ * - update any existing `key` directive
4144
+ * @param {number} delta The number of semitones (positive or negative) to transpose with
4145
+ * @returns {Song} The transposed song
4146
+ */ transpose(delta) {
4147
+ const wrappedKey = (0, $bff5407e03fdc8ee$export$2e2bcd8739ae039).wrap(this.key);
4148
+ let transposedKey = null;
4149
+ let song = this;
4150
+ if (wrappedKey) {
4151
+ transposedKey = wrappedKey.transpose(delta);
4152
+ song = song.setKey(transposedKey);
4153
+ }
4154
+ return song.mapItems((item)=>{
4155
+ if (item instanceof (0, $d454f4215ba01af2$export$2e2bcd8739ae039)) return item.transpose(delta, transposedKey);
4156
+ return item;
4157
+ });
4158
+ }
4159
+ /**
4160
+ * Transposes the song up by one semitone. It will:
4161
+ * - transpose all chords, see: {@link Chord#transpose}
4162
+ * - transpose the song key in {@link metadata}
4163
+ * - update any existing `key` directive
4164
+ * @returns {Song} The transposed song
4165
+ */ transposeUp() {
4166
+ return this.transpose(1);
4167
+ }
4168
+ /**
4169
+ * Transposes the song down by one semitone. It will:
4170
+ * - transpose all chords, see: {@link Chord#transpose}
4171
+ * - transpose the song key in {@link metadata}
4172
+ * - update any existing `key` directive
4173
+ * @returns {Song} The transposed song
4174
+ */ transposeDown() {
4175
+ return this.transpose(-1);
4176
+ }
4177
+ /**
4136
4178
  * Returns a copy of the song with the key set to the specified key. It changes:
4137
- * - the value for `key` in the `metadata` set
4179
+ * - the value for `key` in the {@link metadata} set
4138
4180
  * - any existing `key` directive
4139
4181
  * - all chords, those are transposed according to the distance between the current and the new key
4140
4182
  * @param {string} newKey The new key.
@@ -4148,7 +4190,7 @@ var $ce1dd7d0f2cd2369$export$2e2bcd8739ae039 = $ce1dd7d0f2cd2369$var$ParserWarni
4148
4190
  if (item instanceof (0, $d454f4215ba01af2$export$2e2bcd8739ae039)) return item.transpose(transpose, newKey);
4149
4191
  return item;
4150
4192
  });
4151
- updatedSong.metadata.set("key", newKey);
4193
+ this.setKey(newKey);
4152
4194
  return updatedSong;
4153
4195
  }
4154
4196
  getTransposeDistance(newKey) {