@duplojs/utils 1.4.47 → 1.4.48
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/common/index.d.ts +2 -1
- package/dist/common/mimeType.cjs +1081 -0
- package/dist/common/mimeType.d.ts +22 -0
- package/dist/common/mimeType.mjs +1079 -0
- package/dist/common/path.cjs +114 -0
- package/dist/common/path.d.ts +145 -0
- package/dist/common/path.mjs +114 -0
- package/dist/dataParser/extended/date.d.ts +3 -3
- package/dist/dataParser/extended/time.d.ts +3 -3
- package/dist/dataParser/identifier.d.ts +16 -4
- package/dist/dataParser/parsers/date.cjs +7 -7
- package/dist/dataParser/parsers/date.d.ts +4 -4
- package/dist/dataParser/parsers/date.mjs +7 -7
- package/dist/dataParser/parsers/time/index.cjs +8 -8
- package/dist/dataParser/parsers/time/index.d.ts +4 -4
- package/dist/dataParser/parsers/time/index.mjs +8 -8
- package/dist/index.cjs +7 -2
- package/dist/index.mjs +2 -2
- package/dist/metadata.json +18 -68
- package/package.json +1 -1
- package/dist/common/path/getBaseName.cjs +0 -25
- package/dist/common/path/getBaseName.d.ts +0 -26
- package/dist/common/path/getBaseName.mjs +0 -23
- package/dist/common/path/getExtensionName.cjs +0 -17
- package/dist/common/path/getExtensionName.d.ts +0 -21
- package/dist/common/path/getExtensionName.mjs +0 -15
- package/dist/common/path/getParentFolderPath.cjs +0 -21
- package/dist/common/path/getParentFolderPath.d.ts +0 -23
- package/dist/common/path/getParentFolderPath.mjs +0 -19
- package/dist/common/path/index.cjs +0 -19
- package/dist/common/path/index.d.ts +0 -27
- package/dist/common/path/index.mjs +0 -10
- package/dist/common/path/isAbsolute.cjs +0 -15
- package/dist/common/path/isAbsolute.d.ts +0 -21
- package/dist/common/path/isAbsolute.mjs +0 -13
- package/dist/common/path/resolveFrom.cjs +0 -18
- package/dist/common/path/resolveFrom.d.ts +0 -27
- package/dist/common/path/resolveFrom.mjs +0 -16
- package/dist/common/path/resolveRelative.cjs +0 -51
- package/dist/common/path/resolveRelative.d.ts +0 -23
- package/dist/common/path/resolveRelative.mjs +0 -49
|
@@ -13,7 +13,7 @@ export interface DataParserDefinitionTime extends DataParserDefinition<DataParse
|
|
|
13
13
|
readonly coerce: boolean;
|
|
14
14
|
}
|
|
15
15
|
export declare const timeKind: import("../../../common").KindHandler<import("../../../common").KindDefinition<"@DuplojsUtilsDataParser/time", unknown>>;
|
|
16
|
-
type _DataParserTime<GenericDefinition extends DataParserDefinitionTime> = (DataParser<GenericDefinition, TheTime, TheTime> & Kind<typeof timeKind.definition>);
|
|
16
|
+
type _DataParserTime<GenericDefinition extends DataParserDefinitionTime> = (DataParser<GenericDefinition, TheTime, TheTime | number> & Kind<typeof timeKind.definition>);
|
|
17
17
|
export interface DataParserTime<GenericDefinition extends DataParserDefinitionTime = DataParserDefinitionTime> extends _DataParserTime<GenericDefinition> {
|
|
18
18
|
addChecker<GenericChecker extends readonly [
|
|
19
19
|
DataParserTimeCheckers,
|
|
@@ -24,17 +24,17 @@ export interface DataParserTime<GenericDefinition extends DataParserDefinitionTi
|
|
|
24
24
|
], GenericChecker>): DataParserTime<AddCheckersToDefinition<GenericDefinition, GenericChecker>>;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Creates a data parser for TheTime values.
|
|
27
|
+
* Creates a data parser for TheTime values or safe millisecond numbers.
|
|
28
28
|
*
|
|
29
29
|
* **Supported call styles:**
|
|
30
30
|
* - Classic: `DP.time(definition?)` -> returns a time parser
|
|
31
31
|
* - Curried: not available
|
|
32
32
|
*
|
|
33
|
-
* Validates that the input is a TheTime, optionally applies
|
|
33
|
+
* Validates that the input is a TheTime (or a safe millisecond number), optionally applies ISO string coercion, and runs the configured checkers.
|
|
34
34
|
*
|
|
35
35
|
* ```ts
|
|
36
36
|
* const parser = DP.time();
|
|
37
|
-
* const result = parser.parse(
|
|
37
|
+
* const result = parser.parse(60000);
|
|
38
38
|
* if (E.isRight(result)) {
|
|
39
39
|
* const value = unwrap(result);
|
|
40
40
|
* // value: TheTime
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { dataParserInit } from '../../base.mjs';
|
|
2
2
|
import { SymbolDataParserErrorIssue } from '../../error.mjs';
|
|
3
3
|
import { createDataParserKind } from '../../kind.mjs';
|
|
4
|
-
import { isSafeTimeValue } from '../../../date/isSafeTimeValue.mjs';
|
|
5
|
-
import { createTheTime } from '../../../date/createTheTime.mjs';
|
|
6
4
|
import { isoTimeRegex } from '../../../date/constants.mjs';
|
|
7
5
|
import { createTime } from '../../../date/createTime.mjs';
|
|
8
6
|
import { isLeft } from '../../../either/left/is.mjs';
|
|
9
7
|
import { unwrap } from '../../../common/unwrap.mjs';
|
|
10
8
|
import { isTime } from '../../../date/isTime.mjs';
|
|
9
|
+
import { isSafeTimeValue } from '../../../date/isSafeTimeValue.mjs';
|
|
10
|
+
import { createTheTime } from '../../../date/createTheTime.mjs';
|
|
11
11
|
import { createOverride } from '../../../common/override.mjs';
|
|
12
12
|
|
|
13
13
|
const timeKind = createDataParserKind("time");
|
|
@@ -21,12 +21,6 @@ function time(definition) {
|
|
|
21
21
|
coerce: definition?.coerce ?? false,
|
|
22
22
|
}, (data, _error, self) => {
|
|
23
23
|
if (self.definition.coerce) {
|
|
24
|
-
if (typeof data === "number") {
|
|
25
|
-
if (!isSafeTimeValue(data)) {
|
|
26
|
-
return SymbolDataParserErrorIssue;
|
|
27
|
-
}
|
|
28
|
-
return createTheTime(data);
|
|
29
|
-
}
|
|
30
24
|
if (typeof data === "string" && isoTimeRegex.test(data)) {
|
|
31
25
|
const result = createTime({ value: data });
|
|
32
26
|
if (isLeft(result)) {
|
|
@@ -38,6 +32,12 @@ function time(definition) {
|
|
|
38
32
|
if (typeof data === "string" && isTime(data)) {
|
|
39
33
|
return data;
|
|
40
34
|
}
|
|
35
|
+
if (typeof data === "number") {
|
|
36
|
+
if (!isSafeTimeValue(data)) {
|
|
37
|
+
return SymbolDataParserErrorIssue;
|
|
38
|
+
}
|
|
39
|
+
return createTheTime(data);
|
|
40
|
+
}
|
|
41
41
|
return SymbolDataParserErrorIssue;
|
|
42
42
|
}, time.overrideHandler);
|
|
43
43
|
return self;
|
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,6 @@ 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');
|
|
16
15
|
var addWrappedProperties = require('./common/addWrappedProperties.cjs');
|
|
17
16
|
var asyncPipe = require('./common/asyncPipe.cjs');
|
|
18
17
|
var clone = require('./common/clone.cjs');
|
|
@@ -26,6 +25,7 @@ var promiseObject = require('./common/promiseObject.cjs');
|
|
|
26
25
|
var simpleClone = require('./common/simpleClone.cjs');
|
|
27
26
|
var sleep = require('./common/sleep.cjs');
|
|
28
27
|
var stringToBytes = require('./common/stringToBytes.cjs');
|
|
28
|
+
var mimeType = require('./common/mimeType.cjs');
|
|
29
29
|
var stringToMillisecond = require('./common/stringToMillisecond.cjs');
|
|
30
30
|
var toJSON = require('./common/toJSON.cjs');
|
|
31
31
|
var toTransform = require('./common/toTransform.cjs');
|
|
@@ -62,6 +62,7 @@ var hasKinds = require('./common/hasKinds.cjs');
|
|
|
62
62
|
var toCurriedPredicate = require('./common/toCurriedPredicate.cjs');
|
|
63
63
|
var pipeCall = require('./common/pipeCall.cjs');
|
|
64
64
|
var asserts = require('./common/asserts.cjs');
|
|
65
|
+
var path = require('./common/path.cjs');
|
|
65
66
|
|
|
66
67
|
|
|
67
68
|
|
|
@@ -89,7 +90,6 @@ exports.D = index$a;
|
|
|
89
90
|
exports.DDate = index$a;
|
|
90
91
|
exports.C = index$b;
|
|
91
92
|
exports.DClean = index$b;
|
|
92
|
-
exports.Path = index$c;
|
|
93
93
|
exports.addWrappedProperties = addWrappedProperties.addWrappedProperties;
|
|
94
94
|
exports.asyncPipe = asyncPipe.asyncPipe;
|
|
95
95
|
exports.clone = clone.clone;
|
|
@@ -108,6 +108,7 @@ exports.simpleClone = simpleClone.simpleClone;
|
|
|
108
108
|
exports.sleep = sleep.sleep;
|
|
109
109
|
exports.InvalidBytesInStringError = stringToBytes.InvalidBytesInStringError;
|
|
110
110
|
exports.stringToBytes = stringToBytes.stringToBytes;
|
|
111
|
+
exports.mimeType = mimeType.mimeType;
|
|
111
112
|
exports.InvalidMillisecondInStringError = stringToMillisecond.InvalidMillisecondInStringError;
|
|
112
113
|
exports.stringToMillisecond = stringToMillisecond.stringToMillisecond;
|
|
113
114
|
exports.toJSON = toJSON.toJSON;
|
|
@@ -152,3 +153,7 @@ exports.toCurriedPredicate = toCurriedPredicate.toCurriedPredicate;
|
|
|
152
153
|
exports.pipeCall = pipeCall.pipeCall;
|
|
153
154
|
exports.AssertsError = asserts.AssertsError;
|
|
154
155
|
exports.asserts = asserts.asserts;
|
|
156
|
+
Object.defineProperty(exports, "Path", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () { return path.Path; }
|
|
159
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -34,8 +34,6 @@ 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 };
|
|
39
37
|
export { addWrappedProperties } from './common/addWrappedProperties.mjs';
|
|
40
38
|
export { asyncPipe } from './common/asyncPipe.mjs';
|
|
41
39
|
export { clone } from './common/clone.mjs';
|
|
@@ -49,6 +47,7 @@ export { promiseObject } from './common/promiseObject.mjs';
|
|
|
49
47
|
export { simpleClone } from './common/simpleClone.mjs';
|
|
50
48
|
export { sleep } from './common/sleep.mjs';
|
|
51
49
|
export { InvalidBytesInStringError, stringToBytes } from './common/stringToBytes.mjs';
|
|
50
|
+
export { mimeType } from './common/mimeType.mjs';
|
|
52
51
|
export { InvalidMillisecondInStringError, stringToMillisecond } from './common/stringToMillisecond.mjs';
|
|
53
52
|
export { toJSON } from './common/toJSON.mjs';
|
|
54
53
|
export { toTransform } from './common/toTransform.mjs';
|
|
@@ -85,3 +84,4 @@ export { hasKinds } from './common/hasKinds.mjs';
|
|
|
85
84
|
export { toCurriedPredicate } from './common/toCurriedPredicate.mjs';
|
|
86
85
|
export { pipeCall } from './common/pipeCall.mjs';
|
|
87
86
|
export { AssertsError, asserts } from './common/asserts.mjs';
|
|
87
|
+
export { Path } from './common/path.mjs';
|
package/dist/metadata.json
CHANGED
|
@@ -999,74 +999,6 @@
|
|
|
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
|
-
},
|
|
1070
1002
|
{
|
|
1071
1003
|
"name": "types",
|
|
1072
1004
|
"files": [
|
|
@@ -1483,6 +1415,15 @@
|
|
|
1483
1415
|
{
|
|
1484
1416
|
"name": "memo.mjs"
|
|
1485
1417
|
},
|
|
1418
|
+
{
|
|
1419
|
+
"name": "mimeType.cjs"
|
|
1420
|
+
},
|
|
1421
|
+
{
|
|
1422
|
+
"name": "mimeType.d.ts"
|
|
1423
|
+
},
|
|
1424
|
+
{
|
|
1425
|
+
"name": "mimeType.mjs"
|
|
1426
|
+
},
|
|
1486
1427
|
{
|
|
1487
1428
|
"name": "or.cjs"
|
|
1488
1429
|
},
|
|
@@ -1501,6 +1442,15 @@
|
|
|
1501
1442
|
{
|
|
1502
1443
|
"name": "override.mjs"
|
|
1503
1444
|
},
|
|
1445
|
+
{
|
|
1446
|
+
"name": "path.cjs"
|
|
1447
|
+
},
|
|
1448
|
+
{
|
|
1449
|
+
"name": "path.d.ts"
|
|
1450
|
+
},
|
|
1451
|
+
{
|
|
1452
|
+
"name": "path.mjs"
|
|
1453
|
+
},
|
|
1504
1454
|
{
|
|
1505
1455
|
"name": "pipe.cjs"
|
|
1506
1456
|
},
|
package/package.json
CHANGED
|
@@ -1,25 +0,0 @@
|
|
|
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;
|
|
@@ -1,26 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,23 +0,0 @@
|
|
|
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 };
|
|
@@ -1,17 +0,0 @@
|
|
|
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;
|
|
@@ -1,21 +0,0 @@
|
|
|
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;
|
|
@@ -1,15 +0,0 @@
|
|
|
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 };
|
|
@@ -1,21 +0,0 @@
|
|
|
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;
|
|
@@ -1,23 +0,0 @@
|
|
|
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;
|
|
@@ -1,19 +0,0 @@
|
|
|
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 };
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
|
@@ -1,27 +0,0 @@
|
|
|
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";
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
*/
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,21 +0,0 @@
|
|
|
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;
|
|
@@ -1,13 +0,0 @@
|
|
|
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 };
|
|
@@ -1,18 +0,0 @@
|
|
|
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;
|
|
@@ -1,27 +0,0 @@
|
|
|
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.Fail | DEither.Success<string>;
|
|
@@ -1,16 +0,0 @@
|
|
|
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 };
|