@jsenv/urls 1.0.0 → 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.
- package/main.js +17 -0
- package/package.json +13 -5
- package/src/caller_position.js +1 -1
- package/src/common_pathname.js +42 -0
- package/src/ensure_url_trailing_slash.js +3 -0
- package/src/filesystem_path_to_url.js +10 -0
- package/src/inline_content_url_generator.js +1 -1
- package/src/is_filesystem_path.js +21 -0
- package/src/move_url.js +10 -0
- package/src/resolve_directory_url.js +7 -0
- package/src/resolve_url.js +6 -0
- package/src/url_is_inside_of.js +17 -0
- package/src/url_to_basename.js +9 -0
- package/src/url_to_extension.js +19 -0
- package/src/url_to_filename.js +14 -0
- package/src/url_to_filesystem_path.js +12 -0
- package/src/url_to_origin.js +7 -0
- package/src/url_to_parent_url.js +31 -0
- package/src/url_to_pathname.js +19 -0
- package/src/url_to_relative_url.js +56 -0
- package/src/url_to_ressource.js +21 -0
- package/src/url_to_scheme.js +10 -0
- package/src/url_trace.js +1 -1
- package/src/url_utils.js +3 -1
- package/docs/url_meta/advanced.md +0 -28
- package/docs/url_meta/demo/apply_associations.mjs +0 -27
- package/docs/url_meta/demo/full_match.mjs +0 -7
- package/docs/url_meta/demo/partial_match.mjs +0 -7
- package/docs/url_meta/demo/resolve_associations.mjs +0 -12
- package/docs/url_meta/notes.md +0 -26
- package/docs/url_meta/pattern_matching.md +0 -71
- package/docs/url_meta/readme.md +0 -87
- package/test/data_url.test.mjs +0 -57
- package/test/meta/aliasing.test.mjs +0 -47
- package/test/meta/as_flat_associations/basic.test.mjs +0 -64
- package/test/meta/assertions.test.mjs +0 -23
- package/test/meta/get_url_meta/any.test.mjs +0 -94
- package/test/meta/get_url_meta/basic.test.mjs +0 -226
- package/test/meta/get_url_meta/complex.test.mjs +0 -203
- package/test/meta/get_url_meta/double_wildcard_after.test.mjs +0 -68
- package/test/meta/get_url_meta/double_wildcard_around.test.mjs +0 -42
- package/test/meta/get_url_meta/double_wildcard_before.test.mjs +0 -55
- package/test/meta/get_url_meta/inheritance.test.mjs +0 -59
- package/test/meta/is_plain_object.test.mjs +0 -27
- package/test/meta/pattern_matching/basic.test.mjs +0 -100
- package/test/meta/pattern_matching/common.test.mjs +0 -145
- package/test/meta/pattern_matching/complex.test.mjs +0 -159
- package/test/meta/pattern_matching/contains.test.mjs +0 -46
- package/test/meta/pattern_matching/doublewildcard_after.test.mjs +0 -81
- package/test/meta/pattern_matching/doublewildcard_around.test.mjs +0 -42
- package/test/meta/pattern_matching/doublewildcard_before.test.mjs +0 -68
- package/test/meta/pattern_matching/doublewildcard_inside.test.mjs +0 -42
- package/test/meta/pattern_matching/trailing_slash.test.mjs +0 -55
- package/test/meta/pattern_matching/wildcard_after.test.mjs +0 -68
- package/test/meta/pattern_matching/wildcard_around.test.mjs +0 -94
- package/test/meta/pattern_matching/wildcard_before.test.mjs +0 -55
- package/test/meta/pattern_matching/wildcard_inside.test.mjs +0 -68
- package/test/meta/resolve_associations/basic.test.mjs +0 -42
- package/test/meta/resolve_associations/http_pattern.test.mjs +0 -35
- package/test/meta/url_child_may_match/inheritance.test.mjs +0 -71
- package/test/meta/url_child_may_match/url_child_may_match.test.mjs +0 -166
- package/test/url_trace.test.mjs +0 -224
- package/test.mjs +0 -13
package/main.js
CHANGED
|
@@ -25,3 +25,20 @@ export {
|
|
|
25
25
|
export { getCallerPosition } from "./src/caller_position.js"
|
|
26
26
|
|
|
27
27
|
export { URL_META } from "./src/meta/url_meta.js"
|
|
28
|
+
|
|
29
|
+
export { fileSystemPathToUrl } from "./src/filesystem_path_to_url.js"
|
|
30
|
+
export { isFileSystemPath } from "./src/is_filesystem_path.js"
|
|
31
|
+
export { resolveDirectoryUrl } from "./src/resolve_directory_url.js"
|
|
32
|
+
export { moveUrl } from "./src/move_url.js"
|
|
33
|
+
export { resolveUrl } from "./src/resolve_url.js"
|
|
34
|
+
export { urlIsInsideOf } from "./src/url_is_inside_of.js"
|
|
35
|
+
export { urlToBasename } from "./src/url_to_basename.js"
|
|
36
|
+
export { urlToExtension } from "./src/url_to_extension.js"
|
|
37
|
+
export { urlToFilename } from "./src/url_to_filename.js"
|
|
38
|
+
export { urlToFileSystemPath } from "./src/url_to_filesystem_path.js"
|
|
39
|
+
export { urlToOrigin } from "./src/url_to_origin.js"
|
|
40
|
+
export { urlToParentUrl } from "./src/url_to_parent_url.js"
|
|
41
|
+
export { urlToPathname } from "./src/url_to_pathname.js"
|
|
42
|
+
export { urlToRelativeUrl } from "./src/url_to_relative_url.js"
|
|
43
|
+
export { urlToRessource } from "./src/url_to_ressource.js"
|
|
44
|
+
export { urlToScheme } from "./src/url_to_scheme.js"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsenv/urls",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
"directory": "packages/urls"
|
|
9
9
|
},
|
|
10
10
|
"publishConfig": {
|
|
11
|
-
"access": "public"
|
|
12
|
-
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "dmail",
|
|
15
|
+
"email": "dmaillard06@gmail.com",
|
|
16
|
+
"url": "https://twitter.com/damienmaillard"
|
|
13
17
|
},
|
|
14
18
|
"type": "module",
|
|
15
19
|
"exports": {
|
|
@@ -18,11 +22,15 @@
|
|
|
18
22
|
},
|
|
19
23
|
"./*": "./*"
|
|
20
24
|
},
|
|
25
|
+
"files": [
|
|
26
|
+
"/src/",
|
|
27
|
+
"/main.js"
|
|
28
|
+
],
|
|
21
29
|
"scripts": {
|
|
22
30
|
"test": "node --conditions=development ./test.mjs"
|
|
23
31
|
},
|
|
24
32
|
"dependencies": {
|
|
25
|
-
"@jsenv/filesystem": "
|
|
33
|
+
"@jsenv/filesystem": "4.0.0",
|
|
26
34
|
"@jsenv/log": "1.6.3"
|
|
27
35
|
}
|
|
28
|
-
}
|
|
36
|
+
}
|
package/src/caller_position.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export const getCommonPathname = (pathname, otherPathname) => {
|
|
2
|
+
const firstDifferentCharacterIndex = findFirstDifferentCharacterIndex(
|
|
3
|
+
pathname,
|
|
4
|
+
otherPathname,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
// pathname and otherpathname are exactly the same
|
|
8
|
+
if (firstDifferentCharacterIndex === -1) {
|
|
9
|
+
return pathname
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const commonString = pathname.slice(0, firstDifferentCharacterIndex + 1)
|
|
13
|
+
// the first different char is at firstDifferentCharacterIndex
|
|
14
|
+
if (pathname.charAt(firstDifferentCharacterIndex) === "/") {
|
|
15
|
+
return commonString
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (otherPathname.charAt(firstDifferentCharacterIndex) === "/") {
|
|
19
|
+
return commonString
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const firstDifferentSlashIndex = commonString.lastIndexOf("/")
|
|
23
|
+
return pathname.slice(0, firstDifferentSlashIndex + 1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const findFirstDifferentCharacterIndex = (string, otherString) => {
|
|
27
|
+
const maxCommonLength = Math.min(string.length, otherString.length)
|
|
28
|
+
let i = 0
|
|
29
|
+
while (i < maxCommonLength) {
|
|
30
|
+
const char = string.charAt(i)
|
|
31
|
+
const otherChar = otherString.charAt(i)
|
|
32
|
+
if (char !== otherChar) {
|
|
33
|
+
return i
|
|
34
|
+
}
|
|
35
|
+
i++
|
|
36
|
+
}
|
|
37
|
+
if (string.length === otherString.length) {
|
|
38
|
+
return -1
|
|
39
|
+
}
|
|
40
|
+
// they differ at maxCommonLength
|
|
41
|
+
return maxCommonLength
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url"
|
|
2
|
+
|
|
3
|
+
import { isFileSystemPath } from "./is_filesystem_path.js"
|
|
4
|
+
|
|
5
|
+
export const fileSystemPathToUrl = (value) => {
|
|
6
|
+
if (!isFileSystemPath(value)) {
|
|
7
|
+
throw new Error(`value must be a filesystem path, got ${value}`)
|
|
8
|
+
}
|
|
9
|
+
return String(pathToFileURL(value))
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const isFileSystemPath = (value) => {
|
|
2
|
+
if (typeof value !== "string") {
|
|
3
|
+
throw new TypeError(
|
|
4
|
+
`isFileSystemPath first arg must be a string, got ${value}`,
|
|
5
|
+
)
|
|
6
|
+
}
|
|
7
|
+
if (value[0] === "/") {
|
|
8
|
+
return true
|
|
9
|
+
}
|
|
10
|
+
return startsWithWindowsDriveLetter(value)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const startsWithWindowsDriveLetter = (string) => {
|
|
14
|
+
const firstChar = string[0]
|
|
15
|
+
if (!/[a-zA-Z]/.test(firstChar)) return false
|
|
16
|
+
|
|
17
|
+
const secondChar = string[1]
|
|
18
|
+
if (secondChar !== ":") return false
|
|
19
|
+
|
|
20
|
+
return true
|
|
21
|
+
}
|
package/src/move_url.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { urlToRelativeUrl } from "./url_to_relative_url.js"
|
|
2
|
+
|
|
3
|
+
export const moveUrl = ({ url, from, to, preferAbsolute = false }) => {
|
|
4
|
+
const relativeUrl = urlToRelativeUrl(url, from)
|
|
5
|
+
const absoluteUrl = new URL(relativeUrl, to).href
|
|
6
|
+
if (preferAbsolute) {
|
|
7
|
+
return absoluteUrl
|
|
8
|
+
}
|
|
9
|
+
return urlToRelativeUrl(absoluteUrl, to)
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const urlIsInsideOf = (url, otherUrl) => {
|
|
2
|
+
const urlObject = new URL(url)
|
|
3
|
+
const otherUrlObject = new URL(otherUrl)
|
|
4
|
+
|
|
5
|
+
if (urlObject.origin !== otherUrlObject.origin) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const urlPathname = urlObject.pathname
|
|
10
|
+
const otherUrlPathname = otherUrlObject.pathname
|
|
11
|
+
if (urlPathname === otherUrlPathname) {
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const isInside = urlPathname.startsWith(otherUrlPathname)
|
|
16
|
+
return isInside
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { urlToFilename } from "./url_to_filename.js"
|
|
2
|
+
|
|
3
|
+
export const urlToBasename = (url) => {
|
|
4
|
+
const filename = urlToFilename(url)
|
|
5
|
+
const dotLastIndex = filename.lastIndexOf(".")
|
|
6
|
+
const basename =
|
|
7
|
+
dotLastIndex === -1 ? filename : filename.slice(0, dotLastIndex)
|
|
8
|
+
return basename
|
|
9
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { urlToPathname } from "./url_to_pathname.js"
|
|
2
|
+
|
|
3
|
+
export const urlToExtension = (url) => {
|
|
4
|
+
const pathname = urlToPathname(url)
|
|
5
|
+
return pathnameToExtension(pathname)
|
|
6
|
+
}
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { urlToPathname } from "./url_to_pathname.js"
|
|
2
|
+
|
|
3
|
+
export const urlToFilename = (url) => {
|
|
4
|
+
const pathname = urlToPathname(url)
|
|
5
|
+
const pathnameBeforeLastSlash = pathname.endsWith("/")
|
|
6
|
+
? pathname.slice(0, -1)
|
|
7
|
+
: pathname
|
|
8
|
+
const slashLastIndex = pathnameBeforeLastSlash.lastIndexOf("/")
|
|
9
|
+
const filename =
|
|
10
|
+
slashLastIndex === -1
|
|
11
|
+
? pathnameBeforeLastSlash
|
|
12
|
+
: pathnameBeforeLastSlash.slice(slashLastIndex + 1)
|
|
13
|
+
return filename
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { fileURLToPath } from "url"
|
|
2
|
+
|
|
3
|
+
export const urlToFileSystemPath = (url) => {
|
|
4
|
+
let urlString = String(url)
|
|
5
|
+
if (urlString[urlString.length - 1] === "/") {
|
|
6
|
+
// remove trailing / so that nodejs path becomes predictable otherwise it logs
|
|
7
|
+
// the trailing slash on linux but does not on windows
|
|
8
|
+
urlString = urlString.slice(0, -1)
|
|
9
|
+
}
|
|
10
|
+
const fileSystemPath = fileURLToPath(urlString)
|
|
11
|
+
return fileSystemPath
|
|
12
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { urlToOrigin } from "./url_to_origin.js"
|
|
2
|
+
import { urlToRessource } from "./url_to_ressource.js"
|
|
3
|
+
|
|
4
|
+
export const urlToParentUrl = (url) => {
|
|
5
|
+
const ressource = urlToRessource(url)
|
|
6
|
+
const slashLastIndex = ressource.lastIndexOf("/")
|
|
7
|
+
if (slashLastIndex === -1) {
|
|
8
|
+
const urlAsString = String(url)
|
|
9
|
+
return urlAsString
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const lastCharacterIndex = ressource.length - 1
|
|
13
|
+
if (slashLastIndex === lastCharacterIndex) {
|
|
14
|
+
const slashPreviousIndex = ressource.lastIndexOf(
|
|
15
|
+
"/",
|
|
16
|
+
lastCharacterIndex - 1,
|
|
17
|
+
)
|
|
18
|
+
if (slashPreviousIndex === -1) {
|
|
19
|
+
const urlAsString = String(url)
|
|
20
|
+
return urlAsString
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const origin = urlToOrigin(url)
|
|
24
|
+
const parentUrl = `${origin}${ressource.slice(0, slashPreviousIndex + 1)}`
|
|
25
|
+
return parentUrl
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const origin = urlToOrigin(url)
|
|
29
|
+
const parentUrl = `${origin}${ressource.slice(0, slashLastIndex + 1)}`
|
|
30
|
+
return parentUrl
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { urlToRessource } from "./url_to_ressource.js"
|
|
2
|
+
|
|
3
|
+
export const urlToPathname = (url) => {
|
|
4
|
+
const ressource = urlToRessource(url)
|
|
5
|
+
const pathname = ressourceToPathname(ressource)
|
|
6
|
+
return pathname
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ressourceToPathname = (ressource) => {
|
|
10
|
+
const searchSeparatorIndex = ressource.indexOf("?")
|
|
11
|
+
if (searchSeparatorIndex > -1) {
|
|
12
|
+
return ressource.slice(0, searchSeparatorIndex)
|
|
13
|
+
}
|
|
14
|
+
const hashIndex = ressource.indexOf("#")
|
|
15
|
+
if (hashIndex > -1) {
|
|
16
|
+
return ressource.slice(0, hashIndex)
|
|
17
|
+
}
|
|
18
|
+
return ressource
|
|
19
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { getCommonPathname } from "./common_pathname.js"
|
|
2
|
+
|
|
3
|
+
export const urlToRelativeUrl = (url, baseUrl) => {
|
|
4
|
+
const urlObject = new URL(url)
|
|
5
|
+
const baseUrlObject = new URL(baseUrl)
|
|
6
|
+
|
|
7
|
+
if (urlObject.protocol !== baseUrlObject.protocol) {
|
|
8
|
+
const urlAsString = String(url)
|
|
9
|
+
return urlAsString
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (
|
|
13
|
+
urlObject.username !== baseUrlObject.username ||
|
|
14
|
+
urlObject.password !== baseUrlObject.password ||
|
|
15
|
+
urlObject.host !== baseUrlObject.host
|
|
16
|
+
) {
|
|
17
|
+
const afterUrlScheme = String(url).slice(urlObject.protocol.length)
|
|
18
|
+
return afterUrlScheme
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const { pathname, hash, search } = urlObject
|
|
22
|
+
if (pathname === "/") {
|
|
23
|
+
const baseUrlRessourceWithoutLeadingSlash = baseUrlObject.pathname.slice(1)
|
|
24
|
+
return baseUrlRessourceWithoutLeadingSlash
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const basePathname = baseUrlObject.pathname
|
|
28
|
+
const commonPathname = getCommonPathname(pathname, basePathname)
|
|
29
|
+
if (!commonPathname) {
|
|
30
|
+
const urlAsString = String(url)
|
|
31
|
+
return urlAsString
|
|
32
|
+
}
|
|
33
|
+
const specificPathname = pathname.slice(commonPathname.length)
|
|
34
|
+
const baseSpecificPathname = basePathname.slice(commonPathname.length)
|
|
35
|
+
if (baseSpecificPathname.includes("/")) {
|
|
36
|
+
const baseSpecificParentPathname =
|
|
37
|
+
pathnameToParentPathname(baseSpecificPathname)
|
|
38
|
+
const relativeDirectoriesNotation = baseSpecificParentPathname.replace(
|
|
39
|
+
/.*?\//g,
|
|
40
|
+
"../",
|
|
41
|
+
)
|
|
42
|
+
const relativeUrl = `${relativeDirectoriesNotation}${specificPathname}${search}${hash}`
|
|
43
|
+
return relativeUrl
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const relativeUrl = `${specificPathname}${search}${hash}`
|
|
47
|
+
return relativeUrl
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const pathnameToParentPathname = (pathname) => {
|
|
51
|
+
const slashLastIndex = pathname.lastIndexOf("/")
|
|
52
|
+
if (slashLastIndex === -1) {
|
|
53
|
+
return "/"
|
|
54
|
+
}
|
|
55
|
+
return pathname.slice(0, slashLastIndex + 1)
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { urlToScheme } from "./url_to_scheme.js"
|
|
2
|
+
|
|
3
|
+
export const urlToRessource = (url) => {
|
|
4
|
+
const scheme = urlToScheme(url)
|
|
5
|
+
|
|
6
|
+
if (scheme === "file") {
|
|
7
|
+
const urlAsStringWithoutFileProtocol = String(url).slice("file://".length)
|
|
8
|
+
return urlAsStringWithoutFileProtocol
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (scheme === "https" || scheme === "http") {
|
|
12
|
+
// remove origin
|
|
13
|
+
const afterProtocol = String(url).slice(scheme.length + "://".length)
|
|
14
|
+
const pathnameSlashIndex = afterProtocol.indexOf("/", "://".length)
|
|
15
|
+
const urlAsStringWithoutOrigin = afterProtocol.slice(pathnameSlashIndex)
|
|
16
|
+
return urlAsStringWithoutOrigin
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const urlAsStringWithoutProtocol = String(url).slice(scheme.length + 1)
|
|
20
|
+
return urlAsStringWithoutProtocol
|
|
21
|
+
}
|
package/src/url_trace.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50
|
|
4
4
|
// https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1
|
|
5
5
|
|
|
6
|
-
import { urlToFileSystemPath } from "
|
|
6
|
+
import { urlToFileSystemPath } from "./url_to_filesystem_path.js"
|
|
7
7
|
import { ANSI } from "@jsenv/log"
|
|
8
8
|
|
|
9
9
|
export const stringifyUrlTrace = (trace) => {
|
package/src/url_utils.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { urlToOrigin
|
|
1
|
+
import { urlToOrigin } from "./url_to_origin.js"
|
|
2
|
+
import { urlToExtension } from "./url_to_extension.js"
|
|
3
|
+
import { urlToRessource } from "./url_to_ressource.js"
|
|
2
4
|
|
|
3
5
|
export const asUrlWithoutSearch = (url) => {
|
|
4
6
|
const urlObject = new URL(url)
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# urlChildMayMatch
|
|
2
|
-
|
|
3
|
-
_urlChildMayMatch_ is a function designed to ignore directory content that would never have specific metas.
|
|
4
|
-
|
|
5
|
-
```js
|
|
6
|
-
import { URL_META } from "@jsenv/urls"
|
|
7
|
-
|
|
8
|
-
const associations = {
|
|
9
|
-
color: {
|
|
10
|
-
"file:///**/*": "blue",
|
|
11
|
-
"file:///**/node_modules/": "green",
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const firstUrlCanHaveFilesWithColorBlue = URL_META.urlChildMayMatch({
|
|
16
|
-
url: "file:///src/",
|
|
17
|
-
associations,
|
|
18
|
-
predicate: ({ color }) => color === "blue",
|
|
19
|
-
})
|
|
20
|
-
firstUrlCanHaveFilesWithColorBlue // true
|
|
21
|
-
|
|
22
|
-
const secondUrlCanHaveFileWithColorBlue = URL_META.urlChildMayMatch({
|
|
23
|
-
url: "file:///node_modules/src/",
|
|
24
|
-
associations,
|
|
25
|
-
predicate: ({ color }) => color === "blue",
|
|
26
|
-
})
|
|
27
|
-
secondUrlCanHaveFileWithColorBlue // false
|
|
28
|
-
```
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { URL_META } from "@jsenv/urls"
|
|
2
|
-
|
|
3
|
-
const associations = {
|
|
4
|
-
insideSrc: {
|
|
5
|
-
"file:///src/": true,
|
|
6
|
-
},
|
|
7
|
-
extensionIsJs: {
|
|
8
|
-
"file:///**/*.js": true,
|
|
9
|
-
},
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const urlA = "file:///src/file.js"
|
|
13
|
-
const urlB = "file:///src/file.json"
|
|
14
|
-
console.log(
|
|
15
|
-
`${urlA}: ${JSON.stringify(
|
|
16
|
-
URL_META.applyAssociations({ url: urlA, associations }),
|
|
17
|
-
null,
|
|
18
|
-
" ",
|
|
19
|
-
)}`,
|
|
20
|
-
)
|
|
21
|
-
console.log(
|
|
22
|
-
`${urlB}: ${JSON.stringify(
|
|
23
|
-
URL_META.applyAssociations({ url: urlB, associations }),
|
|
24
|
-
null,
|
|
25
|
-
" ",
|
|
26
|
-
)}`,
|
|
27
|
-
)
|
package/docs/url_meta/notes.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
```js
|
|
2
|
-
// Name of variables in the code below corresponds
|
|
3
|
-
// to the terminology used in the codebase and documentation
|
|
4
|
-
const pattern = "**/*"
|
|
5
|
-
const value = { visible: true }
|
|
6
|
-
const valueMap = {
|
|
7
|
-
[pattern]: value,
|
|
8
|
-
}
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## associations
|
|
12
|
-
|
|
13
|
-
_associations composition_
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
const pattern = "**/*/"
|
|
17
|
-
const key = "visible"
|
|
18
|
-
const value = true
|
|
19
|
-
const meta = { [key]: value }
|
|
20
|
-
const valueMap = {
|
|
21
|
-
[pattern]: meta,
|
|
22
|
-
}
|
|
23
|
-
const associations = {
|
|
24
|
-
[key]: valueMap,
|
|
25
|
-
}
|
|
26
|
-
```
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
# applyPatternMatching
|
|
2
|
-
|
|
3
|
-
_applyPatternMatching_ is a function returning a _matchResult_ indicating if and how a _pattern_ matches an _url_.
|
|
4
|
-
|
|
5
|
-
```js
|
|
6
|
-
import { URL_META } from "@jsenv/urls"
|
|
7
|
-
|
|
8
|
-
const matchResult = URL_META.applyPatternMatching({
|
|
9
|
-
pattern: "file:///**/*",
|
|
10
|
-
url: "file://Users/directory/file.js",
|
|
11
|
-
})
|
|
12
|
-
matchResult.matched // true
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## pattern
|
|
16
|
-
|
|
17
|
-
_pattern_ parameter is a string looking like an url but where `*` and `**` can be used so that one specifier can match several url.
|
|
18
|
-
|
|
19
|
-
This parameter is **required**.
|
|
20
|
-
|
|
21
|
-
## url
|
|
22
|
-
|
|
23
|
-
_url_ parameter is a string representing a url.
|
|
24
|
-
|
|
25
|
-
This parameter is **required**.
|
|
26
|
-
|
|
27
|
-
## matchResult
|
|
28
|
-
|
|
29
|
-
_matchResult_ represents if and how a _pattern_ matches an _url_.
|
|
30
|
-
|
|
31
|
-
### Matching example
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
import { URL_META } from "@jsenv/urls"
|
|
35
|
-
|
|
36
|
-
const fullMatch = URL_META.applyPatternMatching({
|
|
37
|
-
pattern: "file:///**/*",
|
|
38
|
-
url: "file:///Users/directory/file.js",
|
|
39
|
-
})
|
|
40
|
-
console.log(JSON.stringify(fullMatch, null, " "))
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
```json
|
|
44
|
-
{
|
|
45
|
-
"matched": true,
|
|
46
|
-
"patternIndex": 12,
|
|
47
|
-
"urlIndex": 31,
|
|
48
|
-
"matchGroups": ["file.js"]
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Partial matching example
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
import { applyPatternMatching } from "@jsenv/urlss"
|
|
56
|
-
|
|
57
|
-
const partialMatch = URL_META.applyPatternMatching({
|
|
58
|
-
pattern: "file:///*.js",
|
|
59
|
-
url: "file:///file.jsx",
|
|
60
|
-
})
|
|
61
|
-
console.log(JSON.stringify(partialMatch, null, " "))
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
```json
|
|
65
|
-
{
|
|
66
|
-
"matched": false,
|
|
67
|
-
"patternIndex": 12,
|
|
68
|
-
"urlIndex": 15,
|
|
69
|
-
"matchGroups": ["file"]
|
|
70
|
-
}
|
|
71
|
-
```
|