@musodojo/music-theory-data 16.0.6 → 16.1.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
@@ -1,17 +1,92 @@
1
- # Music Theory Data
2
-
3
- ## Currently Under Review for Accuracy
1
+ # Muso Dojo | Music Theory Data
4
2
 
5
3
  **The musician-friendly TypeScript library for modes, scales, chords, and
6
4
  more.**
7
5
 
8
- A modern, Deno/TypeScript-first collection of **music theory data structures**
9
- and **utility functions** for working with modes, scales, arpeggios, chords, and
10
- beyond.
6
+ > **Note:** This library is currently under review for accuracy. Please verify
7
+ > data before use in a critical application.
8
+
9
+ ## Features
10
+
11
+ - **Rich Data Structures:** Access detailed information for scales, modes,
12
+ chords, and more, including intervals, integer notations, and common names.
13
+ - **Practical Utility Functions:** Helpers for common tasks like generating note
14
+ names from a root note and a collection key.
15
+ - **Fully Typed:** Written in TypeScript with comprehensive type definitions for
16
+ a great developer experience.
17
+ - **Deno First, NPM Ready:** A modern Deno module that is also published to npm
18
+ for use in Node.js projects.
19
+
20
+ ## Installation
21
+
22
+ ### Deno / JSR
23
+
24
+ Import directly from JSR in your Deno project:
25
+
26
+ ```ts
27
+ import * as music_theory_data from "@musodojo/music-theory-data";
28
+ ```
29
+
30
+ or
31
+
32
+ ```ts
33
+ import * as music_theory_data from "jsr:@musodojo/music-theory-data";
34
+ ```
35
+
36
+ ### Node.js / npm
37
+
38
+ Install the package from the npm registry:
39
+
40
+ ```bash
41
+ npm install @musodojo/music-theory-data
42
+ ```
43
+
44
+ Then import it into your project:
45
+
46
+ ```ts
47
+ import * as music_theory_data from "@musodojo/music-theory-data";
48
+ ```
49
+
50
+ ## Usage Example
51
+
52
+ The `tests/` directory contains many useful examples.
53
+
54
+ ```ts
55
+ import * as music_theory_data from "jsr:@musodojo/music-theory-data";
56
+
57
+ // Get the notes of A Harmonic Minor
58
+ const notes = music_theory_data.getNoteNamesFromRootAndCollectionKey(
59
+ "A",
60
+ "harmonicMinor",
61
+ );
62
+ console.log(notes);
63
+ // ["A", "B", "C", "D", "E", "F", "G♯", "A"]
64
+
65
+ // Automatically knows whether to use flats or sharps
66
+ notes = music_theory_data.getNoteNamesFromRootAndCollectionKey("F", "ionian");
67
+ console.log(notes);
68
+ // ["F", "G", "A", "B♭", "C", "D", "E", "F"];
69
+
70
+ // Get the full data structure for the Ionian mode (Major Scale)
71
+ const ionian = music_theory_data.noteCollections.ionian;
72
+
73
+ console.log(ionian.primaryName);
74
+ // "Major"
75
+
76
+ console.log(ionian.intervals);
77
+ // ["1", "2", "3", "4", "5", "6", "7", "8"]
78
+
79
+ // Log the array of all available Note Collection Keys
80
+ console.log(Object.keys(music_theory_data.noteCollections));
81
+ // ["ionian", "dorian", "phrygian", ...]
82
+
83
+ // Log the array of all available Grouped Note Collections Keys
84
+ console.log(Object.keys(music_theory_data.groupedNoteCollections));
85
+ // ["diatonicModes", "pentatonicVariants", ...]
86
+ ```
11
87
 
12
- Built for **musicians, educators, and creative coders**, it goes beyond raw note
13
- lists — providing rich, structured metadata and practical helpers for
14
- **analysis, composition, and interactive tools**.
88
+ ## API Documentation
15
89
 
