@lsst/pik-core 0.1.0 → 0.4.0
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.js +52 -49
- package/dist/lib/types/comment-style.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
class
|
|
1
|
+
class n {
|
|
2
2
|
constructor(t) {
|
|
3
3
|
this.lineComment = t;
|
|
4
4
|
}
|
|
5
5
|
static styles = {
|
|
6
6
|
// JavaScript/TypeScript
|
|
7
|
-
js: new
|
|
8
|
-
ts: new
|
|
9
|
-
jsx: new
|
|
10
|
-
tsx: new
|
|
11
|
-
mjs: new
|
|
12
|
-
mts: new
|
|
7
|
+
js: new n("//"),
|
|
8
|
+
ts: new n("//"),
|
|
9
|
+
jsx: new n("//"),
|
|
10
|
+
tsx: new n("//"),
|
|
11
|
+
mjs: new n("//"),
|
|
12
|
+
mts: new n("//"),
|
|
13
|
+
// HTML (for script tags)
|
|
14
|
+
html: new n("//"),
|
|
15
|
+
htm: new n("//"),
|
|
13
16
|
// Config files
|
|
14
|
-
yaml: new
|
|
15
|
-
yml: new
|
|
17
|
+
yaml: new n("#"),
|
|
18
|
+
yml: new n("#"),
|
|
16
19
|
// Shell
|
|
17
|
-
sh: new
|
|
18
|
-
bash: new
|
|
19
|
-
zsh: new
|
|
20
|
+
sh: new n("#"),
|
|
21
|
+
bash: new n("#"),
|
|
22
|
+
zsh: new n("#"),
|
|
20
23
|
// Python
|
|
21
|
-
py: new
|
|
24
|
+
py: new n("#"),
|
|
22
25
|
// Env files
|
|
23
|
-
env: new
|
|
26
|
+
env: new n("#")
|
|
24
27
|
};
|
|
25
|
-
static defaultStyle = new
|
|
28
|
+
static defaultStyle = new n("//");
|
|
26
29
|
/**
|
|
27
30
|
* Get comment style for a file extension
|
|
28
31
|
*/
|
|
29
32
|
static fromExtension(t) {
|
|
30
|
-
const
|
|
31
|
-
return
|
|
33
|
+
const s = t.replace(/^\./, "").toLowerCase();
|
|
34
|
+
return n.styles[s] ?? n.defaultStyle;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Register a custom comment style for an extension
|
|
35
38
|
*/
|
|
36
|
-
static register(t,
|
|
39
|
+
static register(t, s) {
|
|
37
40
|
const i = t.replace(/^\./, "").toLowerCase();
|
|
38
|
-
|
|
41
|
+
n.styles[i] = s;
|
|
39
42
|
}
|
|
40
43
|
}
|
|
41
44
|
class a {
|
|
@@ -48,34 +51,34 @@ class a {
|
|
|
48
51
|
* Create a parser for a specific file extension
|
|
49
52
|
*/
|
|
50
53
|
static forExtension(t) {
|
|
51
|
-
return new a(
|
|
54
|
+
return new a(n.fromExtension(t));
|
|
52
55
|
}
|
|
53
56
|
/**
|
|
54
57
|
* Parse content string for pik selectors and options
|
|
55
58
|
*/
|
|
56
59
|
parse(t) {
|
|
57
|
-
const
|
|
60
|
+
const s = t.split(`
|
|
58
61
|
`), i = [];
|
|
59
|
-
let
|
|
60
|
-
for (let o = 0; o <
|
|
61
|
-
const c =
|
|
62
|
+
let e = null;
|
|
63
|
+
for (let o = 0; o < s.length; o++) {
|
|
64
|
+
const c = s[o], r = o + 1, l = c.match(a.SELECT_REGEX);
|
|
62
65
|
if (l) {
|
|
63
|
-
|
|
66
|
+
e = {
|
|
64
67
|
name: l[1],
|
|
65
68
|
line: r,
|
|
66
69
|
options: []
|
|
67
|
-
}, i.push(
|
|
70
|
+
}, i.push(e);
|
|
68
71
|
continue;
|
|
69
72
|
}
|
|
70
73
|
const h = c.match(a.OPTION_REGEX);
|
|
71
|
-
if (h &&
|
|
72
|
-
const
|
|
74
|
+
if (h && e) {
|
|
75
|
+
const w = {
|
|
73
76
|
name: h[1],
|
|
74
77
|
line: r,
|
|
75
78
|
content: c,
|
|
76
79
|
isActive: !this.isLineCommented(c)
|
|
77
80
|
};
|
|
78
|
-
|
|
81
|
+
e.options.push(w);
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
return { selectors: i, content: t };
|
|
@@ -87,7 +90,7 @@ class a {
|
|
|
87
90
|
return t.trimStart().startsWith(this.commentStyle.lineComment);
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
|
-
class
|
|
93
|
+
class p {
|
|
91
94
|
constructor(t) {
|
|
92
95
|
this.commentStyle = t;
|
|
93
96
|
}
|
|
@@ -101,28 +104,28 @@ class w {
|
|
|
101
104
|
* Comment out a line if not already commented
|
|
102
105
|
*/
|
|
103
106
|
commentLine(t) {
|
|
104
|
-
const
|
|
105
|
-
return
|
|
107
|
+
const s = t.trimStart();
|
|
108
|
+
return s.startsWith(this.commentStyle.lineComment) ? t : `${t.slice(0, t.length - s.length)}${this.commentStyle.lineComment} ${s}`;
|
|
106
109
|
}
|
|
107
110
|
/**
|
|
108
111
|
* Uncomment a line if commented
|
|
109
112
|
*/
|
|
110
113
|
uncommentLine(t) {
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
114
|
+
const s = t.trimStart();
|
|
115
|
+
if (!s.startsWith(this.commentStyle.lineComment))
|
|
113
116
|
return t;
|
|
114
|
-
const i = t.slice(0, t.length -
|
|
117
|
+
const i = t.slice(0, t.length - s.length), e = s.slice(this.commentStyle.lineComment.length), o = e.startsWith(" ") ? e.slice(1) : e;
|
|
115
118
|
return `${i}${o}`;
|
|
116
119
|
}
|
|
117
120
|
}
|
|
118
|
-
class f extends
|
|
121
|
+
class f extends p {
|
|
119
122
|
/**
|
|
120
123
|
* Validate that the option exists in the selector
|
|
121
124
|
*/
|
|
122
|
-
validateOption(t,
|
|
123
|
-
if (!t.options.find((
|
|
125
|
+
validateOption(t, s) {
|
|
126
|
+
if (!t.options.find((e) => e.name === s))
|
|
124
127
|
throw new Error(
|
|
125
|
-
`Option "${
|
|
128
|
+
`Option "${s}" not found in selector "${t.name}"`
|
|
126
129
|
);
|
|
127
130
|
}
|
|
128
131
|
}
|
|
@@ -131,26 +134,26 @@ class m extends f {
|
|
|
131
134
|
* Create a switcher for a specific file extension
|
|
132
135
|
*/
|
|
133
136
|
static forExtension(t) {
|
|
134
|
-
return new m(
|
|
137
|
+
return new m(n.fromExtension(t));
|
|
135
138
|
}
|
|
136
139
|
/**
|
|
137
140
|
* Switch to a specific option, deactivating all others
|
|
138
141
|
*/
|
|
139
|
-
switch(t,
|
|
140
|
-
this.validateOption(
|
|
141
|
-
const
|
|
142
|
+
switch(t, s, i) {
|
|
143
|
+
this.validateOption(s, i);
|
|
144
|
+
const e = t.split(`
|
|
142
145
|
`);
|
|
143
|
-
for (const o of
|
|
144
|
-
const c = o.line - 1, r =
|
|
145
|
-
o.name === i ?
|
|
146
|
+
for (const o of s.options) {
|
|
147
|
+
const c = o.line - 1, r = e[c];
|
|
148
|
+
o.name === i ? e[c] = this.uncommentLine(r) : e[c] = this.commentLine(r);
|
|
146
149
|
}
|
|
147
|
-
return
|
|
150
|
+
return e.join(`
|
|
148
151
|
`);
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
export {
|
|
152
|
-
|
|
153
|
-
|
|
155
|
+
p as CommentManipulator,
|
|
156
|
+
n as CommentStyle,
|
|
154
157
|
a as Parser,
|
|
155
158
|
m as SingleSwitcher,
|
|
156
159
|
f as Switcher
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment-style.d.ts","sourceRoot":"","sources":["../../../src/lib/types/comment-style.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"comment-style.d.ts","sourceRoot":"","sources":["../../../src/lib/types/comment-style.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAY;IA4BrB,4CAA4C;aAC5B,WAAW,EAAE,MAAM;IA5BrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAsB5B;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA0B;;IAG5D,4CAA4C;IAC5B,WAAW,EAAE,MAAM;IAGrC;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY;IAKrD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI;CAI9D"}
|