@@ -4,6 +4,30 @@ import { NullableChordStyle } from '../constants';
44import { transposeDistance } from '../helpers' ;
55import { callChain } from '../utilities' ;
66
7+ interface ConstructorOptions {
8+ capo : number ;
9+ contextKey : Key | null ;
10+ decapo : boolean ;
11+ normalizeChords : boolean ;
12+ renderKey : Key | null ;
13+ songKey : Key | null ;
14+ style : NullableChordStyle ;
15+ transposeKey : string | null ;
16+ useUnicodeModifier : boolean ;
17+ }
18+
19+ const defaultConstructorOptions = {
20+ capo : 0 ,
21+ contextKey : null ,
22+ decapo : false ,
23+ normalizeChords : true ,
24+ renderKey : null ,
25+ songKey : null ,
26+ style : null ,
27+ transposeKey : null ,
28+ useUnicodeModifier : false ,
29+ } ;
30+
731class ChordRenderer {
832 capo : number ;
933
@@ -21,47 +45,17 @@ class ChordRenderer {
2145
2246 useUnicodeModifier : boolean ;
2347
24- constructor (
25- {
26- capo,
27- contextKey,
28- decapo,
29- normalizeChords,
30- renderKey,
31- songKey,
32- style,
33- transposeKey,
34- useUnicodeModifier,
35- } : {
36- capo : number ,
37- contextKey : Key | null ,
38- decapo : boolean ,
39- normalizeChords : boolean ,
40- renderKey : Key | null ,
41- songKey : Key | null ,
42- style : NullableChordStyle ,
43- transposeKey : string | null ,
44- useUnicodeModifier : boolean ,
45- } = {
46- capo : 0 ,
47- contextKey : null ,
48- decapo : false ,
49- normalizeChords : true ,
50- renderKey : null ,
51- songKey : null ,
52- style : null ,
53- transposeKey : null ,
54- useUnicodeModifier : false ,
55- } ,
56- ) {
57- this . capo = decapo ? capo : 0 ;
58- this . contextKey = contextKey ;
59- this . normalizeChords = normalizeChords ;
60- this . renderKey = renderKey ;
61- this . songKey = songKey ;
62- this . style = style ;
63- this . transposeKey = transposeKey ;
64- this . useUnicodeModifier = useUnicodeModifier ;
48+ constructor ( options : Partial < ConstructorOptions > = { } ) {
49+ const config : ConstructorOptions = { ...defaultConstructorOptions , ...options } ;
50+
51+ this . capo = config . decapo ? config . capo : 0 ;
52+ this . contextKey = config . contextKey ;
53+ this . normalizeChords = config . normalizeChords ;
54+ this . renderKey = config . renderKey ;
55+ this . songKey = config . songKey ;
56+ this . style = config . style ;
57+ this . transposeKey = config . transposeKey ;
58+ this . useUnicodeModifier = config . useUnicodeModifier ;
6559 }
6660
6761 render ( chordString : string ) : string {
0 commit comments