@ms-cloudpack/path-string-parsing 1.2.7 → 1.3.1
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 +2 -0
- package/lib/addHashUrl.d.ts +33 -0
- package/lib/addHashUrl.d.ts.map +1 -0
- package/lib/addHashUrl.js +35 -0
- package/lib/addHashUrl.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/removeHashFromUrl.d.ts +32 -0
- package/lib/removeHashFromUrl.d.ts.map +1 -0
- package/lib/removeHashFromUrl.js +45 -0
- package/lib/removeHashFromUrl.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds hash after name and version in a URL.
|
|
3
|
+
* If hash already exists, replaces it.
|
|
4
|
+
*
|
|
5
|
+
* @param params - Parameters for adding hash to URL
|
|
6
|
+
* @param params.url - URL to add hash to
|
|
7
|
+
* @param params.packageName - Package name
|
|
8
|
+
* @param params.version - Package version
|
|
9
|
+
* @param params.hash - Hash to add
|
|
10
|
+
* @returns URL with hash added or replaced
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* addHashUrl({
|
|
15
|
+
* url: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js',
|
|
16
|
+
* packageName: 'react',
|
|
17
|
+
* version: '17.5.0',
|
|
18
|
+
* hash: 'abc123'
|
|
19
|
+
* });
|
|
20
|
+
* // Returns: 'http://localhost:3000/react@17.5.0/h-abc123/v0/bundled/index.js'
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function addHashUrl(params: {
|
|
24
|
+
/** URL to add hash to */
|
|
25
|
+
url: string;
|
|
26
|
+
/** Package name */
|
|
27
|
+
packageName: string;
|
|
28
|
+
/** Package version */
|
|
29
|
+
version: string;
|
|
30
|
+
/** Hash to add */
|
|
31
|
+
hash: string;
|
|
32
|
+
}): string;
|
|
33
|
+
//# sourceMappingURL=addHashUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHashUrl.d.ts","sourceRoot":"","sources":["../src/addHashUrl.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,yBAAyB;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,mBAAmB;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,MAAM,CAUT"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { removeHashFromUrl } from './removeHashFromUrl.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adds hash after name and version in a URL.
|
|
4
|
+
* If hash already exists, replaces it.
|
|
5
|
+
*
|
|
6
|
+
* @param params - Parameters for adding hash to URL
|
|
7
|
+
* @param params.url - URL to add hash to
|
|
8
|
+
* @param params.packageName - Package name
|
|
9
|
+
* @param params.version - Package version
|
|
10
|
+
* @param params.hash - Hash to add
|
|
11
|
+
* @returns URL with hash added or replaced
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* addHashUrl({
|
|
16
|
+
* url: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js',
|
|
17
|
+
* packageName: 'react',
|
|
18
|
+
* version: '17.5.0',
|
|
19
|
+
* hash: 'abc123'
|
|
20
|
+
* });
|
|
21
|
+
* // Returns: 'http://localhost:3000/react@17.5.0/h-abc123/v0/bundled/index.js'
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function addHashUrl(params) {
|
|
25
|
+
const { url, packageName, version, hash } = params;
|
|
26
|
+
const packageId = `${packageName}@${version}`;
|
|
27
|
+
const packageUrlIndex = url.indexOf(packageId);
|
|
28
|
+
if (packageUrlIndex !== -1) {
|
|
29
|
+
const hashIndex = packageUrlIndex + packageId.length;
|
|
30
|
+
const urlWithoutHash = removeHashFromUrl(url);
|
|
31
|
+
return urlWithoutHash.slice(0, hashIndex) + `/h-${hash}` + urlWithoutHash.slice(hashIndex);
|
|
32
|
+
}
|
|
33
|
+
return url;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=addHashUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addHashUrl.js","sourceRoot":"","sources":["../src/addHashUrl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,UAAU,CAAC,MAS1B;IACC,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IACnD,MAAM,SAAS,GAAG,GAAG,WAAW,IAAI,OAAO,EAAE,CAAC;IAC9C,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,eAAe,KAAK,CAAC,CAAC,EAAE,CAAC;QAC3B,MAAM,SAAS,GAAG,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC;QACrD,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAC9C,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { removeHashFromUrl } from './removeHashFromUrl.js';\n\n/**\n * Adds hash after name and version in a URL.\n * If hash already exists, replaces it.\n *\n * @param params - Parameters for adding hash to URL\n * @param params.url - URL to add hash to\n * @param params.packageName - Package name\n * @param params.version - Package version\n * @param params.hash - Hash to add\n * @returns URL with hash added or replaced\n *\n * @example\n * ```ts\n * addHashUrl({\n * url: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js',\n * packageName: 'react',\n * version: '17.5.0',\n * hash: 'abc123'\n * });\n * // Returns: 'http://localhost:3000/react@17.5.0/h-abc123/v0/bundled/index.js'\n * ```\n */\nexport function addHashUrl(params: {\n /** URL to add hash to */\n url: string;\n /** Package name */\n packageName: string;\n /** Package version */\n version: string;\n /** Hash to add */\n hash: string;\n}): string {\n const { url, packageName, version, hash } = params;\n const packageId = `${packageName}@${version}`;\n const packageUrlIndex = url.indexOf(packageId);\n if (packageUrlIndex !== -1) {\n const hashIndex = packageUrlIndex + packageId.length;\n const urlWithoutHash = removeHashFromUrl(url);\n return urlWithoutHash.slice(0, hashIndex) + `/h-${hash}` + urlWithoutHash.slice(hashIndex);\n }\n return url;\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,6 @@ export { slash } from './slash.js';
|
|
|
4
4
|
export { parseImportString, type ImportStringResult } from './parseImportString.js';
|
|
5
5
|
export { parseNamedImports } from './parseNamedImports.js';
|
|
6
6
|
export { makeUrl } from './makeUrl.js';
|
|
7
|
+
export { addHashUrl } from './addHashUrl.js';
|
|
8
|
+
export { removeHashFromUrl } from './removeHashFromUrl.js';
|
|
7
9
|
//# 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,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,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;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,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,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,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;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export { slash } from './slash.js';
|
|
|
4
4
|
export { parseImportString } from './parseImportString.js';
|
|
5
5
|
export { parseNamedImports } from './parseNamedImports.js';
|
|
6
6
|
export { makeUrl } from './makeUrl.js';
|
|
7
|
+
export { addHashUrl } from './addHashUrl.js';
|
|
8
|
+
export { removeHashFromUrl } from './removeHashFromUrl.js';
|
|
7
9
|
//# 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,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC","sourcesContent":["export { safeRelativePath } from './safeRelativePath.js';\nexport { normalizeRelativePath } from './normalizeRelativePath.js';\nexport { slash } from './slash.js';\nexport { parseImportString, type ImportStringResult } from './parseImportString.js';\nexport { parseNamedImports } from './parseNamedImports.js';\nexport { makeUrl } from './makeUrl.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,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC","sourcesContent":["export { safeRelativePath } from './safeRelativePath.js';\nexport { normalizeRelativePath } from './normalizeRelativePath.js';\nexport { slash } from './slash.js';\nexport { parseImportString, type ImportStringResult } from './parseImportString.js';\nexport { parseNamedImports } from './parseNamedImports.js';\nexport { makeUrl } from './makeUrl.js';\nexport { addHashUrl } from './addHashUrl.js';\nexport { removeHashFromUrl } from './removeHashFromUrl.js';\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes hash segment from URL for comparison purposes.
|
|
3
|
+
*
|
|
4
|
+
* This function normalizes URLs by removing the hash segment (e.g., `/h-abc123/`)
|
|
5
|
+
* that appears after the package name and version. This is useful for comparing
|
|
6
|
+
* URLs that point to the same resource but with different hash values.
|
|
7
|
+
*
|
|
8
|
+
* The hash segment is used for cache-busting and content versioning. By removing it,
|
|
9
|
+
* we can check if two URLs refer to the same logical resource regardless of their
|
|
10
|
+
* specific hash values.
|
|
11
|
+
*
|
|
12
|
+
* @param url - URL to remove hash from
|
|
13
|
+
* @returns URL with hash segment removed, or original URL if no hash segment is found
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Remove hash from a URL
|
|
18
|
+
* removeHashFromUrl('http://localhost:3000/react@17.5.0/h-abc123/v0/bundled/index.js');
|
|
19
|
+
* // Returns: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js'
|
|
20
|
+
*
|
|
21
|
+
* // URL without hash is returned unchanged
|
|
22
|
+
* removeHashFromUrl('http://localhost:3000/react@17.5.0/v0/bundled/index.js');
|
|
23
|
+
* // Returns: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js'
|
|
24
|
+
*
|
|
25
|
+
* // Compare URLs with different hashes
|
|
26
|
+
* const url1 = 'http://localhost:3000/pkg@1.0.0/h-old/bundled/index.js';
|
|
27
|
+
* const url2 = 'http://localhost:3000/pkg@1.0.0/h-new/bundled/index.js';
|
|
28
|
+
* removeHashFromUrl(url1) === removeHashFromUrl(url2); // true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function removeHashFromUrl(url: string): string;
|
|
32
|
+
//# sourceMappingURL=removeHashFromUrl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeHashFromUrl.d.ts","sourceRoot":"","sources":["../src/removeHashFromUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAerD"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes hash segment from URL for comparison purposes.
|
|
3
|
+
*
|
|
4
|
+
* This function normalizes URLs by removing the hash segment (e.g., `/h-abc123/`)
|
|
5
|
+
* that appears after the package name and version. This is useful for comparing
|
|
6
|
+
* URLs that point to the same resource but with different hash values.
|
|
7
|
+
*
|
|
8
|
+
* The hash segment is used for cache-busting and content versioning. By removing it,
|
|
9
|
+
* we can check if two URLs refer to the same logical resource regardless of their
|
|
10
|
+
* specific hash values.
|
|
11
|
+
*
|
|
12
|
+
* @param url - URL to remove hash from
|
|
13
|
+
* @returns URL with hash segment removed, or original URL if no hash segment is found
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Remove hash from a URL
|
|
18
|
+
* removeHashFromUrl('http://localhost:3000/react@17.5.0/h-abc123/v0/bundled/index.js');
|
|
19
|
+
* // Returns: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js'
|
|
20
|
+
*
|
|
21
|
+
* // URL without hash is returned unchanged
|
|
22
|
+
* removeHashFromUrl('http://localhost:3000/react@17.5.0/v0/bundled/index.js');
|
|
23
|
+
* // Returns: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js'
|
|
24
|
+
*
|
|
25
|
+
* // Compare URLs with different hashes
|
|
26
|
+
* const url1 = 'http://localhost:3000/pkg@1.0.0/h-old/bundled/index.js';
|
|
27
|
+
* const url2 = 'http://localhost:3000/pkg@1.0.0/h-new/bundled/index.js';
|
|
28
|
+
* removeHashFromUrl(url1) === removeHashFromUrl(url2); // true
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function removeHashFromUrl(url) {
|
|
32
|
+
// Find the start of the hash segment (e.g., '/h-abc123/')
|
|
33
|
+
const hashStart = url.indexOf('/h-');
|
|
34
|
+
if (hashStart === -1) {
|
|
35
|
+
return url;
|
|
36
|
+
}
|
|
37
|
+
// Find the end of the hash segment (the next '/' after '/h-')
|
|
38
|
+
const hashEnd = url.indexOf('/', hashStart + 1);
|
|
39
|
+
if (hashEnd === -1) {
|
|
40
|
+
return url;
|
|
41
|
+
}
|
|
42
|
+
// Remove the hash segment by concatenating everything before and after it
|
|
43
|
+
return url.slice(0, hashStart) + url.slice(hashEnd);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=removeHashFromUrl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeHashFromUrl.js","sourceRoot":"","sources":["../src/removeHashFromUrl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,0DAA0D;IAC1D,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;QACrB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,8DAA8D;IAC9D,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;IAChD,IAAI,OAAO,KAAK,CAAC,CAAC,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC;IACb,CAAC;IAED,0EAA0E;IAC1E,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/**\n * Removes hash segment from URL for comparison purposes.\n *\n * This function normalizes URLs by removing the hash segment (e.g., `/h-abc123/`)\n * that appears after the package name and version. This is useful for comparing\n * URLs that point to the same resource but with different hash values.\n *\n * The hash segment is used for cache-busting and content versioning. By removing it,\n * we can check if two URLs refer to the same logical resource regardless of their\n * specific hash values.\n *\n * @param url - URL to remove hash from\n * @returns URL with hash segment removed, or original URL if no hash segment is found\n *\n * @example\n * ```ts\n * // Remove hash from a URL\n * removeHashFromUrl('http://localhost:3000/react@17.5.0/h-abc123/v0/bundled/index.js');\n * // Returns: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js'\n *\n * // URL without hash is returned unchanged\n * removeHashFromUrl('http://localhost:3000/react@17.5.0/v0/bundled/index.js');\n * // Returns: 'http://localhost:3000/react@17.5.0/v0/bundled/index.js'\n *\n * // Compare URLs with different hashes\n * const url1 = 'http://localhost:3000/pkg@1.0.0/h-old/bundled/index.js';\n * const url2 = 'http://localhost:3000/pkg@1.0.0/h-new/bundled/index.js';\n * removeHashFromUrl(url1) === removeHashFromUrl(url2); // true\n * ```\n */\nexport function removeHashFromUrl(url: string): string {\n // Find the start of the hash segment (e.g., '/h-abc123/')\n const hashStart = url.indexOf('/h-');\n if (hashStart === -1) {\n return url;\n }\n\n // Find the end of the hash segment (the next '/' after '/h-')\n const hashEnd = url.indexOf('/', hashStart + 1);\n if (hashEnd === -1) {\n return url;\n }\n\n // Remove the hash segment by concatenating everything before and after it\n return url.slice(0, hashStart) + url.slice(hashEnd);\n}\n"]}
|