16
- > **Goal:** To be _the_ library that powers next-generation interactive music
17
- > tools, practice apps, and educational software.
90
+ For a full list of all available data, types, and utility functions, please see
91
+ the
92
+ **[auto-generated API documentation on JSR](https://jsr.io/@musodojo/music-theory-data/doc)**.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@musodojo/music-theory-data",
3
- "version": "16.0.6",
3
+ "version": "16.1.0",
4
4
  "description": "The musician-friendly TypeScript library for modes, scales, chords, and more.",
5
5
  "keywords": [
6
6
  "music",
@@ -95,9 +95,9 @@ const ionianSharp5: ScaleCollection = {
95
95
  "augmented second",
96
96
  "half",
97
97
  "whole",
98
- "whole",
98
+ "half",
99
99
  ],
100
- patternShort: ["W", "W", "H", "A2", "H", "W", "W"],
100
+ patternShort: ["W", "W", "H", "A2", "H", "W", "H"],
101
101
  } as const;
102
102
 
103
103
  const dorianSharp4: ScaleCollection = {
@@ -122,10 +122,10 @@ const dorianSharp4: ScaleCollection = {
122
122
  "augmented second",
123
123
  "half",
124
124
  "whole",
125
- "whole",
126
125
  "half",
126
+ "whole",
127
127
  ],
128
- patternShort: ["W", "H", "A2", "H", "W", "W", "H"],
128
+ patternShort: ["W", "H", "A2", "H", "W", "H", "W"],
129
129
  } as const;
130
130
 
131
131
  const phrygianDominant: ScaleCollection = {
@@ -187,9 +187,9 @@ const lydianSharp2: ScaleCollection = {
187
187
  "half",
188
188
  "whole",
189
189
  "whole",
190
- "whole",
190
+ "half",
191
191
  ],
192
- patternShort: ["A2", "H", "W", "H", "W", "W", "W"],
192
+ patternShort: ["A2", "H", "W", "H", "W", "W", "H"],
193
193
  } as const;
194
194
 
195
195
  const superLocrianDoubleFlat7: ScaleCollection = {
@@ -211,8 +211,16 @@ const superLocrianDoubleFlat7: ScaleCollection = {
211
211
  "altered",
212
212
  "theoretical",
213
213
  ],
214
- pattern: ["half", "whole", "half", "whole", "whole", "half", "whole"],
215
- patternShort: ["H", "W", "H", "W", "W", "H", "W"],
214
+ pattern: [
215
+ "half",
216
+ "whole",
217
+ "half",
218
+ "whole",
219
+ "whole",
220
+ "half",
221
+ "augmented second",
222
+ ],
223
+ patternShort: ["H", "W", "H", "W", "W", "H", "A2"],
216
224
  } as const;
217
225
 
218
226
  export const _harmonicMinorModes = {
package/src/mod.ts CHANGED
@@ -13,28 +13,59 @@
13
13
  * import * as music_theory_data from "jsr:@musodojo/music-theory-data";
14
14
  *
15
15
  * // You can now access all the data and functions.
16
+ *
16
17
  * // The details for the Ionian Diatonic Mode (Major Scale).
17
18
  * console.log("ionian details: ", music_theory_data.noteCollections.ionian);
18
19
  * // ionian details: {
19
- * // primaryName: "Major",
20
- * // names: [ "Major", "Ionian", "Major Scale", "Ionian Mode", "Diatonic Major" ],
21
- * // intervals: [
22
- * // "1", "2", "3",
23
- * // "4", "5", "6",
24
- * // "7", "8"
25
- * // ],
26
- * // integers: [
27
- * // 0, 2, 4, 5,
28
- * // 7, 9, 11
29
- * // ],
30
- * // rotation: 0,
31
- * // type: [
32
- * // "major.
33
- * // ...
20
+ * // category: "scale",
21
+ * // rotation: 0,
22
+ * // primaryName: "Major",
23
+ * // names: [
24
+ * // "Major",
25
+ * // "Ionian",
26
+ * // "Major Scale",
27
+ * // "Ionian Mode",
28
+ * // "Diatonic Major",
29
+ * // ],
30
+ * // intervals: ["1", "2", "3", "4", "5", "6", "7", "8"],
31
+ * // integers: [0, 2, 4, 5, 7, 9, 11],
32
+ * // type: [
33
+ * // "major",
34
+ * // "ionian",
35
+ * // "mode",
36
+ * // "scale",
37
+ * // "church mode",
38
+ * // "diatonic mode",
39
+ * // "heptatonic",
40
+ * // "first diatonic mode",
41
+ * // "do mode",
42
+ * // ],
43
+ * // characteristics: [
44
+ * // "bright",
45
+ * // "happy",
46
+ * // "stable",
47
+ * // "uplifting",
48
+ * // "consonant",
49
+ * // "western",
50
+ * // "foundational",
51
+ * // "simple",
52
+ * // "pop music",
53
+ * // "major tonality",
54
+ * // "commonly used western scale",
55
+ * // ],
56
+ * // pattern: ["whole", "whole", "half", "whole", "whole", "whole", "half"],
57
+ * // patternShort: ["W", "W", "H", "W", "W", "W", "H"],
34
58
  * // }
59
+ *
35
60
  * // Get the notes of a stored chord, or scale.
36
61
  * console.log("A harmonic minor: ", music_theory_data.getNoteNamesFromRootAndCollectionKey("A", "harmonicMinor"))
37
62
  * // A harmonic minor: ["A", "B", "C", "D", "E", "F", "G♯", "A"]
63
+ *
64
+ * // Log the array of all available Note Collection Keys
65
+ * console.log(Object.keys(music_theory_data.noteCollections));
66
+ *
67
+ * // Log the array of all available Grouped Note Collections Keys
68
+ * console.log(Object.keys(music_theory_data.groupedNoteCollections));
38
69
  * ```
39
70
  */
40
71
  export * from "./data/mod.ts";
@@ -9,6 +9,7 @@ import {
9
9
  simpleToCompoundIntervalMap,
10
10
  simpleToExtensionIntervalMap,
11
11
  } from "../data/labels/note-labels.ts";
12
+ import type { NoteCollection } from "../types/note-collections.d.ts";
12
13
 
13
14
  export function filterOutOctaveIntervals(
14
15
  intervals: readonly Interval[],
@@ -97,3 +98,14 @@ export function getIntervalsFromQualities(
97
98
  return interval ? [interval] : [];
98
99
  });
99
100
  }
101
+
102
+ /**
103
+ * Extracts the interval qualities (e.g., "P1", "M2", "m3") from a NoteCollection.
104
+ * @param collection The NoteCollection object.
105
+ * @returns An array of IntervalQuality strings.
106
+ */
107
+ export function getQualitiesFromNoteCollection(
108
+ collection: NoteCollection,
109
+ ): IntervalQuality[] {
110
+ return getQualitiesFromIntervals(collection.intervals);
111
+ }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Rotates an array by a given number of steps.
3
+ * The rotation wraps around, so a positive rotation moves elements to the right,
4
+ * and a negative rotation moves them to the left.
5
+ *
6
+ * @param array The array to rotate.
7
+ * @param rotation The number of positions to rotate the array.
8
+ * @returns A new array with the elements rotated.
9
+ */
1
10
  export function rotateArray<T>(array: T[], rotation: number): T[] {
2
11
  const normalizedRotation = ((rotation % array.length) + array.length) %
3
12
  array.length;
@@ -5,7 +14,13 @@ export function rotateArray<T>(array: T[], rotation: number): T[] {
5
14
  array.slice(0, normalizedRotation),
6
15
  );
7
16
  }
8
-
17
+ /**
18
+ * Rotates an array so that it starts with a specific element.
19
+ * @param array The array to rotate.
20
+ * @param start The element that should become the first element of the new array.
21
+ * @returns A new array, rotated to begin with the `start` element.
22
+ * @throws If the `start` element is not found in the array.
23
+ */
9
24
  export function rotateArrayToStartWith<T>(array: T[], start: T): T[] {
10
25
  const index = array.indexOf(start);
11
26
  if (index === -1) {