@ms-cloudpack/path-string-parsing 1.1.1 → 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 +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/parseImportString.js +1 -1
- package/lib/parseImportString.js.map +1 -1
- package/lib/parseNamedImports.d.ts +7 -0
- package/lib/parseNamedImports.d.ts.map +1 -0
- package/lib/parseNamedImports.js +32 -0
- package/lib/parseNamedImports.js.map +1 -0
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +7 -2
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
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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
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"]}
|
package/lib/parseImportString.js
CHANGED
|
@@ -14,7 +14,7 @@ import { safeRelativePath } from './safeRelativePath.js';
|
|
|
14
14
|
export function parseImportString(importString = '') {
|
|
15
15
|
const matches = importString.match(
|
|
16
16
|
// 1: packageName 2: version 3: importPath
|
|
17
|
-
/^\/?((?:@[-\w
|
|
17
|
+
/^\/?((?:@[-\w.:]+\/)?[-\w.:]+)(?:@([-\w.]+))?(?:\/([-\w./]+))?/) || [];
|
|
18
18
|
return {
|
|
19
19
|
packageName: matches[1] || '.',
|
|
20
20
|
version: matches[2] || '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseImportString.js","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAazD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAY,GAAG,EAAE;IACjD,MAAM,OAAO,GACX,YAAY,CAAC,KAAK;IAChB,0DAA0D;IAC1D,
|
|
1
|
+
{"version":3,"file":"parseImportString.js","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAazD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAY,GAAG,EAAE;IACjD,MAAM,OAAO,GACX,YAAY,CAAC,KAAK;IAChB,0DAA0D;IAC1D,gEAAgE,CACjE,IAAI,EAAE,CAAC;IAEV,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG;QAC9B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACzB,UAAU,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import { safeRelativePath } from './safeRelativePath.js';\n\nexport type ImportStringResult = {\n packageName: string;\n /** Optional package version (default: empty string) */\n version: string;\n /**\n * Optional import path (default: `'.'`).\n * If this is set to a non-default value, it will be normalized to start with `./`.\n */\n importPath: string;\n};\n\n/**\n * Parse an import path: usually this will be a standard JS import, but this function also allows\n * an optional `@version` suffix after the package name.\n *\n * Examples of supported import strings:\n * - `foo`\n * - `foo@1.2.3`\n * - `foo@1.2.3/path/to/file`\n * - `@foo/bar`\n * - `@foo/bar@1.2.3`\n * - `@foo/bar@1.2.3/path/to/file`\n */\nexport function parseImportString(importString = ''): ImportStringResult {\n const matches =\n importString.match(\n // 1: packageName 2: version 3: importPath\n /^\\/?((?:@[-\\w.:]+\\/)?[-\\w.:]+)(?:@([-\\w.]+))?(?:\\/([-\\w./]+))?/,\n ) || [];\n\n return {\n packageName: matches[1] || '.',\n version: matches[2] || '',\n importPath: safeRelativePath(matches[3]),\n };\n}\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/lib/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/path-string-parsing",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "Common path-related string parsing utilities for Cloudpack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,5 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"lib/**/!(*.test.*)"
|
|
31
|
-
]
|
|
31
|
+
],
|
|
32
|
+
"beachball": {
|
|
33
|
+
"disallowedChangeTypes": [
|
|
34
|
+
"prerelease"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
32
37
|
}
|