@musodojo/music-theory-data 16.0.6 → 16.0.7

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,87 @@
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
+ Get the notes of a scale or the details of a mode.
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
+ // Get the full data structure for the Ionian mode (Major Scale)
66
+ const ionian = music_theory_data.noteCollections.ionian;
67
+
68
+ console.log(ionian.primaryName);
69
+ // "Major"
70
+
71
+ console.log(ionian.intervals);
72
+ // ["1", "2", "3", "4", "5", "6", "7", "8"]
73
+
74
+ // Log the array of all available Note Collection Keys
75
+ console.log(Object.keys(music_theory_data.noteCollections));
76
+ // ["ionian", "dorian", "phrygian", ...]
77
+
78
+ // Log the array of all available Grouped Note Collections Keys
79
+ console.log(Object.keys(music_theory_data.groupedNoteCollections));
80
+ // ["diatonicModes", "pentatonicVariants", ...]
81
+ ```
11
82
 
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**.
83
+ ## API Documentation
15
84
 
16
- > **Goal:** To be _the_ library that powers next-generation interactive music
17
- > tools, practice apps, and educational software.
85
+ For a full list of all available data, types, and utility functions, please see
86
+ the
87
+ **[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.0.7",
4
4
  "description": "The musician-friendly TypeScript library for modes, scales, chords, and more.",
5
5
  "keywords": [
6
6
  "music",
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";
@@ -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) {