@jsenv/urls 2.6.0 → 2.6.2
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/package.json +3 -3
- package/src/internal/pathname_to_extension.js +15 -0
- package/src/main.js +5 -0
- package/src/resource_to_parts.js +47 -0
- package/src/url_to_extension.js +1 -13
- package/src/url_to_pathname.js +1 -12
- package/src/url_utils.js +1 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/urls",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/jsenv/core",
|
|
8
|
-
"directory": "packages/independent/urls"
|
|
8
|
+
"directory": "packages/independent/shared/urls"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"access": "public"
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
],
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@jsenv/humanize": "1.
|
|
29
|
+
"@jsenv/humanize": "1.3.1"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const pathnameToExtension = (pathname) => {
|
|
2
|
+
const slashLastIndex = pathname.lastIndexOf("/");
|
|
3
|
+
const filename =
|
|
4
|
+
slashLastIndex === -1 ? pathname : pathname.slice(slashLastIndex + 1);
|
|
5
|
+
if (filename.match(/@([0-9])+(\.[0-9]+)?(\.[0-9]+)?$/)) {
|
|
6
|
+
return "";
|
|
7
|
+
}
|
|
8
|
+
const dotLastIndex = filename.lastIndexOf(".");
|
|
9
|
+
if (dotLastIndex === -1) {
|
|
10
|
+
return "";
|
|
11
|
+
}
|
|
12
|
+
// if (dotLastIndex === pathname.length - 1) return ""
|
|
13
|
+
const extension = filename.slice(dotLastIndex);
|
|
14
|
+
return extension;
|
|
15
|
+
};
|
package/src/main.js
CHANGED
|
@@ -44,5 +44,10 @@ export { urlToResource } from "./url_to_resource.js";
|
|
|
44
44
|
export { urlToScheme } from "./url_to_scheme.js";
|
|
45
45
|
|
|
46
46
|
export { getCommonPathname } from "./common_pathname.js";
|
|
47
|
+
export {
|
|
48
|
+
resourceToParts,
|
|
49
|
+
resourceToPathname,
|
|
50
|
+
resourceToExtension,
|
|
51
|
+
} from "./resource_to_parts.js";
|
|
47
52
|
|
|
48
53
|
export { yieldAncestorUrls } from "./yield_ancestor_urls.js";
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { pathnameToExtension } from "./internal/pathname_to_extension.js";
|
|
2
|
+
|
|
3
|
+
export const resourceToParts = (resource) => {
|
|
4
|
+
const searchSeparatorIndex = resource.indexOf("?");
|
|
5
|
+
if (searchSeparatorIndex === -1) {
|
|
6
|
+
const hashSeparatorIndex = resource.indexOf("#");
|
|
7
|
+
if (hashSeparatorIndex === -1) {
|
|
8
|
+
return [resource, "", ""];
|
|
9
|
+
}
|
|
10
|
+
const beforeHashSeparator = resource.slice(0, hashSeparatorIndex);
|
|
11
|
+
const afterHashSeparator = resource.slice(hashSeparatorIndex + 1);
|
|
12
|
+
return [beforeHashSeparator, "", afterHashSeparator];
|
|
13
|
+
}
|
|
14
|
+
const beforeSearchSeparator = resource.slice(0, searchSeparatorIndex);
|
|
15
|
+
const afterSearchSeparator = resource.slice(searchSeparatorIndex + 1);
|
|
16
|
+
const hashSeparatorIndex = afterSearchSeparator.indexOf("#");
|
|
17
|
+
if (hashSeparatorIndex === -1) {
|
|
18
|
+
return [beforeSearchSeparator, afterSearchSeparator, ""];
|
|
19
|
+
}
|
|
20
|
+
const afterSearchSeparatorAndBeforeHashSeparator = afterSearchSeparator.slice(
|
|
21
|
+
0,
|
|
22
|
+
hashSeparatorIndex,
|
|
23
|
+
);
|
|
24
|
+
const afterHashSeparator = afterSearchSeparator.slice(hashSeparatorIndex + 1);
|
|
25
|
+
return [
|
|
26
|
+
beforeSearchSeparator,
|
|
27
|
+
afterSearchSeparatorAndBeforeHashSeparator,
|
|
28
|
+
afterHashSeparator,
|
|
29
|
+
];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const resourceToPathname = (resource) => {
|
|
33
|
+
const searchSeparatorIndex = resource.indexOf("?");
|
|
34
|
+
if (searchSeparatorIndex > -1) {
|
|
35
|
+
return resource.slice(0, searchSeparatorIndex);
|
|
36
|
+
}
|
|
37
|
+
const hashIndex = resource.indexOf("#");
|
|
38
|
+
if (hashIndex > -1) {
|
|
39
|
+
return resource.slice(0, hashIndex);
|
|
40
|
+
}
|
|
41
|
+
return resource;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const resourceToExtension = (resource) => {
|
|
45
|
+
const pathname = resourceToPathname(resource);
|
|
46
|
+
return pathnameToExtension(pathname);
|
|
47
|
+
};
|
package/src/url_to_extension.js
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
|
+
import { pathnameToExtension } from "./internal/pathname_to_extension.js";
|
|
1
2
|
import { urlToPathname } from "./url_to_pathname.js";
|
|
2
3
|
|
|
3
4
|
export const urlToExtension = (url) => {
|
|
4
5
|
const pathname = urlToPathname(url);
|
|
5
6
|
return pathnameToExtension(pathname);
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
-
const pathnameToExtension = (pathname) => {
|
|
9
|
-
const slashLastIndex = pathname.lastIndexOf("/");
|
|
10
|
-
if (slashLastIndex !== -1) {
|
|
11
|
-
pathname = pathname.slice(slashLastIndex + 1);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const dotLastIndex = pathname.lastIndexOf(".");
|
|
15
|
-
if (dotLastIndex === -1) return "";
|
|
16
|
-
// if (dotLastIndex === pathname.length - 1) return ""
|
|
17
|
-
const extension = pathname.slice(dotLastIndex);
|
|
18
|
-
return extension;
|
|
19
|
-
};
|
package/src/url_to_pathname.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resourceToPathname } from "./resource_to_parts.js";
|
|
1
2
|
import { urlToResource } from "./url_to_resource.js";
|
|
2
3
|
|
|
3
4
|
export const urlToPathname = (url) => {
|
|
@@ -5,15 +6,3 @@ export const urlToPathname = (url) => {
|
|
|
5
6
|
const pathname = resourceToPathname(resource);
|
|
6
7
|
return pathname;
|
|
7
8
|
};
|
|
8
|
-
|
|
9
|
-
const resourceToPathname = (resource) => {
|
|
10
|
-
const searchSeparatorIndex = resource.indexOf("?");
|
|
11
|
-
if (searchSeparatorIndex > -1) {
|
|
12
|
-
return resource.slice(0, searchSeparatorIndex);
|
|
13
|
-
}
|
|
14
|
-
const hashIndex = resource.indexOf("#");
|
|
15
|
-
if (hashIndex > -1) {
|
|
16
|
-
return resource.slice(0, hashIndex);
|
|
17
|
-
}
|
|
18
|
-
return resource;
|
|
19
|
-
};
|
package/src/url_utils.js
CHANGED