@tonaljs/core 4.6.2 → 4.6.10
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/dist/index.d.ts +171 -6
- package/dist/index.js +284 -362
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +251 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -6
- package/dist/index.es.js +0 -336
- package/dist/index.es.js.map +0 -1
- package/dist/src/distance.d.ts +0 -27
- package/dist/src/interval.d.ts +0 -57
- package/dist/src/named.d.ts +0 -11
- package/dist/src/note.d.ts +0 -43
- package/dist/src/pitch.d.ts +0 -25
- package/dist/src/utils.d.ts +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Fill a string with a repeated character
|
|
3
|
+
*
|
|
4
|
+
* @param character
|
|
5
|
+
* @param repetition
|
|
6
|
+
*/
|
|
7
|
+
declare const fillStr: (s: string, n: number) => string;
|
|
8
|
+
declare function deprecate<ResultFn extends (this: any, ...newArgs: any[]) => ReturnType<ResultFn>>(original: string, alternative: string, fn: ResultFn): (this: unknown, ...args: unknown[]) => ReturnType<ResultFn>;
|
|
9
|
+
|
|
10
|
+
interface Named {
|
|
11
|
+
readonly name: string;
|
|
12
|
+
}
|
|
13
|
+
interface NamedFound {
|
|
14
|
+
readonly empty: false;
|
|
15
|
+
}
|
|
16
|
+
interface NotFound extends Named {
|
|
17
|
+
readonly empty: true;
|
|
18
|
+
readonly name: "";
|
|
19
|
+
}
|
|
20
|
+
declare function isNamed(src: any): src is Named;
|
|
21
|
+
|
|
22
|
+
type Fifths = number;
|
|
23
|
+
type Octaves = number;
|
|
24
|
+
type Direction = 1 | -1;
|
|
25
|
+
type PitchClassCoordinates = [Fifths];
|
|
26
|
+
type NoteCoordinates = [Fifths, Octaves];
|
|
27
|
+
type IntervalCoordinates = [Fifths, Octaves, Direction];
|
|
28
|
+
type PitchCoordinates = PitchClassCoordinates | NoteCoordinates | IntervalCoordinates;
|
|
29
|
+
/**
|
|
30
|
+
* Pitch properties
|
|
31
|
+
*
|
|
32
|
+
* - {number} step - The step number: 0 = C, 1 = D, ... 6 = B
|
|
33
|
+
* - {number} alt - Number of alterations: -2 = 'bb', -1 = 'b', 0 = '', 1 = '#', ...
|
|
34
|
+
* - {number} [oct] = The octave (undefined when is a coord class)
|
|
35
|
+
* - {number} [dir] = Interval direction (undefined when is not an interval)
|
|
36
|
+
*/
|
|
37
|
+
interface Pitch {
|
|
38
|
+
readonly step: number;
|
|
39
|
+
readonly alt: number;
|
|
40
|
+
readonly oct?: number;
|
|
41
|
+
readonly dir?: Direction;
|
|
42
|
+
}
|
|
43
|
+
declare function isPitch(pitch: any): pitch is Pitch;
|
|
44
|
+
declare function encode(pitch: Pitch): PitchCoordinates;
|
|
45
|
+
declare function decode(coord: PitchCoordinates): Pitch;
|
|
46
|
+
|
|
47
|
+
type NoteWithOctave = string;
|
|
48
|
+
type PcName = string;
|
|
49
|
+
type NoteName = NoteWithOctave | PcName;
|
|
50
|
+
type NoteLiteral = NoteName | Pitch | Named;
|
|
51
|
+
interface Note extends Pitch, Named {
|
|
52
|
+
readonly empty: boolean;
|
|
53
|
+
readonly name: NoteName;
|
|
54
|
+
readonly letter: string;
|
|
55
|
+
readonly acc: string;
|
|
56
|
+
readonly pc: PcName;
|
|
57
|
+
readonly chroma: number;
|
|
58
|
+
readonly height: number;
|
|
59
|
+
readonly coord: PitchCoordinates;
|
|
60
|
+
readonly midi: number | null;
|
|
61
|
+
readonly freq: number | null;
|
|
62
|
+
}
|
|
63
|
+
interface NoNote extends Partial<Note> {
|
|
64
|
+
empty: true;
|
|
65
|
+
name: "";
|
|
66
|
+
pc: "";
|
|
67
|
+
acc: "";
|
|
68
|
+
}
|
|
69
|
+
declare const stepToLetter: (step: number) => string;
|
|
70
|
+
declare const altToAcc: (alt: number) => string;
|
|
71
|
+
declare const accToAlt: (acc: string) => number;
|
|
72
|
+
/**
|
|
73
|
+
* Given a note literal (a note name or a note object), returns the Note object
|
|
74
|
+
* @example
|
|
75
|
+
* note('Bb4') // => { name: "Bb4", midi: 70, chroma: 10, ... }
|
|
76
|
+
*/
|
|
77
|
+
declare function note(src: NoteLiteral): Note | NoNote;
|
|
78
|
+
type NoteTokens = [string, string, string, string];
|
|
79
|
+
/**
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
declare function tokenizeNote(str: string): NoteTokens;
|
|
83
|
+
/**
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
declare function coordToNote(noteCoord: PitchCoordinates): Note;
|
|
87
|
+
|
|
88
|
+
type IntervalName = string;
|
|
89
|
+
type IntervalLiteral = IntervalName | Pitch | Named;
|
|
90
|
+
type Quality = "dddd" | "ddd" | "dd" | "d" | "m" | "M" | "P" | "A" | "AA" | "AAA" | "AAAA";
|
|
91
|
+
type Type = "perfectable" | "majorable";
|
|
92
|
+
interface Interval extends Pitch, Named {
|
|
93
|
+
readonly empty: boolean;
|
|
94
|
+
readonly name: IntervalName;
|
|
95
|
+
readonly num: number;
|
|
96
|
+
readonly q: Quality;
|
|
97
|
+
readonly type: Type;
|
|
98
|
+
readonly step: number;
|
|
99
|
+
readonly alt: number;
|
|
100
|
+
readonly dir: Direction;
|
|
101
|
+
readonly simple: number;
|
|
102
|
+
readonly semitones: number;
|
|
103
|
+
readonly chroma: number;
|
|
104
|
+
readonly coord: IntervalCoordinates;
|
|
105
|
+
readonly oct: number;
|
|
106
|
+
}
|
|
107
|
+
interface NoInterval extends Partial<Interval> {
|
|
108
|
+
readonly empty: true;
|
|
109
|
+
readonly name: "";
|
|
110
|
+
readonly acc: "";
|
|
111
|
+
}
|
|
112
|
+
type IntervalTokens = [string, string];
|
|
113
|
+
/**
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
116
|
+
declare function tokenizeInterval(str?: IntervalName): IntervalTokens;
|
|
117
|
+
/**
|
|
118
|
+
* Get interval properties. It returns an object with:
|
|
119
|
+
*
|
|
120
|
+
* - name: the interval name
|
|
121
|
+
* - num: the interval number
|
|
122
|
+
* - type: 'perfectable' or 'majorable'
|
|
123
|
+
* - q: the interval quality (d, m, M, A)
|
|
124
|
+
* - dir: interval direction (1 ascending, -1 descending)
|
|
125
|
+
* - simple: the simplified number
|
|
126
|
+
* - semitones: the size in semitones
|
|
127
|
+
* - chroma: the interval chroma
|
|
128
|
+
*
|
|
129
|
+
* @param {string} interval - the interval name
|
|
130
|
+
* @return {Object} the interval properties
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* import { interval } from '@tonaljs/core'
|
|
134
|
+
* interval('P5').semitones // => 7
|
|
135
|
+
* interval('m3').type // => 'majorable'
|
|
136
|
+
*/
|
|
137
|
+
declare function interval(src: IntervalLiteral): Interval | NoInterval;
|
|
138
|
+
/**
|
|
139
|
+
* @private
|
|
140
|
+
*
|
|
141
|
+
* forceDescending is used in the case of unison (#243)
|
|
142
|
+
*/
|
|
143
|
+
declare function coordToInterval(coord: PitchCoordinates, forceDescending?: boolean): Interval;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Transpose a note by an interval.
|
|
147
|
+
*
|
|
148
|
+
* @param {string} note - the note or note name
|
|
149
|
+
* @param {string} interval - the interval or interval name
|
|
150
|
+
* @return {string} the transposed note name or empty string if not valid notes
|
|
151
|
+
* @example
|
|
152
|
+
* import { tranpose } from "@tonaljs/core"
|
|
153
|
+
* transpose("d3", "3M") // => "F#3"
|
|
154
|
+
* transpose("D", "3M") // => "F#"
|
|
155
|
+
* ["C", "D", "E", "F", "G"].map(pc => transpose(pc, "M3)) // => ["E", "F#", "G#", "A", "B"]
|
|
156
|
+
*/
|
|
157
|
+
declare function transpose(noteName: NoteLiteral, intervalName: IntervalLiteral): NoteName;
|
|
158
|
+
/**
|
|
159
|
+
* Find the interval distance between two notes or coord classes.
|
|
160
|
+
*
|
|
161
|
+
* To find distance between coord classes, both notes must be coord classes and
|
|
162
|
+
* the interval is always ascending
|
|
163
|
+
*
|
|
164
|
+
* @param {Note|string} from - the note or note name to calculate distance from
|
|
165
|
+
* @param {Note|string} to - the note or note name to calculate distance to
|
|
166
|
+
* @return {string} the interval name or empty string if not valid notes
|
|
167
|
+
*
|
|
168
|
+
*/
|
|
169
|
+
declare function distance(fromNote: NoteLiteral, toNote: NoteLiteral): IntervalName;
|
|
170
|
+
|
|
171
|
+
export { Direction, Interval, IntervalCoordinates, IntervalLiteral, IntervalName, Named, NamedFound, NoInterval, NoNote, NotFound, Note, NoteCoordinates, NoteLiteral, NoteName, NoteWithOctave, PcName, Pitch, PitchClassCoordinates, PitchCoordinates, accToAlt, altToAcc, coordToInterval, coordToNote, decode, deprecate, distance, encode, fillStr, interval, isNamed, isPitch, note, stepToLetter, tokenizeInterval, tokenizeNote, transpose };
|