vadivam 0.0.81 → 0.0.82

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/README.md CHANGED
@@ -8,7 +8,7 @@ Tree-shakeable 24px outline and solid SVG icons for JavaScript, with raw assets
8
8
  [![downloads](https://img.shields.io/npm/dw/vadivam?style=flat-square&color=666)](https://www.npmjs.com/package/vadivam)
9
9
  [![license](https://img.shields.io/npm/l/vadivam?style=flat-square&color=111)](https://github.com/praveenjuge/vadivam/blob/main/LICENSE)
10
10
 
11
- ![All Vadivam icons](https://raw.githubusercontent.com/praveenjuge/vadivam/main/apps/docs/public/preview.png?v=0.0.81)
11
+ ![All Vadivam icons](https://raw.githubusercontent.com/praveenjuge/vadivam/main/apps/docs/public/preview.png?v=0.0.82)
12
12
 
13
13
  ```sh
14
14
  npm install vadivam
Binary file
Binary file
@@ -87,6 +87,146 @@ const renameIdentifier = (identifier) =>
87
87
  ? identifier.replace(/Lucide/g, "Vadivam").replace(/LUCIDE/g, "VADIVAM")
88
88
  : identifier;
89
89
 
90
+ const blank = (span) => span.replace(/[^\n]/g, " ");
91
+
92
+ // The text with strings, template-literal text, and comments blanked out, at
93
+ // the same offsets, so their brackets and commas don't count as code. Code in
94
+ // a template's `${...}` stays, so an object there is still checked.
95
+ function blankQuoted(text) {
96
+ return scanCode(text, 0, false).output;
97
+ }
98
+
99
+ // Where the ' or " string opening at text[position] ends, or -1 when that
100
+ // quote can't open one: a string never follows a name (`Don't` in JSX text),
101
+ // and one without a closing quote on its line is JSX text too.
102
+ function stringEnd(text, position) {
103
+ if (position > 0 && /[\w$]/.test(text[position - 1])) return -1;
104
+ const quote = text[position];
105
+ let stop = position + 1;
106
+ while (stop < text.length && text[stop] !== quote && text[stop] !== "\n") stop += text[stop] === "\\" ? 2 : 1;
107
+ return stop < text.length && text[stop] === quote ? stop + 1 : -1;
108
+ }
109
+
110
+ // Where the regular expression opening at text[position] ends, or -1 when
111
+ // it doesn't close on its line (so the `/` is division or JSX text).
112
+ function regexEnd(text, position) {
113
+ let inClass = false;
114
+ for (let stop = position + 1; stop < text.length && text[stop] !== "\n"; stop += 1) {
115
+ if (text[stop] === "\\") stop += 1;
116
+ else if (text[stop] === "[") inClass = true;
117
+ else if (text[stop] === "]") inClass = false;
118
+ else if (text[stop] === "/" && !inClass) return stop + 1;
119
+ }
120
+ return -1;
121
+ }
122
+
123
+ // Whether a `/` after `previous`, the last code character, opens a regular
124
+ // expression: at the start, after an operator or opening bracket, or after a
125
+ // keyword such as `return`, but not after a value (`total / 2`, `count++ / 2`,
126
+ // TypeScript's `size! / 2`) or JSX `<`.
127
+ const regexCanStart = (previous, output) =>
128
+ previous === "" ||
129
+ (/[(,=:[!&|?{;+\-*%~^]/.test(previous) && !/(?:\+\+|--|[\w$)\]]!)\s*$/.test(output.slice(-64))) ||
130
+ (/[\w$]/.test(previous) &&
131
+ /(?:^|[^\w$.])(?:return|typeof|case|do|else|in|of|void|yield|await|delete|new|instanceof)\s*$/.test(output.slice(-64)));
132
+
133
+ // Scans code from `position`, blanking strings, regular expressions, and
134
+ // comments. Inside a template's `${...}` (`expression`), it stops after the
135
+ // `}` that closes it.
136
+ function scanCode(text, position, expression) {
137
+ let output = "";
138
+ let depth = 0;
139
+ // The last code character, "" at the start; a string or regex is a value.
140
+ let previous = "";
141
+ while (position < text.length) {
142
+ const character = text[position];
143
+ const next = text[position + 1];
144
+ let stop = -1;
145
+ if (character === "/" && next === "*") {
146
+ const close = text.indexOf("*/", position + 2);
147
+ stop = close < 0 ? text.length : close + 2;
148
+ } else if (character === "/" && next === "/") {
149
+ const close = text.indexOf("\n", position);
150
+ stop = close < 0 ? text.length : close;
151
+ } else if (character === '"' || character === "'") {
152
+ stop = stringEnd(text, position);
153
+ if (stop >= 0) previous = "a";
154
+ } else if (character === "/" && regexCanStart(previous, output)) {
155
+ stop = regexEnd(text, position);
156
+ if (stop >= 0) previous = "a";
157
+ }
158
+ if (stop >= 0) {
159
+ output += blank(text.slice(position, stop));
160
+ position = stop;
161
+ } else if (character === "`") {
162
+ const template = scanTemplate(text, position);
163
+ output += template.output;
164
+ position = template.position;
165
+ previous = "a";
166
+ } else {
167
+ output += character;
168
+ position += 1;
169
+ if (!/\s/.test(character)) previous = character;
170
+ if (expression && character === "{") depth += 1;
171
+ else if (expression && character === "}" && (depth -= 1) < 0) break;
172
+ }
173
+ }
174
+ return { output, position };
175
+ }
176
+
177
+ // Blanks the template literal opening at text[position], keeping the code in
178
+ // its `${...}` expressions.
179
+ function scanTemplate(text, position) {
180
+ let output = " ";
181
+ position += 1;
182
+ while (position < text.length && text[position] !== "`") {
183
+ if (text[position] === "\\") {
184
+ output += blank(text.slice(position, position + 2));
185
+ position += 2;
186
+ } else if (text[position] === "$" && text[position + 1] === "{") {
187
+ const expression = scanCode(text, position + 2, true);
188
+ output += `\${${expression.output}`;
189
+ position = expression.position;
190
+ } else {
191
+ output += blank(text[position]);
192
+ position += 1;
193
+ }
194
+ }
195
+ if (position < text.length) {
196
+ output += " ";
197
+ position += 1;
198
+ }
199
+ return { output, position };
200
+ }
201
+
202
+ // Whether the identifier at text[start, end) sits where a shorthand property
203
+ // would (`{ LucideBell }`, `{ a, LucideBell = X }`), where renaming it also
204
+ // renames the key. Telling an object from JSX or a template expression needs a
205
+ // parser, so this only flags it; a JSX attribute (`icon={LucideBell}`) and a
206
+ // template expression (`${LucideBell}`) are left out. `text` has its strings
207
+ // and comments blanked (blankQuoted), so `{ /* icon */ LucideBell }` and
208
+ // `{ face: ":)", LucideBell }` still count.
209
+ function looksLikeShorthand(text, start, end) {
210
+ // A name inside a blanked string or comment isn't code.
211
+ if (text.slice(start, end).trim() === "") return false;
212
+ const before = text.slice(0, start).match(/([{,])\s*$/);
213
+ if (!before || !/^\s*(?:[},]|=(?![=>]))/.test(text.slice(end))) return false;
214
+ if (before[1] === ",") {
215
+ // Only inside braces: `[LucideBell, LucideHome]` and call arguments aren't objects.
216
+ let depth = 0;
217
+ for (let position = start - 1; position >= 0; position -= 1) {
218
+ const character = text[position];
219
+ if (character === ")" || character === "]" || character === "}") depth += 1;
220
+ else if (character === "(" || character === "[" || character === "{") {
221
+ if (depth === 0) return character === "{";
222
+ depth -= 1;
223
+ }
224
+ }
225
+ return false;
226
+ }
227
+ return !/(?:[\w$-]=|\$)$/.test(text.slice(0, start - before[0].length));
228
+ }
229
+
90
230
  /**
91
231
  * Rewrite one source file. Returns the new text, how many edits it made, and
92
232
  * warnings for anything left to migrate by hand.
@@ -137,6 +277,8 @@ export function migrateSource(text, { styles = false } = {}) {
137
277
  );
138
278
  }
139
279
  if (renames.size > 0) {
280
+ const shorthands = new Set();
281
+ const code = blankQuoted(output);
140
282
  // Rewritten import and export statements, quoted strings, and object or
141
283
  // destructuring keys (`{ LucideBell: x }`) stay as they are. A local
142
284
  // `export { LucideBell }` keeps its public name (`VadivamBell as
@@ -144,7 +286,7 @@ export function migrateSource(text, { styles = false } = {}) {
144
286
  // new name.
145
287
  output = output.replace(
146
288
  /\bimport\s+(?:type\s+)?(?:[\w$]+\s*,?\s*)?(?:\*\s+as\s+[\w$]+|\{[^}]*\})?\s*from\s*["'][^"']*["']|\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*["'][^"']*["']|\bexport\s*(?:type\s*)?\{([^}]*)\}|"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|(?<=[{,]\s*)[A-Za-z_$][\w$]*(?=\s*:(?!:))|(?<![\w$.])([A-Za-z_$][\w$]*)/g,
147
- (match, exportList, identifier) => {
289
+ (match, exportList, identifier, offset) => {
148
290
  if (exportList !== undefined) {
149
291
  return match.replace(exportList, (list) =>
150
292
  list.replace(/([\w$]+)(\s+as\s+[\w$]+)?/g, (entry, name, alias) => {
@@ -158,9 +300,14 @@ export function migrateSource(text, { styles = false } = {}) {
158
300
  const renamed = identifier && renames.get(identifier);
159
301
  if (!renamed) return match;
160
302
  changes += 1;
303
+ if (looksLikeShorthand(code, offset, offset + match.length)) {
304
+ const line = code.slice(0, offset).split("\n").length;
305
+ shorthands.add(`line ${line}: { ${match} } is now { ${renamed} }; if ${match} is an object key, write { ${match}: ${renamed} }`);
306
+ }
161
307
  return renamed;
162
308
  },
163
309
  );
310
+ warnings.push(...shorthands);
164
311
  }
165
312
  // A mock factory lists the module's export names, which this can't safely rewrite.
166
313
  if (/\.mock\s*\(\s*["']vadivam[^"']*["']\s*,/.test(output)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vadivam",
3
- "version": "0.0.81",
3
+ "version": "0.0.82",
4
4
  "description": "Pixel-perfect 24px outline and solid SVG icons with tree-shakeable ESM imports and metadata.",
5
5
  "license": "MIT",
6
6
  "author": "Praveen Juge",