@ms-cloudpack/path-string-parsing 1.1.2 → 1.1.3

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/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { safeRelativePath } from './safeRelativePath.js';
2
2
  export { slash } from './slash.js';
3
3
  export { parseImportString, type ImportStringResult } from './parseImportString.js';
4
+ export { parseNamedImports } from './parseNamedImports.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
package/lib/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { safeRelativePath } from './safeRelativePath.js';
2
2
  export { slash } from './slash.js';
3
3
  export { parseImportString } from './parseImportString.js';
4
+ export { parseNamedImports } from './parseNamedImports.js';
4
5
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC","sourcesContent":["export { safeRelativePath } from './safeRelativePath.js';\nexport { slash } from './slash.js';\nexport { parseImportString, type ImportStringResult } from './parseImportString.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { safeRelativePath } from './safeRelativePath.js';\nexport { slash } from './slash.js';\nexport { parseImportString, type ImportStringResult } from './parseImportString.js';\nexport { parseNamedImports } from './parseNamedImports.js';\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Parses an import string into its component parts.
3
+ * @param importLine - The import string to parse.
4
+ * @returns A string array with the named imports, default and/or '*'.
5
+ */
6
+ export declare function parseNamedImports(importLine: string): string[];
7
+ //# sourceMappingURL=parseNamedImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseNamedImports.d.ts","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CA6B9D"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Parses an import string into its component parts.
3
+ * @param importLine - The import string to parse.
4
+ * @returns A string array with the named imports, default and/or '*'.
5
+ */
6
+ export function parseNamedImports(importLine) {
7
+ // Regex from: https://github.com/antonkc/MOR/blob/main/matchJsImports.md
8
+ // With some edits to catch exports * from "package".
9
+ const matches = importLine.match(/(?<=(?:[\s\n;])|^)(?:(?:import|export)[\s\n]*((?:(?<=[\s\n])type)?)(?=[\n\s*{])[\s\n]*)((?:(?:[_$\w][_$\w0-9]*)(?:[\s\n]+(?:as[\s\n]+(?:[_$\w][_$\w0-9]*)))?(?=(?:[\n\s]*,[\n\s]*[{*])|(?:[\n\s]+from)))?)[\s\n,]*((?:\*[\n\s]*(?:as[\s\n]+(?:[_$\w][_$\w0-9]*))(?=[\n\s]+from))?|\*)[\s\n,]*((?:\{[n\s]*(?:(?:[_$\w][_$\w0-9]*)(?:[\s\n]+(?:as[\s\n]+(?:[_$\w][_$\w0-9]*)))?[\s\n]*,?[\s\n]*)*\}(?=[\n\s]*from))?)(?:[\s\n]*((?:from)?))[\s\n]*(?:["']([^"']*)(["']))[\s\n]*?;?/);
10
+ const names = [];
11
+ // If no matches return empty array
12
+ if (matches === null) {
13
+ return names;
14
+ }
15
+ // If there is a default export, push it to the names array
16
+ if (matches[2]) {
17
+ names.push('default');
18
+ }
19
+ // If there is a namespace export, push it to the names array
20
+ if (matches[4]) {
21
+ // Clean out the braces, whitespace, and get alias
22
+ const namedImports = matches[4].matchAll(/([\w$]+)(?:\s+as\s+[\w$]+(?:,)?)?/g);
23
+ for (const namedImport of namedImports) {
24
+ names.push(namedImport[1]);
25
+ }
26
+ }
27
+ if (matches[3]) {
28
+ names.push('*');
29
+ }
30
+ return names;
31
+ }
32
+ //# sourceMappingURL=parseNamedImports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseNamedImports.js","sourceRoot":"","sources":["../src/parseNamedImports.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAkB;IAClD,yEAAyE;IACzE,qDAAqD;IACrD,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAC9B,kdAAkd,CACnd,CAAC;IACF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,mCAAmC;IACnC,IAAI,OAAO,KAAK,IAAI,EAAE;QACpB,OAAO,KAAK,CAAC;KACd;IACD,2DAA2D;IAC3D,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;QACd,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;KACvB;IACD,6DAA6D;IAC7D,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;QACd,kDAAkD;QAClD,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,oCAAoC,CAAC,CAAC;QAC/E,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE;YACtC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5B;KACF;IAED,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE;QACd,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KACjB;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["/**\n * Parses an import string into its component parts.\n * @param importLine - The import string to parse.\n * @returns A string array with the named imports, default and/or '*'.\n */\nexport function parseNamedImports(importLine: string): string[] {\n // Regex from: https://github.com/antonkc/MOR/blob/main/matchJsImports.md\n // With some edits to catch exports * from \"package\".\n const matches = importLine.match(\n /(?<=(?:[\\s\\n;])|^)(?:(?:import|export)[\\s\\n]*((?:(?<=[\\s\\n])type)?)(?=[\\n\\s*{])[\\s\\n]*)((?:(?:[_$\\w][_$\\w0-9]*)(?:[\\s\\n]+(?:as[\\s\\n]+(?:[_$\\w][_$\\w0-9]*)))?(?=(?:[\\n\\s]*,[\\n\\s]*[{*])|(?:[\\n\\s]+from)))?)[\\s\\n,]*((?:\\*[\\n\\s]*(?:as[\\s\\n]+(?:[_$\\w][_$\\w0-9]*))(?=[\\n\\s]+from))?|\\*)[\\s\\n,]*((?:\\{[n\\s]*(?:(?:[_$\\w][_$\\w0-9]*)(?:[\\s\\n]+(?:as[\\s\\n]+(?:[_$\\w][_$\\w0-9]*)))?[\\s\\n]*,?[\\s\\n]*)*\\}(?=[\\n\\s]*from))?)(?:[\\s\\n]*((?:from)?))[\\s\\n]*(?:[\"']([^\"']*)([\"']))[\\s\\n]*?;?/,\n );\n const names: string[] = [];\n // If no matches return empty array\n if (matches === null) {\n return names;\n }\n // If there is a default export, push it to the names array\n if (matches[2]) {\n names.push('default');\n }\n // If there is a namespace export, push it to the names array\n if (matches[4]) {\n // Clean out the braces, whitespace, and get alias\n const namedImports = matches[4].matchAll(/([\\w$]+)(?:\\s+as\\s+[\\w$]+(?:,)?)?/g);\n for (const namedImport of namedImports) {\n names.push(namedImport[1]);\n }\n }\n\n if (matches[3]) {\n names.push('*');\n }\n\n return names;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/path-string-parsing",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Common path-related string parsing utilities for Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",