instruments-chords 0.0.2

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/LICENCE ADDED
@@ -0,0 +1,21 @@
1
+ Licencia MIT
2
+
3
+ Copyright © 2026 Angel Rangel, poner en repositorio de github
4
+
5
+ Por la presente, se concede permiso gratuito a cualquier persona que obtenga una
6
+ copia de este software y los archivos de documentación asociados (el "Software")
7
+ para utilizarlo sin restricciones, incluyendo, entre otros, los derechos de uso,
8
+ copia, modificación, fusión, publicación, distribución, sublicencia y/o venta de
9
+ copias del Software, y para permitir que las personas a quienes se les
10
+ proporciona el Software lo hagan, sujeto a las siguientes condiciones:
11
+
12
+ El aviso de derechos de autor anterior y este aviso de permiso se incluirán en
13
+ todas las copias o partes sustanciales del Software.
14
+
15
+ EL SOFTWARE SE PROPORCIONA "TAL CUAL", SIN GARANTÍA DE NINGÚN TIPO, EXPRESA O
16
+ IMPLÍCITA, INCLUYENDO, ENTRE OTRAS, LAS GARANTÍAS DE COMERCIABILIDAD, IDONEIDAD
17
+ PARA UN PROPÓSITO PARTICULAR Y NO INFRACCIÓN. EN NINGÚN CASO LOS AUTORES O
18
+ TITULARES DE LOS DERECHOS DE AUTOR SERÁN RESPONSABLES DE NINGUNA RECLAMACIÓN,
19
+ DAÑOS U OTRA RESPONSABILIDAD, YA SEA EN UNA ACCIÓN CONTRACTUAL, EXTRACONTRACTUAL
20
+ O DE OTRO TIPO, QUE SURJA DE, O EN CONEXIÓN CON EL SOFTWARE O EL USO U OTRAS
21
+ OPERACIONES EN EL SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # 🎸 instruments-chords
2
+
3
+ Base de datos de acordes de guitarra para desarrolladores, con generación
4
+ automática de diagramas SVG.
5
+
6
+ Pensada para ser **framework agnostic**, escrita en **TypeScript**, sin
7
+ dependencias externas y fácil de integrar en cualquier proyecto web o backend.
8
+
9
+ ---
10
+
11
+ ## ✨ Características
12
+
13
+ - 🎼 Acordes estructurados por tónica y tipo
14
+ - 🎨 Generación automática de diagramas SVG
15
+ - 🧠 Tipos fuertes en TypeScript
16
+ - 🚫 Sin dependencias externas
17
+ - ⚛️ Compatible con React, Vue, Astro, Svelte, Node.js
18
+
19
+ ---
20
+
21
+ ## 📦 Instalación
22
+
23
+ ```bash
24
+ npm install instruments-chords
25
+ ```
26
+
27
+ ---
28
+
29
+ ## Uso básico
30
+
31
+ ### Obtener un acorde
32
+
33
+ ```typescript
34
+ import { getChord } from 'instruments-chords'
35
+
36
+ const dMajor = getChord('D')
37
+ const dMinor = getChord('D', 'minor')
38
+
39
+ console.log(dMajor)
40
+ ```
41
+
42
+ ### Salida
43
+
44
+ ```typescript
45
+ {
46
+ "6": "x",
47
+ "5": "x",
48
+ "4": 0,
49
+ "3": 2,
50
+ "2": 3,
51
+ "1": 2
52
+ }
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Generar diagrama SVG
58
+
59
+ ```typescript
60
+ import { getChordSvg } from 'instruments-chords'
61
+
62
+ const svg = getChordSvg('D')
63
+
64
+ // En el navegador
65
+ document.body.innerHTML = svg!
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Estructura de los acordes
71
+
72
+ ```typescript
73
+ {
74
+ "6": "x", // cuerda muteada
75
+ "5": "x",
76
+ "4": 0, // cuerda al aire
77
+ "3": 2, // traste 2
78
+ "2": 3,
79
+ "1": 2
80
+ }
81
+ ```
82
+
83
+ ---
84
+
85
+ ## Tipos disponibles
86
+
87
+ ```typescript
88
+ type StringNumber = '1' | '2' | '3' | '4' | '5' | '6'
89
+ type Fret = number | 'x'
90
+
91
+ type ChordShape = Record<StringNumber, Fret>
92
+
93
+ type ChordQuality =
94
+ | 'major'
95
+ | 'minor'
96
+ | '7'
97
+ | 'maj7'
98
+ | 'm7'
99
+ | 'sus2'
100
+ | 'sus4'
101
+ | 'aug'
102
+ | 'dim'
103
+ ```
104
+
105
+ ---
106
+
107
+ ## Ejemplos
108
+
109
+ ```typescript
110
+ getChord('D') // D mayor
111
+ getChord('D', 'minor') // D menor
112
+ getChord('D', '7') // D7
113
+ getChord('D', 'sus4') // Dsus4
114
+ ```
@@ -0,0 +1,2 @@
1
+ import type { ChordsDictionary } from '../types';
2
+ export declare const chords: ChordsDictionary;
@@ -0,0 +1,38 @@
1
+ export const chords = {
2
+ D: {
3
+ major: {
4
+ 6: 'x',
5
+ 5: 'x',
6
+ 4: 0,
7
+ 3: 2,
8
+ 2: 3,
9
+ 1: 2
10
+ },
11
+ minor: {
12
+ 6: 'x',
13
+ 5: 'x',
14
+ 4: 0,
15
+ 3: 2,
16
+ 2: 3,
17
+ 1: 1
18
+ },
19
+ 7: {
20
+ 6: 'x',
21
+ 5: 'x',
22
+ 4: 0,
23
+ 3: 2,
24
+ 2: 3,
25
+ 1: 1
26
+ }
27
+ },
28
+ C: {
29
+ major: {
30
+ 6: 'x',
31
+ 5: 3,
32
+ 4: 2,
33
+ 3: 0,
34
+ 2: 1,
35
+ 1: 0
36
+ }
37
+ }
38
+ };
@@ -0,0 +1 @@
1
+ export * from './chords';
@@ -0,0 +1 @@
1
+ export * from './chords';
@@ -0,0 +1,2 @@
1
+ import type { ChordQuality, ChordShape } from './types';
2
+ export declare function getChord(root: string, quality?: ChordQuality): ChordShape | null;
@@ -0,0 +1,4 @@
1
+ import { chords } from './chords/index';
2
+ export function getChord(root, quality = 'major') {
3
+ return chords[root]?.[quality] ?? null;
4
+ }
@@ -0,0 +1 @@
1
+ export declare function getChordSvg(root: string, quality?: any): string | null;
@@ -0,0 +1,22 @@
1
+ import { getChord } from './getChord';
2
+ import { renderBase } from './svg/base';
3
+ import { SVG_HEIGTH, SVG_WIDTH } from './svg/constants';
4
+ import { renderMarkers } from './svg/markers';
5
+ export function getChordSvg(root, quality) {
6
+ const chord = getChord(root, quality);
7
+ if (chord === null)
8
+ return null;
9
+ const base = renderBase();
10
+ const markers = renderMarkers(chord);
11
+ return `
12
+ <svg
13
+ width="${SVG_WIDTH}
14
+ heigth="${SVG_HEIGTH}
15
+ viewBox="0 0 ${SVG_WIDTH} ${SVG_HEIGTH}"
16
+ xmlns="http"://www.w3.org/2000/svg"
17
+ >
18
+ ${base}
19
+ ${markers}
20
+ </svg>
21
+ `.trim();
22
+ }
@@ -0,0 +1,4 @@
1
+ export { getChord } from './getChord';
2
+ export { getChordSvg } from './getChordSvg';
3
+ export { chords } from './chords/index';
4
+ export * from './types';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { getChord } from './getChord';
2
+ export { getChordSvg } from './getChordSvg';
3
+ export { chords } from './chords/index';
4
+ export * from './types';
@@ -0,0 +1 @@
1
+ export declare function renderBase(): string;
@@ -0,0 +1,15 @@
1
+ import { FRET_COUNT, FRET_SPACING, START_X, START_Y, STRING_COUNT, STRING_SPACING } from './constants';
2
+ export function renderBase() {
3
+ let svg = '';
4
+ // cuerdas
5
+ for (let i = 0; i <= STRING_COUNT; i++) {
6
+ const x = START_X + i * STRING_SPACING;
7
+ svg += `<line x1="${x}" y1="${START_Y}" x2="${x}" y2="${START_Y + FRET_SPACING * FRET_COUNT}" stroke="black"/>`;
8
+ }
9
+ // trastes
10
+ for (let i = 0; i <= FRET_COUNT; i++) {
11
+ const y = START_Y + i * FRET_SPACING;
12
+ svg += `<line x1="${START_X}" y1="${y}" x2="${START_X + STRING_SPACING * (STRING_COUNT - 1)}" y2="${y}" stroke="black"/>`;
13
+ }
14
+ return svg;
15
+ }
@@ -0,0 +1,8 @@
1
+ export declare const SVG_WIDTH = 120;
2
+ export declare const SVG_HEIGTH = 160;
3
+ export declare const STRING_COUNT = 6;
4
+ export declare const FRET_COUNT = 5;
5
+ export declare const STRING_SPACING = 20;
6
+ export declare const FRET_SPACING = 25;
7
+ export declare const START_X = 20;
8
+ export declare const START_Y = 30;
@@ -0,0 +1,8 @@
1
+ export const SVG_WIDTH = 120;
2
+ export const SVG_HEIGTH = 160;
3
+ export const STRING_COUNT = 6;
4
+ export const FRET_COUNT = 5;
5
+ export const STRING_SPACING = 20;
6
+ export const FRET_SPACING = 25;
7
+ export const START_X = 20;
8
+ export const START_Y = 30;
@@ -0,0 +1,2 @@
1
+ import type { ChordShape } from '../types';
2
+ export declare function renderMarkers(chord: ChordShape): string;
@@ -0,0 +1,19 @@
1
+ import { getFretY, getStringX } from './utils';
2
+ export function renderMarkers(chord) {
3
+ let svg = '';
4
+ for (const [string, fret] of Object.entries(chord)) {
5
+ const s = Number(string);
6
+ const x = getStringX(s);
7
+ if (fret === 'x') {
8
+ svg += `<text x1="${x}" y="20" text-anchor="middle">x</text>`;
9
+ }
10
+ else if (fret === 0) {
11
+ svg += `<cicle cx="${x}" cy="20" r="5" fill="none" stroke="black" />`;
12
+ }
13
+ else {
14
+ const y = getFretY(fret);
15
+ svg += `<cicle cx="${x}" cy="${y}" r="6" fill="black" />`;
16
+ }
17
+ }
18
+ return svg;
19
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getStringX(stringNumber: number): number;
2
+ export declare function getFretY(fret: number): number;
@@ -0,0 +1,7 @@
1
+ import { FRET_SPACING, START_X, START_Y, STRING_SPACING } from './constants';
2
+ export function getStringX(stringNumber) {
3
+ return START_X + (6 - stringNumber) * STRING_SPACING;
4
+ }
5
+ export function getFretY(fret) {
6
+ return START_Y + fret * FRET_SPACING - FRET_SPACING / 2;
7
+ }
@@ -0,0 +1,5 @@
1
+ export type StringNumber = '1' | '2' | '3' | '4' | '5' | '6';
2
+ export type Fret = number | 'x';
3
+ export type ChordShape = Record<StringNumber, Fret>;
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>>>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "instruments-chords",
3
+ "version": "0.0.2",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "description": "Guitar chords database for developers",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "test": "vitest"
15
+ },
16
+ "keywords": [
17
+ "guitar",
18
+ "chords",
19
+ "music"
20
+ ],
21
+ "author": "Angel Rangel",
22
+ "devDependencies": {
23
+ "typescript": "^5",
24
+ "prettier": "^3.7.4",
25
+ "ts-standard": "^12.0.2",
26
+ "vitest": "^4.0.16"
27
+ },
28
+ "eslintConfig": {
29
+ "extends": "./node_modules/ts-config/eslintrc.json"
30
+ }
31
+ }