@duplojs/lang 0.0.1-beta.4 → 0.0.1-beta.6
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 +13 -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 +11 -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 +3 -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/defaults/segmentPath.cjs +13 -0
- package/dist/dataStructure/constraint/defaults/segmentPath.d.ts +10 -0
- package/dist/dataStructure/constraint/defaults/segmentPath.mjs +12 -0
- package/dist/dataStructure/constraint/types/constraints.d.ts +3 -0
- 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 +3 -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/helpers/segmentPath.cjs +7 -0
- package/dist/dataStructure/helpers/segmentPath.d.ts +2 -0
- package/dist/dataStructure/helpers/segmentPath.mjs +7 -0
- package/dist/dataStructure/index.cjs +24 -0
- package/dist/dataStructure/index.mjs +16 -1
- package/dist/index.cjs +41 -39
- package/dist/index.mjs +3 -2
- package/dist/modeling/entity/namespace.cjs +1 -1
- package/dist/modeling/entity/namespace.mjs +2 -2
- package/dist/modeling/index.cjs +2 -2
- package/dist/modeling/index.mjs +3 -3
- package/dist/modeling/newType/helper.cjs +2 -2
- package/dist/modeling/newType/helper.d.ts +1 -1
- package/dist/modeling/newType/helper.mjs +2 -2
- package/dist/modeling/taggedObject/helper.cjs +7 -2
- package/dist/modeling/taggedObject/helper.d.ts +1 -0
- package/dist/modeling/taggedObject/helper.mjs +7 -2
- 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/constraints/index.d.ts +2 -1
- package/dist/path/constraints/segment.d.ts +3 -0
- package/dist/path/getBaseName.cjs +7 -7
- package/dist/path/getBaseName.d.ts +2 -2
- package/dist/path/getBaseName.mjs +7 -7
- package/dist/path/getExtensionName.cjs +9 -4
- package/dist/path/getExtensionName.d.ts +2 -2
- package/dist/path/getExtensionName.mjs +9 -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 +6 -3
- package/dist/path/index.d.ts +3 -2
- package/dist/path/index.mjs +5 -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/isSegment.cjs +6 -0
- package/dist/path/isSegment.d.ts +4 -0
- package/dist/path/isSegment.mjs +6 -0
- 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 +10 -2
- 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 +6 -0
- package/dist/path/types/isLiteralAbsolutePath.d.ts +2 -0
- package/dist/path/types/isLiteralPath.d.ts +20 -0
- package/dist/path/types/isLiteralSegmentPath.d.ts +9 -0
- package/dist/path/types/requireLiteralAbsolutePath.d.ts +3 -0
- package/dist/path/types/requireLiteralPath.d.ts +3 -0
- package/dist/path/types/requireLiteralSegmentPath.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/dist/tuple/from.cjs +6 -0
- package/dist/tuple/from.d.ts +8 -0
- package/dist/tuple/from.mjs +6 -0
- package/dist/tuple/index.cjs +6 -1
- package/dist/tuple/index.d.ts +1 -0
- package/dist/tuple/index.mjs +6 -2
- 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
|
@@ -12,3 +12,4 @@ export declare function taggedObject<GenericTaggedObject extends ObjectTag>(...a
|
|
|
12
12
|
] : never): GenericTaggedObject;
|
|
13
13
|
export type RequireTaggedObjectSameShape<GenericTaggedObject extends ObjectTag, GenericTaggedObjectShape extends ShapeTaggedObjectStructure> = DCommon.IsEqual<DCommon.SimplifyTopLevel<DObject.DeepReadonly<DKind.Remove<GenericTaggedObject>>>, DCommon.SimplifyTopLevel<DObject.DeepReadonly<DDataStructure.ShapeObjectStructureValue<GenericTaggedObjectShape>>>> extends true ? unknown : DCommon.ComputedTypeError<"Shape do not match.">;
|
|
14
14
|
export declare function createTaggedObject<GenericTaggedObject extends ObjectTag>(name: GetTagValue<GenericTaggedObject>): <GenericShape extends ShapeTaggedObjectStructure<GenericTaggedObject>>(shape: (GenericShape & RequireTaggedObjectSameShape<GenericTaggedObject, GenericShape>)) => TaggedObjectStructure<GenericTaggedObject>;
|
|
15
|
+
export declare function createTaggedObject<GenericTaggedObject extends ObjectTag, GenericName extends string = never, GenericShape extends DDataStructure.ShapeObjectStructure = never>(name: GetTagValue<GenericTaggedObject> | GenericName, shape: ShapeTaggedObjectStructure<GenericTaggedObject> | GenericShape): TaggedObjectStructure<ObjectTag extends GenericTaggedObject ? (ObjectTag<GenericName> & DDataStructure.ShapeObjectStructureValue<GenericShape>) : GenericTaggedObject>;
|
|
@@ -19,8 +19,13 @@ function taggedObject(tag, props) {
|
|
|
19
19
|
[objectTagKind.runTimeKey]: tag
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
function createTaggedObject(
|
|
23
|
-
|
|
22
|
+
function createTaggedObject(...args) {
|
|
23
|
+
if (args.length === 1) {
|
|
24
|
+
const [name] = args;
|
|
25
|
+
return (shape) => createTaggedObject(name, shape);
|
|
26
|
+
}
|
|
27
|
+
const [name, shape] = args;
|
|
28
|
+
return TaggedObjectStructure(name, shape);
|
|
24
29
|
}
|
|
25
30
|
//#endregion
|
|
26
31
|
export { createTaggedObject, getTagValue, hasTagValue, taggedObject };
|
package/dist/number/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@ const require_betweenThan = require("./betweenThan.cjs");
|
|
|
3
3
|
const require_betweenThanOrEqual = require("./betweenThanOrEqual.cjs");
|
|
4
4
|
const require_greaterThan = require("./greaterThan.cjs");
|
|
5
5
|
const require_greaterThanOrEqual = require("./greaterThanOrEqual.cjs");
|
|
6
|
-
const require_infer = require("./infer.cjs");
|
|
7
6
|
const require_isEven = require("./isEven.cjs");
|
|
8
7
|
const require_isInteger = require("./isInteger.cjs");
|
|
9
8
|
const require_isMultipleOf = require("./isMultipleOf.cjs");
|
|
@@ -28,7 +27,6 @@ var number_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
28
27
|
betweenThanOrEqual: () => require_betweenThanOrEqual.betweenThanOrEqual,
|
|
29
28
|
greaterThan: () => require_greaterThan.greaterThan,
|
|
30
29
|
greaterThanOrEqual: () => require_greaterThanOrEqual.greaterThanOrEqual,
|
|
31
|
-
infer: () => require_infer.infer,
|
|
32
30
|
isEven: () => require_isEven.isEven,
|
|
33
31
|
isInteger: () => require_isInteger.isInteger,
|
|
34
32
|
isMultipleOf: () => require_isMultipleOf.isMultipleOf,
|
|
@@ -53,7 +51,6 @@ exports.betweenThan = require_betweenThan.betweenThan;
|
|
|
53
51
|
exports.betweenThanOrEqual = require_betweenThanOrEqual.betweenThanOrEqual;
|
|
54
52
|
exports.greaterThan = require_greaterThan.greaterThan;
|
|
55
53
|
exports.greaterThanOrEqual = require_greaterThanOrEqual.greaterThanOrEqual;
|
|
56
|
-
exports.infer = require_infer.infer;
|
|
57
54
|
exports.isEven = require_isEven.isEven;
|
|
58
55
|
exports.isInteger = require_isInteger.isInteger;
|
|
59
56
|
exports.isMultipleOf = require_isMultipleOf.isMultipleOf;
|
package/dist/number/index.d.ts
CHANGED
package/dist/number/index.mjs
CHANGED
|
@@ -3,7 +3,6 @@ import { betweenThan } from "./betweenThan.mjs";
|
|
|
3
3
|
import { betweenThanOrEqual } from "./betweenThanOrEqual.mjs";
|
|
4
4
|
import { greaterThan } from "./greaterThan.mjs";
|
|
5
5
|
import { greaterThanOrEqual } from "./greaterThanOrEqual.mjs";
|
|
6
|
-
import { infer } from "./infer.mjs";
|
|
7
6
|
import { isEven } from "./isEven.mjs";
|
|
8
7
|
import { isInteger } from "./isInteger.mjs";
|
|
9
8
|
import { isMultipleOf } from "./isMultipleOf.mjs";
|
|
@@ -28,7 +27,6 @@ var number_exports = /* @__PURE__ */ __exportAll({
|
|
|
28
27
|
betweenThanOrEqual: () => betweenThanOrEqual,
|
|
29
28
|
greaterThan: () => greaterThan,
|
|
30
29
|
greaterThanOrEqual: () => greaterThanOrEqual,
|
|
31
|
-
infer: () => infer,
|
|
32
30
|
isEven: () => isEven,
|
|
33
31
|
isInteger: () => isInteger,
|
|
34
32
|
isMultipleOf: () => isMultipleOf,
|
|
@@ -49,4 +47,4 @@ var number_exports = /* @__PURE__ */ __exportAll({
|
|
|
49
47
|
sum: () => sum
|
|
50
48
|
});
|
|
51
49
|
//#endregion
|
|
52
|
-
export { betweenThan, betweenThanOrEqual, greaterThan, greaterThanOrEqual,
|
|
50
|
+
export { betweenThan, betweenThanOrEqual, greaterThan, greaterThanOrEqual, isEven, isInteger, isMultipleOf, isNegative, isNotZero, isOdd, isPositive, isSafe, isStrictNegative, isStrictPositive, lessThan, lessThanOrEqual, max, maxOf, min, minOf, number_exports, sort, sum };
|
|
@@ -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,12 @@
|
|
|
1
|
+
const require_isSegment = require("./isSegment.cjs");
|
|
1
2
|
//#region scripts/path/getBaseName.ts
|
|
2
|
-
const baseNameRegex =
|
|
3
|
-
const extensionNameRegex =
|
|
4
|
-
const segmentTrailingRegex = /\/+$/;
|
|
3
|
+
const baseNameRegex = /([^/]+)$/;
|
|
4
|
+
const extensionNameRegex = /(?<!^)\.[^./]+$/;
|
|
5
5
|
function getBaseName(path, params) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
6
|
+
const baseName = baseNameRegex.exec(path)?.[1];
|
|
7
|
+
if (baseName === void 0) return null;
|
|
8
|
+
const result = params?.removeExtension ? baseName.replace(extensionNameRegex, "") : baseName;
|
|
9
|
+
return require_isSegment.isSegment(result) ? result : null;
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
12
|
exports.getBaseName = getBaseName;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Path } from './constraints';
|
|
1
|
+
import { Absolute, Path, Segment } 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 | Segment)>(path: GenericPath, params?: GetBaseNameParams): (string & Segment) | null;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { isSegment } from "./isSegment.mjs";
|
|
1
2
|
//#region scripts/path/getBaseName.ts
|
|
2
|
-
const baseNameRegex =
|
|
3
|
-
const extensionNameRegex =
|
|
4
|
-
const segmentTrailingRegex = /\/+$/;
|
|
3
|
+
const baseNameRegex = /([^/]+)$/;
|
|
4
|
+
const extensionNameRegex = /(?<!^)\.[^./]+$/;
|
|
5
5
|
function getBaseName(path, params) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return
|
|
6
|
+
const baseName = baseNameRegex.exec(path)?.[1];
|
|
7
|
+
if (baseName === void 0) return null;
|
|
8
|
+
const result = params?.removeExtension ? baseName.replace(extensionNameRegex, "") : baseName;
|
|
9
|
+
return isSegment(result) ? result : null;
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
12
|
export { getBaseName };
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
const require_isSegment = require("./isSegment.cjs");
|
|
1
2
|
//#region scripts/path/getExtensionName.ts
|
|
2
|
-
const
|
|
3
|
+
const basenameRegex = /([^/]+)$/;
|
|
3
4
|
function getExtensionName(path, params) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
5
|
+
const baseName = basenameRegex.exec(path)?.[1];
|
|
6
|
+
if (!baseName || baseName === "." || baseName === "..") return null;
|
|
7
|
+
const dotIndex = baseName.lastIndexOf(".");
|
|
8
|
+
if (dotIndex <= 0 || dotIndex === baseName.length - 1) return null;
|
|
9
|
+
const extension = baseName.slice(dotIndex + 1);
|
|
10
|
+
const result = params?.withDot ? `.${extension}` : extension;
|
|
11
|
+
return require_isSegment.isSegment(result) ? result : null;
|
|
7
12
|
}
|
|
8
13
|
//#endregion
|
|
9
14
|
exports.getExtensionName = getExtensionName;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Path } from './constraints';
|
|
1
|
+
import { Absolute, Path, Segment } 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 | Segment)>(path: GenericPath, params?: GetExtensionNameParams): (string & Segment) | null;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { isSegment } from "./isSegment.mjs";
|
|
1
2
|
//#region scripts/path/getExtensionName.ts
|
|
2
|
-
const
|
|
3
|
+
const basenameRegex = /([^/]+)$/;
|
|
3
4
|
function getExtensionName(path, params) {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
6
|
-
|
|
5
|
+
const baseName = basenameRegex.exec(path)?.[1];
|
|
6
|
+
if (!baseName || baseName === "." || baseName === "..") return null;
|
|
7
|
+
const dotIndex = baseName.lastIndexOf(".");
|
|
8
|
+
if (dotIndex <= 0 || dotIndex === baseName.length - 1) return null;
|
|
9
|
+
const extension = baseName.slice(dotIndex + 1);
|
|
10
|
+
const result = params?.withDot ? `.${extension}` : extension;
|
|
11
|
+
return isSegment(result) ? result : null;
|
|
7
12
|
}
|
|
8
13
|
//#endregion
|
|
9
14
|
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,36 @@
|
|
|
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");
|
|
3
|
+
const require_isSegment = require("./isSegment.cjs");
|
|
4
4
|
const require_getBaseName = require("./getBaseName.cjs");
|
|
5
5
|
const require_getExtensionName = require("./getExtensionName.cjs");
|
|
6
6
|
const require_getParentFolderPath = require("./getParentFolderPath.cjs");
|
|
7
7
|
const require_is = require("./is.cjs");
|
|
8
8
|
const require_isAbsolute = require("./isAbsolute.cjs");
|
|
9
|
+
const require_normalize = require("./normalize.cjs");
|
|
9
10
|
const require_resolveRelative = require("./resolveRelative.cjs");
|
|
10
11
|
const require_resolveFrom = require("./resolveFrom.cjs");
|
|
11
12
|
//#region scripts/path/index.ts
|
|
12
13
|
var path_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
13
14
|
computeRelative: () => require_computeRelative.computeRelative,
|
|
14
|
-
fix: () => require_fix.fix,
|
|
15
15
|
getBaseName: () => require_getBaseName.getBaseName,
|
|
16
16
|
getExtensionName: () => require_getExtensionName.getExtensionName,
|
|
17
17
|
getParentFolderPath: () => require_getParentFolderPath.getParentFolderPath,
|
|
18
18
|
is: () => require_is.is,
|
|
19
19
|
isAbsolute: () => require_isAbsolute.isAbsolute,
|
|
20
|
+
isSegment: () => require_isSegment.isSegment,
|
|
21
|
+
normalize: () => require_normalize.normalize,
|
|
20
22
|
resolveFrom: () => require_resolveFrom.resolveFrom,
|
|
21
23
|
resolveRelative: () => require_resolveRelative.resolveRelative
|
|
22
24
|
});
|
|
23
25
|
//#endregion
|
|
24
26
|
exports.computeRelative = require_computeRelative.computeRelative;
|
|
25
|
-
exports.fix = require_fix.fix;
|
|
26
27
|
exports.getBaseName = require_getBaseName.getBaseName;
|
|
27
28
|
exports.getExtensionName = require_getExtensionName.getExtensionName;
|
|
28
29
|
exports.getParentFolderPath = require_getParentFolderPath.getParentFolderPath;
|
|
29
30
|
exports.is = require_is.is;
|
|
30
31
|
exports.isAbsolute = require_isAbsolute.isAbsolute;
|
|
32
|
+
exports.isSegment = require_isSegment.isSegment;
|
|
33
|
+
exports.normalize = require_normalize.normalize;
|
|
31
34
|
Object.defineProperty(exports, "path_exports", {
|
|
32
35
|
enumerable: true,
|
|
33
36
|
get: function() {
|
package/dist/path/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
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 './isSegment';
|
|
9
|
+
export * from './normalize';
|
|
9
10
|
export * from './resolveFrom';
|
|
10
11
|
export * from './resolveRelative';
|
|
11
12
|
export type * from './types';
|
package/dist/path/index.mjs
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { __exportAll } from "../_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { fix } from "./fix.mjs";
|
|
3
2
|
import { computeRelative } from "./computeRelative.mjs";
|
|
3
|
+
import { isSegment } from "./isSegment.mjs";
|
|
4
4
|
import { getBaseName } from "./getBaseName.mjs";
|
|
5
5
|
import { getExtensionName } from "./getExtensionName.mjs";
|
|
6
6
|
import { getParentFolderPath } from "./getParentFolderPath.mjs";
|
|
7
7
|
import { is } from "./is.mjs";
|
|
8
8
|
import { isAbsolute } from "./isAbsolute.mjs";
|
|
9
|
+
import { normalize } from "./normalize.mjs";
|
|
9
10
|
import { resolveRelative } from "./resolveRelative.mjs";
|
|
10
11
|
import { resolveFrom } from "./resolveFrom.mjs";
|
|
11
12
|
//#region scripts/path/index.ts
|
|
12
13
|
var path_exports = /* @__PURE__ */ __exportAll({
|
|
13
14
|
computeRelative: () => computeRelative,
|
|
14
|
-
fix: () => fix,
|
|
15
15
|
getBaseName: () => getBaseName,
|
|
16
16
|
getExtensionName: () => getExtensionName,
|
|
17
17
|
getParentFolderPath: () => getParentFolderPath,
|
|
18
18
|
is: () => is,
|
|
19
19
|
isAbsolute: () => isAbsolute,
|
|
20
|
+
isSegment: () => isSegment,
|
|
21
|
+
normalize: () => normalize,
|
|
20
22
|
resolveFrom: () => resolveFrom,
|
|
21
23
|
resolveRelative: () => resolveRelative
|
|
22
24
|
});
|
|
23
25
|
//#endregion
|
|
24
|
-
export { computeRelative,
|
|
26
|
+
export { computeRelative, getBaseName, getExtensionName, getParentFolderPath, is, isAbsolute, isSegment, 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,4 @@
|
|
|
1
|
+
import { Segment } from './constraints';
|
|
2
|
+
import { IsLiteralSegmentPath } from './types';
|
|
3
|
+
import type * as DString from '../string';
|
|
4
|
+
export declare function isSegment<GenericValue extends string>(value: GenericValue): value is (GenericValue extends Segment ? GenericValue : IsLiteralSegmentPath<GenericValue> extends true ? GenericValue : DString.IsLiteral<GenericValue> extends true ? never : GenericValue & Segment);
|
|
@@ -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
|
-
import { Absolute, Path } from './constraints';
|
|
1
|
+
import { Absolute, Path, Segment } 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 | Segment))[], 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;
|