@duplojs/utils 1.4.40 → 1.4.42

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.
Files changed (40) hide show
  1. package/dist/array/types/index.d.ts +1 -1
  2. package/dist/clean/constraint/base.d.ts +1 -1
  3. package/dist/clean/entity.d.ts +1 -1
  4. package/dist/clean/newType.d.ts +1 -1
  5. package/dist/clean/primitive/base.d.ts +1 -1
  6. package/dist/common/asserts.d.ts +1 -1
  7. package/dist/common/builder.d.ts +1 -1
  8. package/dist/common/index.d.ts +1 -0
  9. package/dist/common/kind.d.ts +1 -1
  10. package/dist/common/path/getBaseName.cjs +25 -0
  11. package/dist/common/path/getBaseName.d.ts +26 -0
  12. package/dist/common/path/getBaseName.mjs +23 -0
  13. package/dist/common/path/getExtensionName.cjs +17 -0
  14. package/dist/common/path/getExtensionName.d.ts +21 -0
  15. package/dist/common/path/getExtensionName.mjs +15 -0
  16. package/dist/common/path/getParentFolderPath.cjs +21 -0
  17. package/dist/common/path/getParentFolderPath.d.ts +23 -0
  18. package/dist/common/path/getParentFolderPath.mjs +19 -0
  19. package/dist/common/path/index.cjs +19 -0
  20. package/dist/common/path/index.d.ts +27 -0
  21. package/dist/common/path/index.mjs +10 -0
  22. package/dist/common/path/isAbsolute.cjs +15 -0
  23. package/dist/common/path/isAbsolute.d.ts +21 -0
  24. package/dist/common/path/isAbsolute.mjs +13 -0
  25. package/dist/common/path/resolveFrom.cjs +18 -0
  26. package/dist/common/path/resolveFrom.d.ts +27 -0
  27. package/dist/common/path/resolveFrom.mjs +16 -0
  28. package/dist/common/path/resolveRelative.cjs +51 -0
  29. package/dist/common/path/resolveRelative.d.ts +23 -0
  30. package/dist/common/path/resolveRelative.mjs +49 -0
  31. package/dist/common/stringToBytes.d.ts +1 -1
  32. package/dist/common/stringToMillisecond.d.ts +1 -1
  33. package/dist/date/createOrThrow.d.ts +1 -1
  34. package/dist/date/createTimeOrThrow.d.ts +1 -1
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.mjs +2 -0
  37. package/dist/metadata.json +69 -1
  38. package/dist/pattern/match/builder.d.ts +1 -1
  39. package/package.json +1 -1
  40. /package/dist/array/types/{ArrayCoalescing.d.ts → arrayCoalescing.d.ts} +0 -0
@@ -7,5 +7,5 @@ export * from "./mergeUnionTuple";
7
7
  export * from "./extractTuple";
8
8
  export * from "./excludeTuple";
9
9
  export * from "./createTuple";
10
- export * from "./ArrayCoalescing";
10
+ export * from "./arrayCoalescing";
11
11
  export * from "./joinTuple";
@@ -79,7 +79,7 @@ export interface ConstraintHandler<GenericName extends string = string, GenericP
79
79
  }
