@ms-cloudpack/path-string-parsing 1.0.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/CHANGELOG.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@ms-cloudpack/path-string-parsing",
3
+ "entries": [
4
+ {
5
+ "date": "Sat, 15 Oct 2022 08:11:07 GMT",
6
+ "tag": "@ms-cloudpack/path-string-parsing_v1.0.0",
7
+ "version": "1.0.0",
8
+ "comments": {
9
+ "major": [
10
+ {
11
+ "author": "dake.3601@gmail.com",
12
+ "package": "@ms-cloudpack/path-string-parsing",
13
+ "commit": "962ebd9eb867b159565e221c9f5e800a8eb0ec84",
14
+ "comment": "Environment agnostic package with slash, parseImportString, and safeRelativePath."
15
+ }
16
+ ]
17
+ }
18
+ }
19
+ ]
20
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Change Log - @ms-cloudpack/path-string-parsing
2
+
3
+ This log was last generated on Sat, 15 Oct 2022 08:11:07 GMT and should not be manually modified.
4
+
5
+ <!-- Start content -->
6
+
7
+ ## 1.0.0
8
+
9
+ Sat, 15 Oct 2022 08:11:07 GMT
10
+
11
+ ### Major changes
12
+
13
+ - Environment agnostic package with slash, parseImportString, and safeRelativePath. (dake.3601@gmail.com)
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { safeRelativePath } from './safeRelativePath.js';
2
+ export { slash } from './slash.js';
3
+ export { parseImportString, type ImportStringResult } from './parseImportString.js';
package/lib/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { safeRelativePath } from './safeRelativePath.js';
2
+ export { slash } from './slash.js';
3
+ export { parseImportString } from './parseImportString.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,6 @@
1
+ export declare type ImportStringResult = {
2
+ packageName: string | undefined;
3
+ version: string | undefined;
4
+ importPath: string | undefined;
5
+ };
6
+ export declare function parseImportString(importString?: string): ImportStringResult;
@@ -0,0 +1,10 @@
1
+ import { safeRelativePath } from './safeRelativePath.js';
2
+ 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.]+))?/) || [];
4
+ return {
5
+ packageName: matches[1] || '.',
6
+ version: matches[3] || '',
7
+ importPath: safeRelativePath(matches[5]),
8
+ };
9
+ }
10
+ //# sourceMappingURL=parseImportString.js.map
@@ -0,0 +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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from '@jest/globals';
2
+ import { parseImportString } from './parseImportString.js';
3
+ describe(`parseImportString`, () => {
4
+ it(`can parse a package import`, () => {
5
+ expect(parseImportString('package')).toEqual({ packageName: 'package', version: '', importPath: '.' });
6
+ });
7
+ it(`can parse a package import with a scope`, () => {
8
+ expect(parseImportString('@scope/package')).toEqual({
9
+ packageName: '@scope/package',
10
+ version: '',
11
+ importPath: '.',
12
+ });
13
+ });
14
+ it(`can parse a package import with a scope and path`, () => {
15
+ expect(parseImportString('@scope/package/path/to/thing')).toEqual({
16
+ packageName: '@scope/package',
17
+ version: '',
18
+ importPath: './path/to/thing',
19
+ });
20
+ });
21
+ it(`can parse a package import with a scope, version, and path`, () => {
22
+ expect(parseImportString('@scope/package@1234567890.1234567890.1234567890-abcdeABCDE/path/to/thing')).toEqual({
23
+ packageName: '@scope/package',
24
+ version: '1234567890.1234567890.1234567890-abcdeABCDE',
25
+ importPath: './path/to/thing',
26
+ });
27
+ });
28
+ it(`can handle package names with underscores`, () => {
29
+ expect(parseImportString('package_name')).toEqual({
30
+ packageName: 'package_name',
31
+ version: '',
32
+ importPath: '.',
33
+ });
34
+ });
35
+ it(`can handle package names with dashes`, () => {
36
+ expect(parseImportString('package-name')).toEqual({
37
+ packageName: 'package-name',
38
+ version: '',
39
+ importPath: '.',
40
+ });
41
+ });
42
+ });
43
+ //# sourceMappingURL=parseImportString.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseImportString.test.js","sourceRoot":"","sources":["../src/parseImportString.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;IACzG,CAAC,CAAC,C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ative path starts with a ./
3
+ */
4
+ export declare function safeRelativePath(originalPath: string | undefined): string;
@@ -0,0 +1,19 @@
1
+ import { slash } from './slash.js';
2
+ /**
3
+ * Ensures the give relative path starts with a ./
4
+ */
5
+ export function safeRelativePath(originalPath) {
6
+ if (!originalPath || originalPath.length === 0 || originalPath === '.') {
7
+ return '.';
8
+ }
9
+ // Ensure we have the right slashes.
10
+ originalPath = slash(originalPath);
11
+ if (originalPath.startsWith('/')) {
12
+ return '.' + originalPath;
13
+ }
14
+ else if (originalPath.startsWith('./')) {
15
+ return originalPath;
16
+ }
17
+ return `./${originalPath}`;
18
+ }
19
+ //# sourceMappingURL=safeRelativePath.js.map
@@ -0,0 +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"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { describe, it, expect } from '@jest/globals';
2
+ import { safeRelativePath } from './safeRelativePath.js';
3
+ describe('safeRelativePath', () => {
4
+ it('can handle default import paths', () => {
5
+ expect(safeRelativePath(undefined)).toEqual('.');
6
+ expect(safeRelativePath('')).toEqual('.');
7
+ expect(safeRelativePath('.')).toEqual('.');
8
+ });
9
+ it('can handle an absolute path', () => {
10
+ expect(safeRelativePath('/foo/bar')).toEqual('./foo/bar');
11
+ });
12
+ it('can handle a relative path', () => {
13
+ expect(safeRelativePath('./foo/bar')).toEqual('./foo/bar');
14
+ });
15
+ it('can handle a relative path without a leading slash', () => {
16
+ expect(safeRelativePath('foo/bar')).toEqual('./foo/bar');
17
+ });
18
+ });
19
+ //# sourceMappingURL=safeRelativePath.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safeRelativePath.test.js","sourceRoot":"","sources":["../src/safeRelativePath.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,iCAAiC,EAAE,GAAG,EAAE;QACzC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,MAAM,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4BAA4B,EAAE,GAAG,EAAE;QACpC,MAAM,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/lib/slash.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function slash(str: string): string;
package/lib/slash.js ADDED
@@ -0,0 +1,4 @@
1
+ export function slash(str) {
2
+ return str.replace(/\\/g, '/');
3
+ }
4
+ //# sourceMappingURL=slash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash.js","sourceRoot":"","sources":["../src/slash.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import { describe, it, expect } from '@jest/globals';
2
+ import { slash } from './slash.js';
3
+ describe('slash', () => {
4
+ it('can reverse slashes', () => {
5
+ expect(slash('\\asdf\\asdf/asdf')).toEqual('/asdf/asdf/asdf');
6
+ });
7
+ });
8
+ //# sourceMappingURL=slash.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slash.test.js","sourceRoot":"","sources":["../src/slash.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;QAC7B,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.33.1"
9
+ }
10
+ ]
11
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@ms-cloudpack/path-string-parsing",
3
+ "version": "1.0.0",
4
+ "description": "Common string parsing of path utilities for the Cloudpack repo.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "types": "./lib/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "import": "./lib/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "api:update": "cloudpack-scripts api-update",
17
+ "api": "cloudpack-scripts api",
18
+ "build:watch": "cloudpack-scripts build-watch",
19
+ "build": "cloudpack-scripts build",
20
+ "lint:update": "cloudpack-scripts lint-update",
21
+ "lint": "cloudpack-scripts lint",
22
+ "test:update": "cloudpack-scripts test-update",
23
+ "test:watch": "cloudpack-scripts test-watch",
24
+ "test": "cloudpack-scripts test"
25
+ },
26
+ "devDependencies": {
27
+ "@ms-cloudpack/eslint-config-base": "*"
28
+ },
29
+ "files": [
30
+ "/lib"
31
+ ]
32
+ }