@ms-cloudpack/path-string-parsing 1.0.2 → 1.1.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.
@@ -1,7 +1,24 @@
1
1
  export type ImportStringResult = {
2
- packageName: string | undefined;
3
- version: string | undefined;
4
- importPath: string | undefined;
2
+ packageName: string;
3
+ /** Optional package version (default: empty string) */
4
+ version: string;
5
+ /**
6
+ * Optional import path (default: `'.'`).
7
+ * If this is set to a non-default value, it will be normalized to start with `./`.
8
+ */
9
+ importPath: string;
5
10
  };
11
+ /**
12
+ * Parse an import path: usually this will be a standard JS import, but this function also allows
13
+ * an optional `@version` suffix after the package name.
14
+ *
15
+ * Examples of supported import strings:
16
+ * - `foo`
17
+ * - `foo@1.2.3`
18
+ * - `foo@1.2.3/path/to/file`
19
+ * - `@foo/bar`
20
+ * - `@foo/bar@1.2.3`
21
+ * - `@foo/bar@1.2.3/path/to/file`
22
+ */
6
23
  export declare function parseImportString(importString?: string): ImportStringResult;
7
24
  //# sourceMappingURL=parseImportString.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseImportString.d.ts","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,YAAY,SAAK,GAAG,kBAAkB,CAWvE"}
1
+ {"version":3,"file":"parseImportString.d.ts","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,SAAK,GAAG,kBAAkB,CAYvE"}
@@ -1,10 +1,24 @@
1
1
  import { safeRelativePath } from './safeRelativePath.js';
2
+ /**
3
+ * Parse an import path: usually this will be a standard JS import, but this function also allows
4
+ * an optional `@version` suffix after the package name.
5
+ *
6
+ * Examples of supported import strings:
7
+ * - `foo`
8
+ * - `foo@1.2.3`
9
+ * - `foo@1.2.3/path/to/file`
10
+ * - `@foo/bar`
11
+ * - `@foo/bar@1.2.3`
12
+ * - `@foo/bar@1.2.3/path/to/file`
13
+ */
2
14
  export function parseImportString(importString = '') {
3
- const matches = importString.match(/[/]?(@[-_a-z-A-Z0-9.]+\/[-_a-z-A-Z0-9.]+|[-_a-zA-Z0-9.]+)(@([-_a-zA-Z-0-9.]+))?(\/([-_/a-zA-Z0-9.]+))?/) || [];
15
+ const matches = importString.match(
16
+ // 1: packageName 2: version 3: importPath
17
+ /^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/([-\w./]+))?/) || [];
4
18
  return {
5
19
  packageName: matches[1] || '.',
6
- version: matches[3] || '',
7
- importPath: safeRelativePath(matches[5]),
20
+ version: matches[2] || '',
21
+ importPath: safeRelativePath(matches[3]),
8
22
  };
9
23
  }
10
24
  //# sourceMappingURL=parseImportString.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseImportString.js","sourceRoot":"","sources":["../src/parseImportString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAQzD,MAAM,UAAU,iBAAiB,CAAC,YAAY,GAAG,EAAE;IACjD,MAAM,OAAO,GACX,YAAY,CAAC,KAAK,CAChB,wGAAwG,CACzG,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 | undefined;\n version: string | undefined;\n importPath: string | undefined;\n};\n\nexport function parseImportString(importString = ''): ImportStringResult {\n const matches =\n importString.match(\n /[/]?(@[-_a-z-A-Z0-9.]+\\/[-_a-z-A-Z0-9.]+|[-_a-zA-Z0-9.]+)(@([-_a-zA-Z-0-9.]+))?(\\/([-_/a-zA-Z0-9.]+))?/,\n ) || [];\n\n return {\n packageName: matches[1] || '.',\n version: matches[3] || '',\n importPath: safeRelativePath(matches[5]),\n };\n}\n"]}
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,8DAA8D,CAC/D,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"]}
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Ensures the give relative path starts with a ./
2
+ * If the given relative path is non-empty, ensure it starts with `./`.
3
+ * Returns `.` if the given path is empty or undefined (or already `.`).
3
4
  */
4
5
  export declare function safeRelativePath(originalPath: string | undefined): string;
5
6
  //# sourceMappingURL=safeRelativePath.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"safeRelativePath.d.ts","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAezE"}
1
+ {"version":3,"file":"safeRelativePath.d.ts","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAezE"}
@@ -1,9 +1,10 @@
1
1
  import { slash } from './slash.js';
2
2
  /**
3
- * Ensures the give relative path starts with a ./
3
+ * If the given relative path is non-empty, ensure it starts with `./`.
4
+ * Returns `.` if the given path is empty or undefined (or already `.`).
4
5
  */
5
6
  export function safeRelativePath(originalPath) {
6
- if (!originalPath || originalPath.length === 0 || originalPath === '.') {
7
+ if (!originalPath || originalPath === '.') {
7
8
  return '.';
8
9
  }
9
10
  // Ensure we have the right slashes.
@@ -1 +1 @@
1
- {"version":3,"file":"safeRelativePath.js","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAgC;IAC/D,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY,KAAK,GAAG,EAAE;QACtE,OAAO,GAAG,CAAC;KACZ;IAED,oCAAoC;IACpC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IAEnC,IAAI,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAChC,OAAO,GAAG,GAAG,YAAY,CAAC;KAC3B;SAAM,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACxC,OAAO,YAAY,CAAC;KACrB;IAED,OAAO,KAAK,YAAY,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import { slash } from './slash.js';\n\n/**\n * Ensures the give relative path starts with a ./\n */\nexport function safeRelativePath(originalPath: string | undefined): string {\n if (!originalPath || originalPath.length === 0 || originalPath === '.') {\n return '.';\n }\n\n // Ensure we have the right slashes.\n originalPath = slash(originalPath);\n\n if (originalPath.startsWith('/')) {\n return '.' + originalPath;\n } else if (originalPath.startsWith('./')) {\n return originalPath;\n }\n\n return `./${originalPath}`;\n}\n"]}
1
+ {"version":3,"file":"safeRelativePath.js","sourceRoot":"","sources":["../src/safeRelativePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAgC;IAC/D,IAAI,CAAC,YAAY,IAAI,YAAY,KAAK,GAAG,EAAE;QACzC,OAAO,GAAG,CAAC;KACZ;IAED,oCAAoC;IACpC,YAAY,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC;IAEnC,IAAI,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAChC,OAAO,GAAG,GAAG,YAAY,CAAC;KAC3B;SAAM,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACxC,OAAO,YAAY,CAAC;KACrB;IAED,OAAO,KAAK,YAAY,EAAE,CAAC;AAC7B,CAAC","sourcesContent":["import { slash } from './slash.js';\n\n/**\n * If the given relative path is non-empty, ensure it starts with `./`.\n * Returns `.` if the given path is empty or undefined (or already `.`).\n */\nexport function safeRelativePath(originalPath: string | undefined): string {\n if (!originalPath || originalPath === '.') {\n return '.';\n }\n\n // Ensure we have the right slashes.\n originalPath = slash(originalPath);\n\n if (originalPath.startsWith('/')) {\n return '.' + originalPath;\n } else if (originalPath.startsWith('./')) {\n return originalPath;\n }\n\n return `./${originalPath}`;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.35.2"
8
+ "packageVersion": "7.36.4"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/path-string-parsing",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Common path-related string parsing utilities for Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",