80
80
  declare const CreateConstrainedTypeError_base: new (params: {
81
81
  "@DuplojsUtilsError/create-constrained-type-error"?: unknown;
82
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../..").KindDefinition<"create-constrained-type-error", unknown>, unknown> & Kind<import("../..").KindDefinition<"@DuplojsUtilsError/create-constrained-type-error", unknown>, unknown>;
82
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../..").KindDefinition<"create-constrained-type-error", unknown>, unknown> & Kind<import("../..").KindDefinition<"@DuplojsUtilsError/create-constrained-type-error", unknown>, unknown>;
83
83
  export declare class CreateConstrainedTypeError extends CreateConstrainedTypeError_base {
84
84
  constrainedTypeName: string;
85
85
  data: unknown;
@@ -115,7 +115,7 @@ export interface EntityHandler<GenericName extends string = string, GenericPrope
115
115
  }
116
116
  declare const CreateEntityError_base: new (params: {
117
117
  "@DuplojsUtilsError/create-entity-error"?: unknown;
118
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../common").KindDefinition<"create-entity-error", unknown>, unknown> & Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-entity-error", unknown>, unknown>;
118
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../common").KindDefinition<"create-entity-error", unknown>, unknown> & Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-entity-error", unknown>, unknown>;
119
119
  export declare class CreateEntityError extends CreateEntityError_base {
120
120
  rawProperties: EntityRawProperties;
121
121
  dataParserError: DDataParser.DataParserError;
@@ -87,7 +87,7 @@ export interface NewTypeHandler<GenericName extends string = string, GenericValu
87
87
  }
88
88
  declare const CreateNewTypeError_base: new (params: {
89
89
  "@DuplojsUtilsError/create-new-type-error"?: unknown;
90
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("..").KindDefinition<"create-new-type-error", unknown>, unknown> & Kind<import("..").KindDefinition<"@DuplojsUtilsError/create-new-type-error", unknown>, unknown>;
90
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("..").KindDefinition<"create-new-type-error", unknown>, unknown> & Kind<import("..").KindDefinition<"@DuplojsUtilsError/create-new-type-error", unknown>, unknown>;
91
91
  export declare class CreateNewTypeError extends CreateNewTypeError_base {
92
92
  newTypeName: string;
93
93
  data: unknown;
@@ -67,7 +67,7 @@ export interface PrimitiveHandler<GenericValue extends EligiblePrimitive = Eligi
67
67
  }
68
68
  declare const CreatePrimitiveError_base: new (params: {
69
69
  "@DuplojsUtilsError/create-primitive-error"?: unknown;
70
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../../common").KindDefinition<"create-primitive-error", unknown>, unknown> & Kind<import("../../common").KindDefinition<"@DuplojsUtilsError/create-primitive-error", unknown>, unknown>;
70
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("../../common").KindDefinition<"create-primitive-error", unknown>, unknown> & Kind<import("../../common").KindDefinition<"@DuplojsUtilsError/create-primitive-error", unknown>, unknown>;
71
71
  export declare class CreatePrimitiveError extends CreatePrimitiveError_base {
72
72
  data: unknown;
73
73
  dataParserError: DDataParser.DataParserError;
@@ -1,6 +1,6 @@
1
1
  declare const AssertsError_base: new (params: {
2
2
  "@DuplojsUtilsError/asserts-error"?: unknown;
3
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("./kind").Kind<import("./kind").KindDefinition<"asserts-error", unknown>, unknown> & import("./kind").Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/asserts-error", unknown>, unknown>;
3
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("./kind").Kind<import("./kind").KindDefinition<"asserts-error", unknown>, unknown> & import("./kind").Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/asserts-error", unknown>, unknown>;
4
4
  export declare class AssertsError extends AssertsError_base {
5
5
  value: unknown;
6
6
  constructor(value: unknown);
@@ -25,7 +25,7 @@ export interface BuilderHandler<GenericBuilder extends Builder = Builder> {
25
25
  }
26
26
  declare const MissingBuilderMethodsError_base: new (params: {
27
27
  "@DuplojsUtilsError/missing-builder-methods-error"?: unknown;
28
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/missing-builder-methods-error", unknown>, unknown> & Kind<import("./kind").KindDefinition<"missing-builder-methods-error", unknown>, unknown>;
28
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/missing-builder-methods-error", unknown>, unknown> & Kind<import("./kind").KindDefinition<"missing-builder-methods-error", unknown>, unknown>;
29
29
  export declare class MissingBuilderMethodsError extends MissingBuilderMethodsError_base {
30
30
  method: string;
31
31
  constructor(method: string);
@@ -72,3 +72,4 @@ export * from "./hasKinds";
72
72
  export * from "./toCurriedPredicate";
73
73
  export * from "./pipeCall";
74
74
  export * from "./asserts";
75
+ export * as Path from "./path";
@@ -141,6 +141,6 @@ export declare function createKindNamespace<GenericNamespace extends string>(nam
141
141
  export type KindHeritageConstructorParams<GenericKindHandler extends KindHandler> = {
142
142
  [KindHandler in GenericKindHandler as KindHandler["definition"]["name"]]: KindHandler["definition"]["value"];
143
143
  } extends infer InferredResult extends object ? PartialKeys<InferredResult, GetPropsWithValue<InferredResult, unknown>> : never;
144
- export declare function kindHeritage<GenericUniqueName extends string, GenericKindHandler extends KindHandler, GenericParent extends AnyConstructor = AnyConstructor<unknown[], never>>(uniqueName: GenericUniqueName & ForbiddenKindCharacters<GenericUniqueName>, kind: GenericKindHandler | GenericKindHandler[], parent?: GenericParent): new (...args: And<[IsEqual<GenericKindHandler extends KindHandler ? IsEqual<GenericKindHandler["definition"]["value"], unknown> : never, true>, IsEqual<InstanceType<GenericParent>, never>]> extends true ? [params?: KindHeritageConstructorParams<GenericKindHandler>] : [params: KindHeritageConstructorParams<GenericKindHandler>, ...parentArgs: IsEqual<ConstructorParameters<GenericParent>, unknown[]> extends true ? [parentParams?: ConstructorParameters<GenericParent>] : [parentParams: ConstructorParameters<GenericParent>]]) => UnionToIntersection<(GenericKindHandler extends KindHandler ? Kind<GenericKindHandler["definition"]> : never) | Kind<KindDefinition<GenericUniqueName, unknown>> | InstanceType<GenericParent>>;
144
+ export declare function kindHeritage<GenericUniqueName extends string, GenericKindHandler extends KindHandler, GenericParent extends AnyConstructor = AnyConstructor<unknown[], never>>(uniqueName: GenericUniqueName & ForbiddenKindCharacters<GenericUniqueName>, kind: GenericKindHandler | GenericKindHandler[], parent?: GenericParent): new (...args: And<[IsEqual<GenericKindHandler extends KindHandler ? IsEqual<GenericKindHandler["definition"]["value"], unknown> : never, true>, IsEqual<InstanceType<GenericParent>, never>]> extends true ? [params?: KindHeritageConstructorParams<GenericKindHandler>] : [params: KindHeritageConstructorParams<GenericKindHandler>, ...parentArgs: IsEqual<ConstructorParameters<GenericParent>, unknown[]> extends true ? [parentParams?: readonly [...ConstructorParameters<GenericParent>]] : [parentParams: readonly [...ConstructorParameters<GenericParent>]]]) => UnionToIntersection<(GenericKindHandler extends KindHandler ? Kind<GenericKindHandler["definition"]> : never) | Kind<KindDefinition<GenericUniqueName, unknown>> | InstanceType<GenericParent>>;
145
145
  export declare function isRuntimeKind(value: string): boolean;
146
146
  export {};
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var split = require('../../string/split.cjs');
4
+ var findLast = require('../../array/findLast.cjs');
5
+ var length = require('../../string/length.cjs');
6
+ var endsWith = require('../../string/endsWith.cjs');
7
+ var slice = require('../../string/slice.cjs');
8
+
9
+ /**
10
+ * {@include common/path/getBaseName/index.md}
11
+ */
12
+ function getBaseName(path, params) {
13
+ const segments = split.split(path, "/");
14
+ const lastSegment = findLast.findLast(segments, (value) => length.length(value) > 0) ?? null;
15
+ if (!lastSegment || lastSegment === "..") {
16
+ return null;
17
+ }
18
+ if (params?.extension && endsWith.endsWith(lastSegment, params?.extension)) {
19
+ const extensionLength = length.length(params.extension);
20
+ return slice.slice(lastSegment, 0, -extensionLength);
21
+ }
22
+ return lastSegment;
23
+ }
24
+
25
+ exports.getBaseName = getBaseName;
@@ -0,0 +1,26 @@
1
+ interface GetBaseNameParams {
2
+ extension?: string;
3
+ }
4
+ /**
5
+ * Returns the last non-empty segment of a path, optionally without an extension.
6
+ *
7
+ * **Supported call styles:**
8
+ * - Classic: `getBaseName(path, params?)` -> returns the base name or null
9
+ *
10
+ * It ignores trailing slashes and returns null when the path has no segment or when the last segment is `..`.
11
+ * When an extension is provided, it is removed only if it matches the end of the base name.
12
+ *
13
+ * ```ts
14
+ * const defaultResult = Path.getBaseName("/foo/bar.txt");
15
+ * // defaultResult: "bar.txt"
16
+ * const withoutExtResult = Path.getBaseName("/foo/bar.txt", { extension: ".txt" });
17
+ * // withoutExtResult: "bar"
18
+ * const nullResult = Path.getBaseName("..");
19
+ * // nullResult: null
20
+ * ```
21
+ *
22
+ * @see https://utils.duplojs.dev/en/v1/api/common/path/getBaseName
23
+ *
24
+ */
25
+ export declare function getBaseName<GenericPath extends string>(path: GenericPath, params?: GetBaseNameParams): string | null;
26
+ export {};
@@ -0,0 +1,23 @@
1
+ import { split } from '../../string/split.mjs';
2
+ import { findLast } from '../../array/findLast.mjs';
3
+ import { length } from '../../string/length.mjs';
4
+ import { endsWith } from '../../string/endsWith.mjs';
5
+ import { slice } from '../../string/slice.mjs';
6
+
7
+ /**
8
+ * {@include common/path/getBaseName/index.md}
9
+ */
10
+ function getBaseName(path, params) {
11
+ const segments = split(path, "/");
12
+ const lastSegment = findLast(segments, (value) => length(value) > 0) ?? null;
13
+ if (!lastSegment || lastSegment === "..") {
14
+ return null;
15
+ }
16
+ if (params?.extension && endsWith(lastSegment, params?.extension)) {
17
+ const extensionLength = length(params.extension);
18
+ return slice(lastSegment, 0, -extensionLength);
19
+ }
20
+ return lastSegment;
21
+ }
22
+
23
+ export { getBaseName };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var minElements = require('../../array/minElements.cjs');
4
+
5
+ const extensionNameRegex = /\.([^./]+)$/;
6
+ /**
7
+ * {@include common/path/getExtensionName/index.md}
8
+ */
9
+ function getExtensionName(path) {
10
+ const match = extensionNameRegex.exec(path);
11
+ if (!!match && minElements.minElements(match, 2)) {
12
+ return match[1];
13
+ }
14
+ return null;
15
+ }
16
+
17
+ exports.getExtensionName = getExtensionName;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Returns the last extension of a path, without the leading dot.
3
+ *
4
+ * **Supported call styles:**
5
+ * - Classic: `getExtensionName(path)` -> returns the extension or null
6
+ *
7
+ * It returns null when no extension is found, when the path ends with a dot, or when the path is `..`.
8
+ *
9
+ * ```ts
10
+ * const txtResult = Path.getExtensionName("/foo/bar.txt");
11
+ * // txtResult: "txt"
12
+ * const tarResult = Path.getExtensionName("archive.tar.gz");
13
+ * // tarResult: "gz"
14
+ * const dotResult = Path.getExtensionName("file.");
15
+ * // dotResult: null
16
+ * ```
17
+ *
18
+ * @see https://utils.duplojs.dev/en/v1/api/common/path/getExtensionName
19
+ *
20
+ */
21
+ export declare function getExtensionName<GenericPath extends string>(path: GenericPath): string | null;
@@ -0,0 +1,15 @@
1
+ import { minElements } from '../../array/minElements.mjs';
2
+
3
+ const extensionNameRegex = /\.([^./]+)$/;
4
+ /**
5
+ * {@include common/path/getExtensionName/index.md}
6
+ */
7
+ function getExtensionName(path) {
8
+ const match = extensionNameRegex.exec(path);
9
+ if (!!match && minElements(match, 2)) {
10
+ return match[1];
11
+ }
12
+ return null;
13
+ }
14
+
15
+ export { getExtensionName };
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ var pipe = require('../pipe.cjs');
4
+ var isAbsolute = require('./isAbsolute.cjs');
5
+ var slice = require('../../array/slice.cjs');
6
+ var split = require('../../string/split.cjs');
7
+ var replace = require('../../string/replace.cjs');
8
+ var join = require('../../array/join.cjs');
9
+
10
+ /**
11
+ * {@include common/path/getParentFolderPath/index.md}
12
+ */
13
+ function getParentFolderPath(path) {
14
+ const segments = pipe.pipe(path, replace.replace(/\/$/, ""), split.split("/"), slice.slice(0, -1));
15
+ return join.join(segments, "/")
16
+ || (isAbsolute.isAbsolute(path)
17
+ ? "/"
18
+ : ".");
19
+ }
20
+
21
+ exports.getParentFolderPath = getParentFolderPath;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Returns the parent folder path of a POSIX path.
3
+ *
4
+ * **Supported call styles:**
5
+ * - Classic: `getParentFolderPath(path)` -> returns the parent folder
6
+ *
7
+ * It removes a trailing slash, drops the last segment, and falls back to `/` for absolute paths or `.` for relative paths when needed.
8
+ *
9
+ * ```ts
10
+ * const result = Path.getParentFolderPath("/foo/bar/baz");
11
+ * // result: "/foo/bar"
12
+ * const trailingResult = Path.getParentFolderPath("/foo/bar/");
13
+ * // trailingResult: "/foo"
14
+ * const relativeResult = Path.getParentFolderPath("foo");
15
+ * // relativeResult: "."
16
+ * const absoluteResult = Path.getParentFolderPath("/foo");
17
+ * // absoluteResult: "/"
18
+ * ```
19
+ *
20
+ * @see https://utils.duplojs.dev/en/v1/api/common/path/getParentFolderPath
21
+ *
22
+ */
23
+ export declare function getParentFolderPath<GenericPath extends string>(path: GenericPath): string;
@@ -0,0 +1,19 @@
1
+ import { pipe } from '../pipe.mjs';
2
+ import { isAbsolute } from './isAbsolute.mjs';
3
+ import { slice } from '../../array/slice.mjs';
4
+ import { split } from '../../string/split.mjs';
5
+ import { replace } from '../../string/replace.mjs';
6
+ import { join } from '../../array/join.mjs';
7
+
8
+ /**
9
+ * {@include common/path/getParentFolderPath/index.md}
10
+ */
11
+ function getParentFolderPath(path) {
12
+ const segments = pipe(path, replace(/\/$/, ""), split("/"), slice(0, -1));
13
+ return join(segments, "/")
14
+ || (isAbsolute(path)
15
+ ? "/"
16
+ : ".");
17
+ }
18
+
19
+ export { getParentFolderPath };
@@ -0,0 +1,19 @@
1
+ 'use strict';
2
+
3
+ var isAbsolute = require('./isAbsolute.cjs');
4
+ var getParentFolderPath = require('./getParentFolderPath.cjs');
5
+ var getBaseName = require('./getBaseName.cjs');
6
+ var getExtensionName = require('./getExtensionName.cjs');
7
+ var resolveFrom = require('./resolveFrom.cjs');
8
+ var resolveRelative = require('./resolveRelative.cjs');
9
+
10
+ /**
11
+ * {@include common/path/index.md}
12
+ */
13
+
14
+ exports.isAbsolute = isAbsolute.isAbsolute;
15
+ exports.getParentFolderPath = getParentFolderPath.getParentFolderPath;
16
+ exports.getBaseName = getBaseName.getBaseName;
17
+ exports.getExtensionName = getExtensionName.getExtensionName;
18
+ exports.resolveFrom = resolveFrom.resolveFrom;
19
+ exports.resolveRelative = resolveRelative.resolveRelative;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Path utilities to resolve and inspect POSIX paths.
3
+ * They preserve input strings and return new values.
4
+ *
5
+ * **How to import:**
6
+ * - From the main common namespace
7
+ * - Via direct import for tree-shaking
8
+ *
9
+ * ```ts
10
+ * import { Path } from "@duplojs/utils";
11
+ * import * as Path from "@duplojs/utils/common/path";
12
+ * ```
13
+ *
14
+ * What you will find in this namespace:
15
+ * - checks (`Path.isAbsolute`)
16
+ * - resolution (`Path.resolveFrom`, `Path.resolveRelative`)
17
+ * - path parsing (`Path.getParentFolderPath`, `Path.getBaseName`, `Path.getExtensionName`)
18
+ *
19
+ * @see https://utils.duplojs.dev/en/v1/api/common/path
20
+ *
21
+ */
22
+ export * from "./isAbsolute";
23
+ export * from "./getParentFolderPath";
24
+ export * from "./getBaseName";
25
+ export * from "./getExtensionName";
26
+ export * from "./resolveFrom";
27
+ export * from "./resolveRelative";
@@ -0,0 +1,10 @@
1
+ export { isAbsolute } from './isAbsolute.mjs';
2
+ export { getParentFolderPath } from './getParentFolderPath.mjs';
3
+ export { getBaseName } from './getBaseName.mjs';
4
+ export { getExtensionName } from './getExtensionName.mjs';
5
+ export { resolveFrom } from './resolveFrom.mjs';
6
+ export { resolveRelative } from './resolveRelative.mjs';
7
+
8
+ /**
9
+ * {@include common/path/index.md}
10
+ */
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var startsWith = require('../../string/startsWith.cjs');
4
+ var test = require('../../string/test.cjs');
5
+
6
+ const isRelativeRegex = /(^|\/)\.\.(?=\/|$)/;
7
+ /**
8
+ * {@include common/path/isAbsolute/index.md}
9
+ */
10
+ function isAbsolute(path) {
11
+ return startsWith.startsWith(path, "/")
12
+ && !test.test(path, isRelativeRegex);
13
+ }
14
+
15
+ exports.isAbsolute = isAbsolute;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Checks whether a path is absolute (POSIX).
3
+ *
4
+ * **Supported call styles:**
5
+ * - Classic: `isAbsolute(path)` -> returns a boolean
6
+ *
7
+ * It returns true when the path starts with `/` and does not contain `..` segments.
8
+ *
9
+ * ```ts
10
+ * const absolutePath = Path.isAbsolute("/var/log");
11
+ * // absolutePath: true
12
+ * const parentTraversal = Path.isAbsolute("/var/../log");
13
+ * // parentTraversal: false
14
+ * const relativePath = Path.isAbsolute("var/log");
15
+ * // relativePath: false
16
+ * ```
17
+ *
18
+ * @see https://utils.duplojs.dev/en/v1/api/common/path/isAbsolute
19
+ *
20
+ */
21
+ export declare function isAbsolute<GenericPath extends string>(path: GenericPath): boolean;
@@ -0,0 +1,13 @@
1
+ import { startsWith } from '../../string/startsWith.mjs';
2
+ import { test } from '../../string/test.mjs';
3
+
4
+ const isRelativeRegex = /(^|\/)\.\.(?=\/|$)/;
5
+ /**
6
+ * {@include common/path/isAbsolute/index.md}
7
+ */
8
+ function isAbsolute(path) {
9
+ return startsWith(path, "/")
10
+ && !test(path, isRelativeRegex);
11
+ }
12
+
13
+ export { isAbsolute };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ var isAbsolute = require('./isAbsolute.cjs');
4
+ var resolveRelative = require('./resolveRelative.cjs');
5
+ var success = require('../../either/right/success.cjs');
6
+ var fail = require('../../either/left/fail.cjs');
7
+
8
+ /**
9
+ * {@include common/path/resolveFrom/index.md}
10
+ */
11
+ function resolveFrom(origin, segments) {
12
+ const result = resolveRelative.resolveRelative([origin, ...segments]);
13
+ return isAbsolute.isAbsolute(result)
14
+ ? success.success(result)
15
+ : fail.fail();
16
+ }
17
+
18
+ exports.resolveFrom = resolveFrom;
@@ -0,0 +1,27 @@
1
+ import * as DEither from "../../either";
2
+ import type { AnyTuple } from "../types";
3
+ /**
4
+ * Resolves a list of path segments from an origin and returns an Either.
5
+ *
6
+ * **Supported call styles:**
7
+ * - Classic: `resolveFrom(origin, segments)` -> returns an Either
8
+ *
9
+ * Segments are resolved in order using `resolveRelative`.
10
+ * The result is an `Either` that is `success` only when the resolved path is absolute; otherwise it returns `fail`.
11
+ *
12
+ * ```ts
13
+ * const absoluteResult = Path.resolveFrom("/root", ["alpha", "beta"]);
14
+ * // absoluteResult: DEither.success<"/root/alpha/beta">
15
+ * const result = unwrap(absoluteResult);
16
+ * // result: "/root/alpha/beta"
17
+ *
18
+ * const overrideResult = Path.resolveFrom("gamma", ["alpha", "/root", "beta"]);
19
+ * // overrideResult: DEither.success<"/root/beta">
20
+ * const relativeResult = Path.resolveFrom("alpha", ["..", ".."]);
21
+ * // relativeResult: DEither.fail
22
+ * ```
23
+ *
24
+ * @see https://utils.duplojs.dev/en/v1/api/common/path/resolveFrom
25
+ *
26
+ */
27
+ export declare function resolveFrom<GenericSegment extends string>(origin: string, segments: AnyTuple<GenericSegment>): DEither.EitherFail | DEither.EitherSuccess<string>;
@@ -0,0 +1,16 @@
1
+ import { isAbsolute } from './isAbsolute.mjs';
2
+ import { resolveRelative } from './resolveRelative.mjs';
3
+ import { success } from '../../either/right/success.mjs';
4
+ import { fail } from '../../either/left/fail.mjs';
5
+
6
+ /**
7
+ * {@include common/path/resolveFrom/index.md}
8
+ */
9
+ function resolveFrom(origin, segments) {
10
+ const result = resolveRelative([origin, ...segments]);
11
+ return isAbsolute(result)
12
+ ? success(result)
13
+ : fail();
14
+ }
15
+
16
+ export { resolveFrom };
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ const segmentTrailingRegex = /\/$/;
4
+ const segmentRelativeRegex = /^(.\/)/;
5
+ /**
6
+ * {@include common/path/resolveRelative/index.md}
7
+ */
8
+ function resolveRelative(segments) {
9
+ let clearedPath = "";
10
+ for (const segment of segments) {
11
+ if (segment.length === 0) {
12
+ continue;
13
+ }
14
+ if (segment === "/") {
15
+ clearedPath = segment;
16
+ continue;
17
+ }
18
+ const formattedSegment = segment
19
+ .replace(segmentTrailingRegex, "")
20
+ .replace(segmentRelativeRegex, "");
21
+ if (formattedSegment.startsWith("/")) {
22
+ clearedPath = formattedSegment;
23
+ continue;
24
+ }
25
+ if (clearedPath === "/") {
26
+ clearedPath += formattedSegment;
27
+ }
28
+ else {
29
+ clearedPath += `/${formattedSegment}`;
30
+ }
31
+ }
32
+ const dotResult = [];
33
+ const result = [];
34
+ for (const element of clearedPath.split("/")) {
35
+ if (element === "..") {
36
+ const deletedElement = result.pop();
37
+ if (!deletedElement) {
38
+ dotResult.push(element);
39
+ }
40
+ }
41
+ else {
42
+ result.push(element);
43
+ }
44
+ }
45
+ if (dotResult.length === 0) {
46
+ return result.join("/");
47
+ }
48
+ return `${dotResult.join("/")}/${result.join("/")}`;
49
+ }
50
+
51
+ exports.resolveRelative = resolveRelative;
@@ -0,0 +1,23 @@
1
+ import type { AnyTuple } from "../types";
2
+ /**
3
+ * Resolves path segments into a single POSIX-like path.
4
+ *
5
+ * **Supported call styles:**
6
+ * - Classic: `resolveRelative(segments)` -> returns the resolved path
7
+ *
8
+ * Empty segments are ignored, trailing slashes and leading `./` are removed, and absolute segments reset the base.
9
+ * `..` segments remove previous segments and may remain leading when resolving above root.
10
+ *
11
+ * ```ts
12
+ * const basicResult = Path.resolveRelative(["alpha", "beta"]);
13
+ * // basicResult: "/alpha/beta"
14
+ * const overrideResult = Path.resolveRelative(["alpha", "/root", "beta"]);
15
+ * // overrideResult: "/root/beta"
16
+ * const parentResult = Path.resolveRelative(["alpha", "..", "..", "beta"]);
17
+ * // parentResult: "../beta"
18
+ * ```
19
+ *
20
+ * @see https://utils.duplojs.dev/en/v1/api/common/path/resolveRelative
21
+ *
22
+ */
23
+ export declare function resolveRelative<GenericSegment extends string>(segments: AnyTuple<GenericSegment>): string;
@@ -0,0 +1,49 @@
1
+ const segmentTrailingRegex = /\/$/;
2
+ const segmentRelativeRegex = /^(.\/)/;
3
+ /**
4
+ * {@include common/path/resolveRelative/index.md}
5
+ */
6
+ function resolveRelative(segments) {
7
+ let clearedPath = "";
8
+ for (const segment of segments) {
9
+ if (segment.length === 0) {
10
+ continue;
11
+ }
12
+ if (segment === "/") {
13
+ clearedPath = segment;
14
+ continue;
15
+ }
16
+ const formattedSegment = segment
17
+ .replace(segmentTrailingRegex, "")
18
+ .replace(segmentRelativeRegex, "");
19
+ if (formattedSegment.startsWith("/")) {
20
+ clearedPath = formattedSegment;
21
+ continue;
22
+ }
23
+ if (clearedPath === "/") {
24
+ clearedPath += formattedSegment;
25
+ }
26
+ else {
27
+ clearedPath += `/${formattedSegment}`;
28
+ }
29
+ }
30
+ const dotResult = [];
31
+ const result = [];
32
+ for (const element of clearedPath.split("/")) {
33
+ if (element === "..") {
34
+ const deletedElement = result.pop();
35
+ if (!deletedElement) {
36
+ dotResult.push(element);
37
+ }
38
+ }
39
+ else {
40
+ result.push(element);
41
+ }
42
+ }
43
+ if (dotResult.length === 0) {
44
+ return result.join("/");
45
+ }
46
+ return `${dotResult.join("/")}/${result.join("/")}`;
47
+ }
48
+
49
+ export { resolveRelative };
@@ -1,6 +1,6 @@
1
1
  declare const InvalidBytesInStringError_base: new (params: {
2
2
  "@DuplojsUtilsError/missing-builder-methods-error"?: unknown;
3
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("./kind").Kind<import("./kind").KindDefinition<"invalid-bytes-in-string-error", unknown>, unknown> & import("./kind").Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/missing-builder-methods-error", unknown>, unknown>;
3
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("./kind").Kind<import("./kind").KindDefinition<"invalid-bytes-in-string-error", unknown>, unknown> & import("./kind").Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/missing-builder-methods-error", unknown>, unknown>;
4
4
  export declare class InvalidBytesInStringError extends InvalidBytesInStringError_base {
5
5
  input: string;
6
6
  constructor(input: string);
@@ -1,6 +1,6 @@
1
1
  declare const InvalidMillisecondInStringError_base: new (params: {
2
2
  "@DuplojsUtilsError/missing-builder-methods-error"?: unknown;
3
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("./kind").Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/missing-builder-methods-error", unknown>, unknown> & import("./kind").Kind<import("./kind").KindDefinition<"invalid-millisecond-in-string-error", unknown>, unknown>;
3
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("./kind").Kind<import("./kind").KindDefinition<"@DuplojsUtilsError/missing-builder-methods-error", unknown>, unknown> & import("./kind").Kind<import("./kind").KindDefinition<"invalid-millisecond-in-string-error", unknown>, unknown>;
4
4
  export declare class InvalidMillisecondInStringError extends InvalidMillisecondInStringError_base {
5
5
  input: string;
6
6
  constructor(input: string);
@@ -1,7 +1,7 @@
1
1
  import type { TheDate, SpoolingDate } from "./types";
2
2
  declare const CreateTheDateError_base: new (params: {
3
3
  "@DuplojsUtilsError/create-the-date-error"?: unknown;
4
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../common").Kind<import("../common").KindDefinition<"create-the-date-error", unknown>, unknown> & import("../common").Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-the-date-error", unknown>, unknown>;
4
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../common").Kind<import("../common").KindDefinition<"create-the-date-error", unknown>, unknown> & import("../common").Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-the-date-error", unknown>, unknown>;
5
5
  export declare class CreateTheDateError extends CreateTheDateError_base {
6
6
  input: string | Date | number | SpoolingDate;
7
7
  constructor(input: string | Date | number | SpoolingDate);
@@ -1,7 +1,7 @@
1
1
  import type { SpoolingTime, TheTime } from "./types";
2
2
  declare const CreateTheTimeError_base: new (params: {
3
3
  "@DuplojsUtilsError/create-the-time-error"?: unknown;
4
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../common").Kind<import("../common").KindDefinition<"create-the-time-error", unknown>, unknown> & import("../common").Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-the-time-error", unknown>, unknown>;
4
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../common").Kind<import("../common").KindDefinition<"create-the-time-error", unknown>, unknown> & import("../common").Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-the-time-error", unknown>, unknown>;
5
5
  export declare class CreateTheTimeError extends CreateTheTimeError_base {
6
6
  input: TheTime | number | SpoolingTime;
7
7
  constructor(input: TheTime | number | SpoolingTime);
package/dist/index.cjs CHANGED
@@ -12,6 +12,7 @@ var index$8 = require('./dataParser/parsers/coerce/index.cjs');
12
12
  var index$9 = require('./dataParser/extended/index.cjs');
13
13
  var index$a = require('./date/index.cjs');
14
14
  var index$b = require('./clean/index.cjs');
15
+ var index$c = require('./common/path/index.cjs');
15
16
  var addWrappedProperties = require('./common/addWrappedProperties.cjs');
16
17
  var asyncPipe = require('./common/asyncPipe.cjs');
17
18
  var clone = require('./common/clone.cjs');
@@ -88,6 +89,7 @@ exports.D = index$a;
88
89
  exports.DDate = index$a;
89
90
  exports.C = index$b;
90
91
  exports.DClean = index$b;
92
+ exports.Path = index$c;
91
93
  exports.addWrappedProperties = addWrappedProperties.addWrappedProperties;
92
94
  exports.asyncPipe = asyncPipe.asyncPipe;
93
95
  exports.clone = clone.clone;
package/dist/index.mjs CHANGED
@@ -34,6 +34,8 @@ export { index$a as DDate };
34
34
  import * as index$b from './clean/index.mjs';
35
35
  export { index$b as C };
36
36
  export { index$b as DClean };
37
+ import * as index$c from './common/path/index.mjs';
38
+ export { index$c as Path };
37
39
  export { addWrappedProperties } from './common/addWrappedProperties.mjs';
38
40
  export { asyncPipe } from './common/asyncPipe.mjs';
39
41
  export { clone } from './common/clone.mjs';
@@ -139,7 +139,7 @@
139
139
  "name": "types",
140
140
  "files": [
141
141
  {
142
- "name": "ArrayCoalescing.d.ts"
142
+ "name": "arrayCoalescing.d.ts"
143
143
  },
144
144
  {
145
145
  "name": "atTuple.d.ts"
@@ -999,6 +999,74 @@
999
999
  {
1000
1000
  "name": "common",
1001
1001
  "files": [
1002
+ {
1003
+ "name": "path",
1004
+ "files": [
1005
+ {
1006
+ "name": "getBaseName.cjs"
1007
+ },
1008
+ {
1009
+ "name": "getBaseName.d.ts"
1010
+ },
1011
+ {
1012
+ "name": "getBaseName.mjs"
1013
+ },
1014
+ {
1015
+ "name": "getExtensionName.cjs"
1016
+ },
1017
+ {
1018
+ "name": "getExtensionName.d.ts"
1019
+ },
1020
+ {
1021
+ "name": "getExtensionName.mjs"
1022
+ },
1023
+ {
1024
+ "name": "getParentFolderPath.cjs"
1025
+ },
1026
+ {
1027
+ "name": "getParentFolderPath.d.ts"
1028
+ },
1029
+ {
1030
+ "name": "getParentFolderPath.mjs"
1031
+ },
1032
+ {
1033
+ "name": "index.cjs"
1034
+ },
1035
+ {
1036
+ "name": "index.d.ts"
1037
+ },
1038
+ {
1039
+ "name": "index.mjs"
1040
+ },
1041
+ {
1042
+ "name": "isAbsolute.cjs"
1043
+ },
1044
+ {
1045
+ "name": "isAbsolute.d.ts"
1046
+ },
1047
+ {
1048
+ "name": "isAbsolute.mjs"
1049
+ },
1050
+ {
1051
+ "name": "resolveFrom.cjs"
1052
+ },
1053
+ {
1054
+ "name": "resolveFrom.d.ts"
1055
+ },
1056
+ {
1057
+ "name": "resolveFrom.mjs"
1058
+ },
1059
+ {
1060
+ "name": "resolveRelative.cjs"
1061
+ },
1062
+ {
1063
+ "name": "resolveRelative.d.ts"
1064
+ },
1065
+ {
1066
+ "name": "resolveRelative.mjs"
1067
+ }
1068
+ ]
1069
+ },
1002
1070
  {
1003
1071
  "name": "types",
1004
1072
  "files": [
@@ -21,7 +21,7 @@ export interface MatchBuilder<GenericValue extends unknown = never, GenericResul
21
21
  }
22
22
  declare const InvalidExhaustivePatternError_base: new (params: {
23
23
  "@DuplojsUtilsError/invalid-exhaustive-pattern-error"?: unknown;
24
- }, parentParams: [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../../common").Kind<import("../../common").KindDefinition<"invalid-exhaustive-pattern-error", unknown>, unknown> & import("../../common").Kind<import("../../common").KindDefinition<"@DuplojsUtilsError/invalid-exhaustive-pattern-error", unknown>, unknown>;
24
+ }, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../../common").Kind<import("../../common").KindDefinition<"invalid-exhaustive-pattern-error", unknown>, unknown> & import("../../common").Kind<import("../../common").KindDefinition<"@DuplojsUtilsError/invalid-exhaustive-pattern-error", unknown>, unknown>;
25
25
  export declare class InvalidExhaustivePatternError extends InvalidExhaustivePatternError_base {
26
26
  input: unknown;
27
27
  constructor(input: unknown);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duplojs/utils",
3
- "version": "1.4.40",
3
+ "version": "1.4.42",
4
4
  "author": {
5
5
  "name": "mathcovax",
6
6
  "url": "https://github.com/mathcovax"