@lsst/pik-core 0.1.0 → 0.2.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 CHANGED
@@ -1,41 +1,44 @@
1
- class e {
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 e("//"),
8
- ts: new e("//"),
9
- jsx: new e("//"),
10
- tsx: new e("//"),
11
- mjs: new e("//"),
12
- mts: new e("//"),
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 e("#"),
15
- yml: new e("#"),
17
+ yaml: new n("#"),
18
+ yml: new n("#"),
16
19
  // Shell
17
- sh: new e("#"),
18
- bash: new e("#"),
19
- zsh: new e("#"),
20
+ sh: new n("#"),
21
+ bash: new n("#"),
22
+ zsh: new n("#"),
20
23
  // Python
21
- py: new e("#"),
24
+ py: new n("#"),
22
25
  // Env files
23
- env: new e("#")
26
+ env: new n("#")
24
27
  };
25
- static defaultStyle = new e("//");
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 n = t.replace(/^\./, "").toLowerCase();
31
- return e.styles[n] ?? e.defaultStyle;
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, n) {
39
+ static register(t, s) {
37
40
  const i = t.replace(/^\./, "").toLowerCase();
38
- e.styles[i] = n;
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(e.fromExtension(t));
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 n = t.split(`
60
+ const s = t.split(`
58
61
  `), i = [];
59
- let s = null;
60
- for (let o = 0; o < n.length; o++) {
61
- const c = n[o], r = o + 1, l = c.match(a.SELECT_REGEX);
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
- s = {
66
+ e = {
64
67
  name: l[1],
65
68
  line: r,
66
69
  options: []
67
- }, i.push(s);
70
+ }, i.push(e);
68
71
  continue;
69
72
  }
70
73
  const h = c.match(a.OPTION_REGEX);
71
- if (h && s) {
72
- const p = {
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
- s.options.push(p);
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 w {
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 n = t.trimStart();
105
- return n.startsWith(this.commentStyle.lineComment) ? t : `${t.slice(0, t.length - n.length)}${this.commentStyle.lineComment} ${n}`;
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 n = t.trimStart();
112
- if (!n.startsWith(this.commentStyle.lineComment))
114
+ const s = t.trimStart();
115
+ if (!s.startsWith(this.commentStyle.lineComment))
113
116
  return t;
114
- const i = t.slice(0, t.length - n.length), s = n.slice(this.commentStyle.lineComment.length), o = s.startsWith(" ") ? s.slice(1) : s;
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 w {
121
+ class f extends p {
119
122
  /**
120
123
  * Validate that the option exists in the selector
121
124
  */
122
- validateOption(t, n) {
123
- if (!t.options.find((s) => s.name === n))
125
+ validateOption(t, s) {
126
+ if (!t.options.find((e) => e.name === s))
124
127
  throw new Error(
125
- `Option "${n}" not found in selector "${t.name}"`
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(e.fromExtension(t));
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, n, i) {
140
- this.validateOption(n, i);
141
- const s = t.split(`
142
+ switch(t, s, i) {
143
+ this.validateOption(s, i);
144
+ const e = t.split(`
142
145
  `);
143
- for (const o of n.options) {
144
- const c = o.line - 1, r = s[c];
145
- o.name === i ? s[c] = this.uncommentLine(r) : s[c] = this.commentLine(r);
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 s.join(`
150
+ return e.join(`
148
151
  `);
149
152
  }
150
153
  }
151
154
  export {
152
- w as CommentManipulator,
153
- e as CommentStyle,
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;IAyBrB,4CAA4C;aAC5B,WAAW,EAAE,MAAM;IAzBrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAmB5B;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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsst/pik-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Core library for parsing and switching @pik config markers",
5
5
  "type": "module",
6
6
  "license": "MIT",