@duplojs/lang 0.0.1-beta.3 → 0.0.1-beta.5
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/dist/array/index.cjs +0 -3
- package/dist/array/index.d.ts +0 -1
- package/dist/array/index.mjs +1 -3
- package/dist/common/constraint/cast/number.d.ts +15 -0
- package/dist/common/constraint/cast/string.d.ts +9 -0
- package/dist/common/constraint/index.d.ts +1 -0
- package/dist/common/constraint/infer/array.d.ts +7 -0
- package/dist/{array/infer.cjs → common/constraint/infer/index.cjs} +1 -1
- package/dist/common/constraint/infer/index.d.ts +26 -0
- package/dist/{string/infer.mjs → common/constraint/infer/index.mjs} +1 -1
- package/dist/common/constraint/infer/number.d.ts +11 -0
- package/dist/common/constraint/infer/string.d.ts +10 -0
- package/dist/common/index.cjs +3 -0
- package/dist/common/index.mjs +3 -1
- package/dist/dataStructure/constraint/defaults/absolutePath.cjs +13 -0
- package/dist/dataStructure/constraint/defaults/absolutePath.d.ts +10 -0
- package/dist/dataStructure/constraint/defaults/absolutePath.mjs +12 -0
- package/dist/dataStructure/constraint/defaults/index.d.ts +2 -0
- package/dist/dataStructure/constraint/defaults/path.cjs +13 -0
- package/dist/dataStructure/constraint/defaults/path.d.ts +10 -0
- package/dist/dataStructure/constraint/defaults/path.mjs +12 -0
- package/dist/dataStructure/constraint/identifier.d.ts +1 -4
- package/dist/dataStructure/constraint/types/constraints.d.ts +2 -0
- package/dist/dataStructure/fundamentalType/identifier.d.ts +1 -4
- package/dist/dataStructure/helpers/absolutePath.cjs +7 -0
- package/dist/dataStructure/helpers/absolutePath.d.ts +2 -0
- package/dist/dataStructure/helpers/absolutePath.mjs +7 -0
- package/dist/dataStructure/helpers/index.d.ts +2 -0
- package/dist/dataStructure/helpers/path.cjs +7 -0
- package/dist/dataStructure/helpers/path.d.ts +2 -0
- package/dist/dataStructure/helpers/path.mjs +7 -0
- package/dist/dataStructure/index.cjs +16 -0
- package/dist/dataStructure/index.mjs +11 -1
- package/dist/dataStructure/structure/identifier.d.ts +1 -4
- package/dist/dataStructure/type/identifier.d.ts +1 -4
- package/dist/index.cjs +41 -39
- package/dist/index.mjs +3 -2
- package/dist/kind/createIdentifier.d.ts +8 -4
- package/dist/number/index.cjs +0 -3
- package/dist/number/index.d.ts +0 -1
- package/dist/number/index.mjs +1 -3
- package/dist/path/computeRelative.cjs +5 -6
- package/dist/path/computeRelative.d.ts +1 -1
- package/dist/path/computeRelative.mjs +5 -6
- package/dist/path/constraints/absolute.d.ts +1 -1
- package/dist/path/getBaseName.cjs +5 -7
- package/dist/path/getBaseName.d.ts +2 -2
- package/dist/path/getBaseName.mjs +5 -7
- package/dist/path/getExtensionName.cjs +7 -4
- package/dist/path/getExtensionName.d.ts +2 -2
- package/dist/path/getExtensionName.mjs +7 -4
- package/dist/path/getParentFolderPath.cjs +5 -4
- package/dist/path/getParentFolderPath.d.ts +1 -2
- package/dist/path/getParentFolderPath.mjs +5 -4
- package/dist/path/index.cjs +3 -3
- package/dist/path/index.d.ts +2 -2
- package/dist/path/index.mjs +3 -3
- package/dist/path/is.cjs +9 -4
- package/dist/path/is.d.ts +4 -2
- package/dist/path/is.mjs +9 -4
- package/dist/path/isAbsolute.cjs +3 -5
- package/dist/path/isAbsolute.d.ts +4 -2
- package/dist/path/isAbsolute.mjs +3 -5
- package/dist/path/normalize.cjs +18 -0
- package/dist/path/normalize.d.ts +2 -0
- package/dist/path/normalize.mjs +18 -0
- package/dist/path/resolveFrom.cjs +4 -5
- package/dist/path/resolveFrom.d.ts +9 -1
- package/dist/path/resolveFrom.mjs +4 -5
- package/dist/path/resolveRelative.cjs +17 -20
- package/dist/path/resolveRelative.d.ts +9 -2
- package/dist/path/resolveRelative.mjs +17 -20
- package/dist/path/types/index.d.ts +4 -0
- package/dist/path/types/isLiteralAbsolutePath.d.ts +2 -0
- package/dist/path/types/isLiteralPath.d.ts +20 -0
- package/dist/path/types/requireLiteralAbsolutePath.d.ts +3 -0
- package/dist/path/types/requireLiteralPath.d.ts +3 -0
- package/dist/string/index.cjs +0 -3
- package/dist/string/index.d.ts +0 -1
- package/dist/string/index.mjs +1 -3
- package/dist/string/types/split.d.ts +1 -1
- package/package.json +1 -1
- package/dist/array/infer.d.ts +0 -14
- package/dist/array/infer.mjs +0 -6
- package/dist/number/infer.cjs +0 -6
- package/dist/number/infer.d.ts +0 -12
- package/dist/number/infer.mjs +0 -6
- package/dist/path/fix.cjs +0 -8
- package/dist/path/fix.d.ts +0 -1
- package/dist/path/fix.mjs +0 -8
- package/dist/string/infer.cjs +0 -6
- package/dist/string/infer.d.ts +0 -12
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
const require_fix = require("./fix.cjs");
|
|
2
1
|
//#region scripts/path/computeRelative.ts
|
|
3
2
|
function computeRelative(source, destination) {
|
|
4
|
-
const sourceSegments =
|
|
5
|
-
const destinationSegments =
|
|
6
|
-
let commonIndex =
|
|
3
|
+
const sourceSegments = source === "/" ? [] : source.slice(1).split("/");
|
|
4
|
+
const destinationSegments = destination === "/" ? [] : destination.slice(1).split("/");
|
|
5
|
+
let commonIndex = 0;
|
|
7
6
|
while (commonIndex < sourceSegments.length && commonIndex < destinationSegments.length && sourceSegments[commonIndex] === destinationSegments[commonIndex]) commonIndex++;
|
|
8
7
|
let result = "";
|
|
9
|
-
for (let index = commonIndex; index < sourceSegments.length; index++) result += result
|
|
10
|
-
for (let index = commonIndex; index < destinationSegments.length; index++) result += result
|
|
8
|
+
for (let index = commonIndex; index < sourceSegments.length; index++) result += result ? "/.." : "..";
|
|
9
|
+
for (let index = commonIndex; index < destinationSegments.length; index++) result += result ? `/${destinationSegments[index]}` : destinationSegments[index];
|
|
11
10
|
return result || ".";
|
|
12
11
|
}
|
|
13
12
|
//#endregion
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Absolute, Path } from './constraints';
|
|
2
|
-
export declare function computeRelative<GenericSourcePath extends string &
|
|
2
|
+
export declare function computeRelative<GenericSourcePath extends string & Absolute, GenericDestinationPath extends string & Absolute>(source: GenericSourcePath, destination: GenericDestinationPath): string & Path;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { fix } from "./fix.mjs";
|
|
2
1
|
//#region scripts/path/computeRelative.ts
|
|
3
2
|
function computeRelative(source, destination) {
|
|
4
|
-
const sourceSegments =
|
|
5
|
-
const destinationSegments =
|
|
6
|
-
let commonIndex =
|
|
3
|
+
const sourceSegments = source === "/" ? [] : source.slice(1).split("/");
|
|
4
|
+
const destinationSegments = destination === "/" ? [] : destination.slice(1).split("/");
|
|
5
|
+
let commonIndex = 0;
|
|
7
6
|
while (commonIndex < sourceSegments.length && commonIndex < destinationSegments.length && sourceSegments[commonIndex] === destinationSegments[commonIndex]) commonIndex++;
|
|
8
7
|
let result = "";
|
|
9
|
-
for (let index = commonIndex; index < sourceSegments.length; index++) result += result
|
|
10
|
-
for (let index = commonIndex; index < destinationSegments.length; index++) result += result
|
|
8
|
+
for (let index = commonIndex; index < sourceSegments.length; index++) result += result ? "/.." : "..";
|
|
9
|
+
for (let index = commonIndex; index < destinationSegments.length; index++) result += result ? `/${destinationSegments[index]}` : destinationSegments[index];
|
|
11
10
|
return result || ".";
|
|
12
11
|
}
|
|
13
12
|
//#endregion
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
//#region scripts/path/getBaseName.ts
|
|
2
|
-
const baseNameRegex =
|
|
3
|
-
const extensionNameRegex =
|
|
4
|
-
const segmentTrailingRegex = /\/+$/;
|
|
2
|
+
const baseNameRegex = /([^/]+)$/;
|
|
3
|
+
const extensionNameRegex = /(?<!^)\.[^./]+$/;
|
|
5
4
|
function getBaseName(path, params) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return baseName;
|
|
5
|
+
const baseName = baseNameRegex.exec(path)?.[1];
|
|
6
|
+
if (baseName === void 0) return null;
|
|
7
|
+
return params?.removeExtension ? baseName.replace(extensionNameRegex, "") : baseName;
|
|
10
8
|
}
|
|
11
9
|
//#endregion
|
|
12
10
|
exports.getBaseName = getBaseName;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Path } from './constraints';
|
|
1
|
+
import { Absolute, Path } from './constraints';
|
|
2
2
|
export interface GetBaseNameParams {
|
|
3
3
|
removeExtension?: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare function getBaseName<GenericPath extends string & Path>(path: GenericPath, params?: GetBaseNameParams): string;
|
|
5
|
+
export declare function getBaseName<GenericPath extends string & (Path | Absolute)>(path: GenericPath, params?: GetBaseNameParams): string | null;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
//#region scripts/path/getBaseName.ts
|
|
2
|
-
const baseNameRegex =
|
|
3
|
-
const extensionNameRegex =
|
|
4
|
-
const segmentTrailingRegex = /\/+$/;
|
|
2
|
+
const baseNameRegex = /([^/]+)$/;
|
|
3
|
+
const extensionNameRegex = /(?<!^)\.[^./]+$/;
|
|
5
4
|
function getBaseName(path, params) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return baseName;
|
|
5
|
+
const baseName = baseNameRegex.exec(path)?.[1];
|
|
6
|
+
if (baseName === void 0) return null;
|
|
7
|
+
return params?.removeExtension ? baseName.replace(extensionNameRegex, "") : baseName;
|
|
10
8
|
}
|
|
11
9
|
//#endregion
|
|
12
10
|
export { getBaseName };
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
//#region scripts/path/getExtensionName.ts
|
|
2
|
-
const
|
|
2
|
+
const basenameRegex = /([^/]+)$/;
|
|
3
3
|
function getExtensionName(path, params) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
4
|
+
const baseName = basenameRegex.exec(path)?.[1];
|
|
5
|
+
if (!baseName || baseName === "." || baseName === "..") return null;
|
|
6
|
+
const dotIndex = baseName.lastIndexOf(".");
|
|
7
|
+
if (dotIndex <= 0 || dotIndex === baseName.length - 1) return null;
|
|
8
|
+
const extension = baseName.slice(dotIndex + 1);
|
|
9
|
+
return params?.withDot ? `.${extension}` : extension;
|
|
7
10
|
}
|
|
8
11
|
//#endregion
|
|
9
12
|
exports.getExtensionName = getExtensionName;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Path } from './constraints';
|
|
1
|
+
import { Absolute, Path } from './constraints';
|
|
2
2
|
export interface GetExtensionNameParams {
|
|
3
3
|
withDot?: boolean;
|
|
4
4
|
}
|
|
5
|
-
export declare function getExtensionName<GenericPath extends string & Path>(path: GenericPath, params?: GetExtensionNameParams): string;
|
|
5
|
+
export declare function getExtensionName<GenericPath extends string & (Path | Absolute)>(path: GenericPath, params?: GetExtensionNameParams): string | null;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
//#region scripts/path/getExtensionName.ts
|
|
2
|
-
const
|
|
2
|
+
const basenameRegex = /([^/]+)$/;
|
|
3
3
|
function getExtensionName(path, params) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
4
|
+
const baseName = basenameRegex.exec(path)?.[1];
|
|
5
|
+
if (!baseName || baseName === "." || baseName === "..") return null;
|
|
6
|
+
const dotIndex = baseName.lastIndexOf(".");
|
|
7
|
+
if (dotIndex <= 0 || dotIndex === baseName.length - 1) return null;
|
|
8
|
+
const extension = baseName.slice(dotIndex + 1);
|
|
9
|
+
return params?.withDot ? `.${extension}` : extension;
|
|
7
10
|
}
|
|
8
11
|
//#endregion
|
|
9
12
|
export { getExtensionName };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//#region scripts/path/getParentFolderPath.ts
|
|
2
|
-
const
|
|
2
|
+
const parentFolderPathRegex = /^([^]*)\/[^/]+$/;
|
|
3
|
+
const onlyParentsRegex = /^(?:\.\.)(?:\/\.\.)*$/;
|
|
3
4
|
function getParentFolderPath(path) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
return
|
|
5
|
+
const parent = parentFolderPathRegex.exec(path)?.[1];
|
|
6
|
+
if (parent === void 0 || parent === "" || onlyParentsRegex.test(parent)) return path.startsWith("/") && parent === "" ? "/" : null;
|
|
7
|
+
return parent;
|
|
7
8
|
}
|
|
8
9
|
//#endregion
|
|
9
10
|
exports.getParentFolderPath = getParentFolderPath;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import { Absolute, Path } from './constraints';
|
|
2
|
-
export declare function getParentFolderPath<GenericPath extends string & Path
|
|
3
|
-
export declare function getParentFolderPath<GenericPath extends string & Path>(path: GenericPath): string;
|
|
2
|
+
export declare function getParentFolderPath<GenericPath extends string & (Path | Absolute)>(path: GenericPath): string | null;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//#region scripts/path/getParentFolderPath.ts
|
|
2
|
-
const
|
|
2
|
+
const parentFolderPathRegex = /^([^]*)\/[^/]+$/;
|
|
3
|
+
const onlyParentsRegex = /^(?:\.\.)(?:\/\.\.)*$/;
|
|
3
4
|
function getParentFolderPath(path) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
return
|
|
5
|
+
const parent = parentFolderPathRegex.exec(path)?.[1];
|
|
6
|
+
if (parent === void 0 || parent === "" || onlyParentsRegex.test(parent)) return path.startsWith("/") && parent === "" ? "/" : null;
|
|
7
|
+
return parent;
|
|
7
8
|
}
|
|
8
9
|
//#endregion
|
|
9
10
|
export { getParentFolderPath };
|
package/dist/path/index.cjs
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
const require_runtime = require("../_virtual/_rolldown/runtime.cjs");
|
|
2
|
-
const require_fix = require("./fix.cjs");
|
|
3
2
|
const require_computeRelative = require("./computeRelative.cjs");
|
|
4
3
|
const require_getBaseName = require("./getBaseName.cjs");
|
|
5
4
|
const require_getExtensionName = require("./getExtensionName.cjs");
|
|
6
5
|
const require_getParentFolderPath = require("./getParentFolderPath.cjs");
|
|
7
6
|
const require_is = require("./is.cjs");
|
|
8
7
|
const require_isAbsolute = require("./isAbsolute.cjs");
|
|
8
|
+
const require_normalize = require("./normalize.cjs");
|
|
9
9
|
const require_resolveRelative = require("./resolveRelative.cjs");
|
|
10
10
|
const require_resolveFrom = require("./resolveFrom.cjs");
|
|
11
11
|
//#region scripts/path/index.ts
|
|
12
12
|
var path_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
13
13
|
computeRelative: () => require_computeRelative.computeRelative,
|
|
14
|
-
fix: () => require_fix.fix,
|
|
15
14
|
getBaseName: () => require_getBaseName.getBaseName,
|
|
16
15
|
getExtensionName: () => require_getExtensionName.getExtensionName,
|
|
17
16
|
getParentFolderPath: () => require_getParentFolderPath.getParentFolderPath,
|
|
18
17
|
is: () => require_is.is,
|
|
19
18
|
isAbsolute: () => require_isAbsolute.isAbsolute,
|
|
19
|
+
normalize: () => require_normalize.normalize,
|
|
20
20
|
resolveFrom: () => require_resolveFrom.resolveFrom,
|
|
21
21
|
resolveRelative: () => require_resolveRelative.resolveRelative
|
|
22
22
|
});
|
|
23
23
|
//#endregion
|
|
24
24
|
exports.computeRelative = require_computeRelative.computeRelative;
|
|
25
|
-
exports.fix = require_fix.fix;
|
|
26
25
|
exports.getBaseName = require_getBaseName.getBaseName;
|
|
27
26
|
exports.getExtensionName = require_getExtensionName.getExtensionName;
|
|
28
27
|
exports.getParentFolderPath = require_getParentFolderPath.getParentFolderPath;
|
|
29
28
|
exports.is = require_is.is;
|
|
30
29
|
exports.isAbsolute = require_isAbsolute.isAbsolute;
|
|
30
|
+
exports.normalize = require_normalize.normalize;
|
|
31
31
|
Object.defineProperty(exports, "path_exports", {
|
|
32
32
|
enumerable: true,
|
|
33
33
|
get: function() {
|
package/dist/path/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export type * from './constraints';
|
|
2
1
|
export * from './computeRelative';
|
|
3
|
-
export * from './
|
|
2
|
+
export type * from './constraints';
|
|
4
3
|
export * from './getBaseName';
|
|
5
4
|
export * from './getExtensionName';
|
|
6
5
|
export * from './getParentFolderPath';
|
|
7
6
|
export * from './is';
|
|
8
7
|
export * from './isAbsolute';
|
|
8
|
+
export * from './normalize';
|
|
9
9
|
export * from './resolveFrom';
|
|
10
10
|
export * from './resolveRelative';
|
|
11
11
|
export type * from './types';
|
package/dist/path/index.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { fix } from "./fix.mjs";
|
|
3
2
|
import { computeRelative } from "./computeRelative.mjs";
|
|
4
3
|
import { getBaseName } from "./getBaseName.mjs";
|
|
5
4
|
import { getExtensionName } from "./getExtensionName.mjs";
|
|
6
5
|
import { getParentFolderPath } from "./getParentFolderPath.mjs";
|
|
7
6
|
import { is } from "./is.mjs";
|
|
8
7
|
import { isAbsolute } from "./isAbsolute.mjs";
|
|
8
|
+
import { normalize } from "./normalize.mjs";
|
|
9
9
|
import { resolveRelative } from "./resolveRelative.mjs";
|
|
10
10
|
import { resolveFrom } from "./resolveFrom.mjs";
|
|
11
11
|
//#region scripts/path/index.ts
|
|
12
12
|
var path_exports = /* @__PURE__ */ __exportAll({
|
|
13
13
|
computeRelative: () => computeRelative,
|
|
14
|
-
fix: () => fix,
|
|
15
14
|
getBaseName: () => getBaseName,
|
|
16
15
|
getExtensionName: () => getExtensionName,
|
|
17
16
|
getParentFolderPath: () => getParentFolderPath,
|
|
18
17
|
is: () => is,
|
|
19
18
|
isAbsolute: () => isAbsolute,
|
|
19
|
+
normalize: () => normalize,
|
|
20
20
|
resolveFrom: () => resolveFrom,
|
|
21
21
|
resolveRelative: () => resolveRelative
|
|
22
22
|
});
|
|
23
23
|
//#endregion
|
|
24
|
-
export { computeRelative,
|
|
24
|
+
export { computeRelative, getBaseName, getExtensionName, getParentFolderPath, is, isAbsolute, normalize, path_exports, resolveFrom, resolveRelative };
|
package/dist/path/is.cjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
//#region scripts/path/is.ts
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const dotSegmentRegExp = /(^|\/)\.(\/|$)/;
|
|
3
|
+
const endsWithSlash = /[^]+\/$/;
|
|
4
|
+
const dotDotRegExp = /(^|\/)\.\.(\/|$)/;
|
|
5
|
+
const invalidDotDotRegExp = /(^|\/)(?!\.\.(?:\/|$))[^/]+\/\.\.(?:\/|$)/;
|
|
6
|
+
function is(value) {
|
|
7
|
+
if (value === ".") return true;
|
|
8
|
+
if (value === "" || value.includes("\0") || value.includes("//") || endsWithSlash.test(value) || dotSegmentRegExp.test(value)) return false;
|
|
9
|
+
if (value.startsWith("/")) return !dotDotRegExp.test(value);
|
|
10
|
+
return !invalidDotDotRegExp.test(value);
|
|
6
11
|
}
|
|
7
12
|
//#endregion
|
|
8
13
|
exports.is = is;
|
package/dist/path/is.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Path } from './constraints';
|
|
2
|
-
|
|
1
|
+
import { Absolute, Path } from './constraints';
|
|
2
|
+
import { IsLiteralPath } from './types';
|
|
3
|
+
import type * as DString from '../string';
|
|
4
|
+
export declare function is<GenericPath extends string>(value: GenericPath): value is (GenericPath extends (Path | Absolute) ? GenericPath : IsLiteralPath<GenericPath> extends true ? GenericPath : DString.IsLiteral<GenericPath> extends true ? never : GenericPath & Path);
|
package/dist/path/is.mjs
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
//#region scripts/path/is.ts
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const dotSegmentRegExp = /(^|\/)\.(\/|$)/;
|
|
3
|
+
const endsWithSlash = /[^]+\/$/;
|
|
4
|
+
const dotDotRegExp = /(^|\/)\.\.(\/|$)/;
|
|
5
|
+
const invalidDotDotRegExp = /(^|\/)(?!\.\.(?:\/|$))[^/]+\/\.\.(?:\/|$)/;
|
|
6
|
+
function is(value) {
|
|
7
|
+
if (value === ".") return true;
|
|
8
|
+
if (value === "" || value.includes("\0") || value.includes("//") || endsWithSlash.test(value) || dotSegmentRegExp.test(value)) return false;
|
|
9
|
+
if (value.startsWith("/")) return !dotDotRegExp.test(value);
|
|
10
|
+
return !invalidDotDotRegExp.test(value);
|
|
6
11
|
}
|
|
7
12
|
//#endregion
|
|
8
13
|
export { is };
|
package/dist/path/isAbsolute.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
const require_is = require("./is.cjs");
|
|
1
2
|
//#region scripts/path/isAbsolute.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const posixAbsolutePathRegex = /^\/(?:$|[^/]+(?:\/[^/]+)*(?:\/+)?$)/;
|
|
5
|
-
function isAbsolute(path) {
|
|
6
|
-
return !path.includes(nullCharacter) && posixAbsolutePathRegex.test(path) && !containBackPathRegex.test(path);
|
|
3
|
+
function isAbsolute(value) {
|
|
4
|
+
return value.startsWith("/") && require_is.is(value);
|
|
7
5
|
}
|
|
8
6
|
//#endregion
|
|
9
7
|
exports.isAbsolute = isAbsolute;
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { Absolute
|
|
2
|
-
|
|
1
|
+
import { Absolute } from './constraints';
|
|
2
|
+
import { IsLiteralAbsolutePath } from './types';
|
|
3
|
+
import type * as DString from '../string';
|
|
4
|
+
export declare function isAbsolute<GenericPath extends string>(value: GenericPath): value is (GenericPath extends Absolute ? GenericPath : IsLiteralAbsolutePath<GenericPath> extends true ? GenericPath : DString.IsLiteral<GenericPath> extends true ? never : GenericPath & Absolute);
|
package/dist/path/isAbsolute.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
+
import { is } from "./is.mjs";
|
|
1
2
|
//#region scripts/path/isAbsolute.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const posixAbsolutePathRegex = /^\/(?:$|[^/]+(?:\/[^/]+)*(?:\/+)?$)/;
|
|
5
|
-
function isAbsolute(path) {
|
|
6
|
-
return !path.includes(nullCharacter) && posixAbsolutePathRegex.test(path) && !containBackPathRegex.test(path);
|
|
3
|
+
function isAbsolute(value) {
|
|
4
|
+
return value.startsWith("/") && is(value);
|
|
7
5
|
}
|
|
8
6
|
//#endregion
|
|
9
7
|
export { isAbsolute };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region scripts/path/normalize.ts
|
|
2
|
+
function normalize(path) {
|
|
3
|
+
if (path.includes("\0")) return null;
|
|
4
|
+
const absolute = path.startsWith("/");
|
|
5
|
+
const result = [];
|
|
6
|
+
for (const segment of path.split("/")) {
|
|
7
|
+
if (segment === "" || segment === ".") continue;
|
|
8
|
+
if (segment === "..") {
|
|
9
|
+
if (result.length !== 0 && result.at(-1) !== "..") result.pop();
|
|
10
|
+
else if (!absolute) result.push("..");
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
result.push(segment);
|
|
14
|
+
}
|
|
15
|
+
return absolute ? `/${result.join("/")}` : result.join("/") || ".";
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.normalize = normalize;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region scripts/path/normalize.ts
|
|
2
|
+
function normalize(path) {
|
|
3
|
+
if (path.includes("\0")) return null;
|
|
4
|
+
const absolute = path.startsWith("/");
|
|
5
|
+
const result = [];
|
|
6
|
+
for (const segment of path.split("/")) {
|
|
7
|
+
if (segment === "" || segment === ".") continue;
|
|
8
|
+
if (segment === "..") {
|
|
9
|
+
if (result.length !== 0 && result.at(-1) !== "..") result.pop();
|
|
10
|
+
else if (!absolute) result.push("..");
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
result.push(segment);
|
|
14
|
+
}
|
|
15
|
+
return absolute ? `/${result.join("/")}` : result.join("/") || ".";
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { normalize };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const require_resolveRelative = require("./resolveRelative.cjs");
|
|
2
2
|
//#region scripts/path/resolveFrom.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return `/${result.replace(aboveRootRegex, "")}`;
|
|
3
|
+
function resolveFrom(origin, segments, params) {
|
|
4
|
+
const resultRelative = require_resolveRelative.resolveRelative(segments);
|
|
5
|
+
if (params?.stayInOrigin && (resultRelative === ".." || resultRelative.startsWith("../") || resultRelative.startsWith("/"))) return null;
|
|
6
|
+
return require_resolveRelative.resolveRelative([origin, resultRelative]);
|
|
8
7
|
}
|
|
9
8
|
//#endregion
|
|
10
9
|
exports.resolveFrom = resolveFrom;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import { Absolute, Path } from './constraints';
|
|
2
2
|
import { RequireSegments } from './types';
|
|
3
|
-
|
|
3
|
+
import type * as DCommon from '../common';
|
|
4
|
+
export interface ResolveFromParams {
|
|
5
|
+
stayInOrigin?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function resolveFrom<const GenericSegments extends readonly (string & (Path | Absolute))[], const GenericParams extends ResolveFromParams>(origin: string & Absolute, segments: GenericSegments & RequireSegments<GenericSegments>, params?: GenericParams): (string & Absolute) | (DCommon.BreakGenericLink<DCommon.Or<[
|
|
8
|
+
DCommon.IsEqual<GenericParams["stayInOrigin"], ResolveFromParams["stayInOrigin"]>,
|
|
9
|
+
DCommon.IsEqual<GenericParams["stayInOrigin"], false>,
|
|
10
|
+
DCommon.IsEqual<GenericParams["stayInOrigin"], unknown>
|
|
11
|
+
]> extends true ? never : null>);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { resolveRelative } from "./resolveRelative.mjs";
|
|
2
2
|
//#region scripts/path/resolveFrom.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return `/${result.replace(aboveRootRegex, "")}`;
|
|
3
|
+
function resolveFrom(origin, segments, params) {
|
|
4
|
+
const resultRelative = resolveRelative(segments);
|
|
5
|
+
if (params?.stayInOrigin && (resultRelative === ".." || resultRelative.startsWith("../") || resultRelative.startsWith("/"))) return null;
|
|
6
|
+
return resolveRelative([origin, resultRelative]);
|
|
8
7
|
}
|
|
9
8
|
//#endregion
|
|
10
9
|
export { resolveFrom };
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
//#region scripts/path/resolveRelative.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
function resolveRelative(paths) {
|
|
3
|
+
let absolute = false;
|
|
4
|
+
const result = [];
|
|
5
|
+
for (const path of paths) {
|
|
6
|
+
if (path === ".") continue;
|
|
7
|
+
if (path.startsWith("/")) {
|
|
8
|
+
absolute = true;
|
|
9
|
+
result.length = 0;
|
|
10
|
+
}
|
|
11
|
+
for (const segment of path.split("/")) {
|
|
12
|
+
if (segment === "") continue;
|
|
13
|
+
if (segment === "..") {
|
|
14
|
+
if (result.length && result.at(-1) !== "..") result.pop();
|
|
15
|
+
else if (!absolute) result.push("..");
|
|
16
|
+
} else result.push(segment);
|
|
11
17
|
}
|
|
12
|
-
const formattedSegment = segment.replace(segmentTrailingRegex, "").replace(segmentRelativeRegex, "");
|
|
13
|
-
if (formattedSegment.startsWith("/") || clearedPath === "") clearedPath = formattedSegment;
|
|
14
|
-
else if (clearedPath === "/") clearedPath += formattedSegment;
|
|
15
|
-
else clearedPath += `/${formattedSegment}`;
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (const element of clearedPath.split("/")) if (element === "..") {
|
|
20
|
-
if (!result.pop()) dotResult.push(element);
|
|
21
|
-
} else result.push(element);
|
|
22
|
-
if (dotResult.length === 0) return result.join("/");
|
|
23
|
-
return `${dotResult.join("/")}/${result.join("/")}`;
|
|
19
|
+
if (absolute) return `/${result.join("/")}`;
|
|
20
|
+
return result.join("/") || ".";
|
|
24
21
|
}
|
|
25
22
|
//#endregion
|
|
26
23
|
exports.resolveRelative = resolveRelative;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { Path } from './constraints';
|
|
1
|
+
import { Absolute, Path } from './constraints';
|
|
2
2
|
import { RequireSegments } from './types';
|
|
3
|
-
|
|
3
|
+
import type * as DCommon from '../common';
|
|
4
|
+
type HasAbsolutePath<GenericSegments extends readonly (string & (Path | Absolute))[]> = DCommon.ContainExtends<{
|
|
5
|
+
[Prop in keyof GenericSegments]: [DCommon.IsExtends<GenericSegments[Prop], Absolute>];
|
|
6
|
+
}[Extract<keyof GenericSegments, number>], [
|
|
7
|
+
true
|
|
8
|
+
]>;
|
|
9
|
+
export declare function resolveRelative<const GenericSegments extends readonly (string & (Path | Absolute))[]>(segments: GenericSegments & RequireSegments<GenericSegments>): string & Path & (DCommon.BreakGenericLink<HasAbsolutePath<GenericSegments> extends true ? Absolute : unknown>);
|
|
10
|
+
export {};
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
//#region scripts/path/resolveRelative.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
function resolveRelative(paths) {
|
|
3
|
+
let absolute = false;
|
|
4
|
+
const result = [];
|
|
5
|
+
for (const path of paths) {
|
|
6
|
+
if (path === ".") continue;
|
|
7
|
+
if (path.startsWith("/")) {
|
|
8
|
+
absolute = true;
|
|
9
|
+
result.length = 0;
|
|
10
|
+
}
|
|
11
|
+
for (const segment of path.split("/")) {
|
|
12
|
+
if (segment === "") continue;
|
|
13
|
+
if (segment === "..") {
|
|
14
|
+
if (result.length && result.at(-1) !== "..") result.pop();
|
|
15
|
+
else if (!absolute) result.push("..");
|
|
16
|
+
} else result.push(segment);
|
|
11
17
|
}
|
|
12
|
-
const formattedSegment = segment.replace(segmentTrailingRegex, "").replace(segmentRelativeRegex, "");
|
|
13
|
-
if (formattedSegment.startsWith("/") || clearedPath === "") clearedPath = formattedSegment;
|
|
14
|
-
else if (clearedPath === "/") clearedPath += formattedSegment;
|
|
15
|
-
else clearedPath += `/${formattedSegment}`;
|
|
16
18
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
for (const element of clearedPath.split("/")) if (element === "..") {
|
|
20
|
-
if (!result.pop()) dotResult.push(element);
|
|
21
|
-
} else result.push(element);
|
|
22
|
-
if (dotResult.length === 0) return result.join("/");
|
|
23
|
-
return `${dotResult.join("/")}/${result.join("/")}`;
|
|
19
|
+
if (absolute) return `/${result.join("/")}`;
|
|
20
|
+
return result.join("/") || ".";
|
|
24
21
|
}
|
|
25
22
|
//#endregion
|
|
26
23
|
export { resolveRelative };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type * as DCommon from '../../common';
|
|
2
|
+
import type * as DString from '../../string';
|
|
3
|
+
type CheckSegment<GenericSegment extends readonly string[], GenericDotIsPass extends boolean, GenericIsFirst extends boolean = true> = GenericSegment extends readonly [] ? true : GenericSegment extends readonly [
|
|
4
|
+
infer InferredFirst extends string,
|
|
5
|
+
...infer InferredRest extends readonly string[]
|
|
6
|
+
] ? DCommon.Or<[
|
|
7
|
+
DCommon.IsEqual<".", InferredFirst>,
|
|
8
|
+
DString.Includes<InferredFirst, "/">,
|
|
9
|
+
DString.Includes<InferredFirst, "\0">,
|
|
10
|
+
DCommon.And<[
|
|
11
|
+
DCommon.IsEqual<GenericIsFirst, false>,
|
|
12
|
+
DCommon.IsEqual<"", InferredFirst>
|
|
13
|
+
]>,
|
|
14
|
+
DCommon.And<[
|
|
15
|
+
DCommon.IsEqual<GenericDotIsPass, true>,
|
|
16
|
+
DCommon.IsEqual<"..", InferredFirst>
|
|
17
|
+
]>
|
|
18
|
+
]> extends true ? false : CheckSegment<InferredRest, DCommon.Not<DCommon.IsEqual<InferredFirst, "..">>, false> : false;
|
|
19
|
+
export type IsLiteralPath<GenericValue extends string> = DString.IsLiteral<GenericValue> extends true ? GenericValue extends "" ? false : GenericValue extends "/" ? true : GenericValue extends "." ? true : DString.Split<GenericValue, "/"> extends infer InferredResult extends readonly string[] ? CheckSegment<InferredResult, false> : never : false;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IsLiteralAbsolutePath } from './isLiteralAbsolutePath';
|
|
2
|
+
import type * as DCommon from '../../common';
|
|
3
|
+
export type RequireLiteralAbsolutePath<GenericValue extends string> = IsLiteralAbsolutePath<GenericValue> extends true ? unknown : DCommon.ComputedTypeError<"Value is not a absolute path.">;
|
package/dist/string/index.cjs
CHANGED
|
@@ -9,7 +9,6 @@ const require_extractAll = require("./extractAll.cjs");
|
|
|
9
9
|
const require_first = require("./first.cjs");
|
|
10
10
|
const require_includes = require("./includes.cjs");
|
|
11
11
|
const require_indexOf = require("./indexOf.cjs");
|
|
12
|
-
const require_infer = require("./infer.cjs");
|
|
13
12
|
const require_isComposedOf = require("./isComposedOf.cjs");
|
|
14
13
|
const require_isEmail = require("./isEmail.cjs");
|
|
15
14
|
const require_isIn = require("./isIn.cjs");
|
|
@@ -63,7 +62,6 @@ var string_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
63
62
|
first: () => require_first.first,
|
|
64
63
|
includes: () => require_includes.includes,
|
|
65
64
|
indexOf: () => require_indexOf.indexOf,
|
|
66
|
-
infer: () => require_infer.infer,
|
|
67
65
|
isComposedOf: () => require_isComposedOf.isComposedOf,
|
|
68
66
|
isEmail: () => require_isEmail.isEmail,
|
|
69
67
|
isIn: () => require_isIn.isIn,
|
|
@@ -118,7 +116,6 @@ exports.extractAll = require_extractAll.extractAll;
|
|
|
118
116
|
exports.first = require_first.first;
|
|
119
117
|
exports.includes = require_includes.includes;
|
|
120
118
|
exports.indexOf = require_indexOf.indexOf;
|
|
121
|
-
exports.infer = require_infer.infer;
|
|
122
119
|
exports.isComposedOf = require_isComposedOf.isComposedOf;
|
|
123
120
|
exports.isEmail = require_isEmail.isEmail;
|
|
124
121
|
exports.isIn = require_isIn.isIn;
|