instruments-chords 0.0.7 → 0.0.8

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.
@@ -1,38 +1,209 @@
1
1
  export const chords = {
2
- D: {
2
+ C: {
3
3
  major: {
4
- 6: 'x',
5
- 5: 'x',
6
- 4: 0,
7
- 3: 2,
8
- 2: 3,
9
- 1: 2
4
+ default: '1',
5
+ variants: {
6
+ 1: {
7
+ 6: 'x',
8
+ 5: 3,
9
+ 4: 2,
10
+ 3: 0,
11
+ 2: 1,
12
+ 1: 0
13
+ },
14
+ 2: {
15
+ 6: 'x',
16
+ 5: 3,
17
+ 4: 2,
18
+ 3: 5,
19
+ 2: 'x',
20
+ 1: 'x'
21
+ }
22
+ }
10
23
  },
11
24
  minor: {
12
- 6: 'x',
13
- 5: 'x',
14
- 4: 0,
15
- 3: 2,
16
- 2: 3,
17
- 1: 1
25
+ default: '1',
26
+ variants: {
27
+ 1: {
28
+ 6: 'x',
29
+ 5: 3,
30
+ 4: 5,
31
+ 3: 5,
32
+ 2: 4,
33
+ 1: 3
34
+ }
35
+ }
36
+ },
37
+ 5: {
38
+ default: '1',
39
+ variants: {
40
+ 1: {
41
+ 6: 'x',
42
+ 5: 3,
43
+ 4: 5,
44
+ 3: 5,
45
+ 2: 'x',
46
+ 1: 'x'
47
+ }
48
+ }
18
49
  },
19
50
  7: {
20
- 6: 'x',
21
- 5: 'x',
22
- 4: 0,
23
- 3: 2,
24
- 2: 3,
25
- 1: 1
51
+ default: '1',
52
+ variants: {
53
+ 1: {
54
+ 6: 'x',
55
+ 5: 3,
56
+ 4: 2,
57
+ 3: 3,
58
+ 2: 1,
59
+ 1: 'x'
60
+ }
61
+ }
62
+ },
63
+ maj7: {
64
+ default: '1',
65
+ variants: {
66
+ 1: {
67
+ 6: 'x',
68
+ 5: 3,
69
+ 4: 2,
70
+ 3: 0,
71
+ 2: 0,
72
+ 1: 0
73
+ }
74
+ }
75
+ },
76
+ m7: {
77
+ default: '1',
78
+ variants: {
79
+ 1: {
80
+ 6: 'x',
81
+ 5: 3,
82
+ 4: 5,
83
+ 3: 3,
84
+ 2: 4,
85
+ 1: 3
86
+ }
87
+ }
88
+ },
89
+ sus4: {
90
+ default: '1',
91
+ variants: {
92
+ 1: {
93
+ 6: 'x',
94
+ 5: 3,
95
+ 4: 5,
96
+ 3: 5,
97
+ 2: 6,
98
+ 1: 3
99
+ }
100
+ }
101
+ },
102
+ add9: {
103
+ default: '1',
104
+ variants: {
105
+ 1: {
106
+ 6: 'x',
107
+ 5: 3,
108
+ 4: 2,
109
+ 3: 0,
110
+ 2: 3,
111
+ 1: 0
112
+ }
113
+ }
114
+ },
115
+ sus2: {
116
+ default: '1',
117
+ variants: {
118
+ 1: {
119
+ 6: 'x',
120
+ 5: 3,
121
+ 4: 5,
122
+ 3: 5,
123
+ 2: 3,
124
+ 1: 3
125
+ }
126
+ }
127
+ },
128
+ '7sus4': {
129
+ default: '1',
130
+ variants: {
131
+ 1: {
132
+ 6: 'x',
133
+ 5: 3,
134
+ 4: 5,
135
+ 3: 3,
136
+ 2: 6,
137
+ 1: 3
138
+ }
139
+ }
140
+ },
141
+ '7#9': {
142
+ default: '1',
143
+ variants: {
144
+ 1: {
145
+ 6: 'x',
146
+ 5: 3,
147
+ 4: 2,
148
+ 3: 3,
149
+ 2: 4,
150
+ 1: 'x'
151
+ }
152
+ }
153
+ },
154
+ 9: {
155
+ default: '1',
156
+ variants: {
157
+ 1: {
158
+ 6: 'x',
159
+ 5: 3,
160
+ 4: 2,
161
+ 3: 3,
162
+ 2: 3,
163
+ 1: 'x'
164
+ }
165
+ }
26
166
  }
27
167
  },
28
- C: {
168
+ D: {
29
169
  major: {
30
- 6: 'x',
31
- 5: 3,
32
- 4: 2,
33
- 3: 0,
34
- 2: 1,
35
- 1: 0
170
+ default: '1',
171
+ variants: {
172
+ 1: {
173
+ 6: 'x',
174
+ 5: 'x',
175
+ 4: 0,
176
+ 3: 2,
177
+ 2: 3,
178
+ 1: 2
179
+ }
180
+ }
181
+ },
182
+ minor: {
183
+ default: '1',
184
+ variants: {
185
+ 1: {
186
+ 6: 'x',
187
+ 5: 'x',
188
+ 4: 0,
189
+ 3: 2,
190
+ 2: 3,
191
+ 1: 1
192
+ }
193
+ }
194
+ },
195
+ 7: {
196
+ default: '1',
197
+ variants: {
198
+ 1: {
199
+ 6: 'x',
200
+ 5: 'x',
201
+ 4: 0,
202
+ 3: 2,
203
+ 2: 3,
204
+ 1: 1
205
+ }
206
+ }
36
207
  }
37
208
  }
38
209
  };
@@ -1,2 +1,2 @@
1
- import type { ChordQuality, ChordShape } from './types';
2
- export declare function getChord(root: string, quality?: ChordQuality): ChordShape | null;
1
+ import type { ChordQuality, ChordShape, ChordVariantId } from './types';
2
+ export declare function getChord(root: string, quality?: ChordQuality, variant?: ChordVariantId): ChordShape | null;
package/dist/getChord.js CHANGED
@@ -1,4 +1,16 @@
1
1
  import { chords } from './chords/index';
2
- export function getChord(root, quality = 'major') {
3
- return chords[root]?.[quality] ?? null;
2
+ export function getChord(root, quality = 'major', variant) {
3
+ const chord = chords[root];
4
+ if (chord === null)
5
+ return null;
6
+ const qualityDefinition = chord[quality];
7
+ if (qualityDefinition === undefined) {
8
+ return null;
9
+ }
10
+ const selectedVariant = variant ?? qualityDefinition.default;
11
+ const shape = qualityDefinition.variants[selectedVariant];
12
+ if (!shape) {
13
+ return null;
14
+ }
15
+ return shape;
4
16
  }
@@ -1 +1,2 @@
1
- export declare function getChordSvg(root: string, quality?: any): string | null;
1
+ import type { ChordQuality, ChordVariantId } from './types';
2
+ export declare function getChordSvg(root: string, quality: ChordQuality, variant?: ChordVariantId): string | null;
@@ -2,9 +2,9 @@ import { getChord } from './getChord';
2
2
  import { renderBase } from './svg/base';
3
3
  import { renderMarkers } from './svg/markers';
4
4
  import { SVG_WIDTH, SVG_HEIGHT } from './svg/constants';
5
- export function getChordSvg(root, quality) {
6
- const chord = getChord(root, quality);
7
- if (!chord)
5
+ export function getChordSvg(root, quality, variant) {
6
+ const chord = getChord(root, quality, variant);
7
+ if (chord === null)
8
8
  return null;
9
9
  const base = renderBase();
10
10
  const markers = renderMarkers(chord);
@@ -1,19 +1,42 @@
1
1
  import { getStringX, getFretY } from './utils';
2
+ const STRING_ORDER = ['6', '5', '4', '3', '2', '1'];
2
3
  export function renderMarkers(chord) {
3
4
  let svg = '';
4
- for (const [string, fret] of Object.entries(chord)) {
5
- const s = Number(string);
6
- const x = getStringX(s);
5
+ for (const string of STRING_ORDER) {
6
+ const fret = chord[string];
7
+ const x = getStringX(Number(string));
7
8
  if (fret === 'x') {
8
- svg += `<text x="${x}" y="20" text-anchor="middle" fill="currentcolor">x</text>`;
9
+ svg += `
10
+ <text
11
+ x="${x}"
12
+ y="20"
13
+ text-anchor="middle"
14
+ fill="currentColor"
15
+ >x</text>
16
+ `;
17
+ continue;
9
18
  }
10
- else if (fret === 0) {
11
- svg += `<circle cx="${x}" cy="17" r="5" fill="none" stroke="currentcolor"/>`;
12
- }
13
- else {
14
- const y = getFretY(fret);
15
- svg += `<circle cx="${x}" cy="${y}" r="6" fill="currentcolor"/>`;
19
+ if (fret === 0) {
20
+ svg += `
21
+ <circle
22
+ cx="${x}"
23
+ cy="17"
24
+ r="5"
25
+ fill="none"
26
+ stroke="currentColor"
27
+ />
28
+ `;
29
+ continue;
16
30
  }
31
+ const y = getFretY(fret);
32
+ svg += `
33
+ <circle
34
+ cx="${x}"
35
+ cy="${y}"
36
+ r="6"
37
+ fill="currentColor"
38
+ />
39
+ `;
17
40
  }
18
- return svg;
41
+ return svg.trim();
19
42
  }
package/dist/types.d.ts CHANGED
@@ -2,4 +2,10 @@ export type StringNumber = '1' | '2' | '3' | '4' | '5' | '6';
2
2
  export type Fret = number | 'x';
3
3
  export type ChordShape = Record<StringNumber, Fret>;
4
4
  export type ChordQuality = 'major' | 'minor' | '5' | '7' | 'maj7' | 'm7' | 'sus4' | 'add9' | 'sus2' | '7sus4' | '7#9' | '9' | 'aug' | 'dim';
5
- export type ChordsDictionary = Record<string, Partial<Record<ChordQuality, ChordShape>>>;
5
+ export type ChordVariantId = string;
6
+ export type ChordVariant = Record<ChordVariantId, ChordShape>;
7
+ export interface ChordQualityDefinition {
8
+ default: ChordVariantId;
9
+ variants: ChordVariant;
10
+ }
11
+ export type ChordsDictionary = Record<string, Partial<Record<ChordQuality, ChordQualityDefinition>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instruments-chords",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "Guitar chords database for developers",
@@ -20,9 +20,9 @@
20
20
  ],
21
21
  "author": "Angel Rangel",
22
22
  "devDependencies": {
23
- "typescript": "^5",
24
23
  "prettier": "^3.7.4",
25
24
  "ts-standard": "^12.0.2",
25
+ "typescript": "^5",
26
26
  "vitest": "^4.0.16"
27
27
  },
28
28
  "eslintConfig": {