@augment-vir/common 23.4.0 → 24.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/augments/error.js +2 -2
- package/dist/cjs/index.js +0 -1
- package/dist/esm/augments/error.js +2 -2
- package/dist/esm/index.js +0 -1
- package/dist/types/augments/error.d.ts +2 -4
- package/dist/types/index.d.ts +0 -1
- package/package.json +2 -2
- package/dist/cjs/augments/string/url.js +0 -73
- package/dist/esm/augments/string/url.js +0 -69
- package/dist/types/augments/string/url.d.ts +0 -7
|
@@ -52,9 +52,9 @@ function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
|
52
52
|
return error;
|
|
53
53
|
}
|
|
54
54
|
exports.ensureErrorAndPrependMessage = ensureErrorAndPrependMessage;
|
|
55
|
-
function wrapInTry(inputs) {
|
|
55
|
+
function wrapInTry(callback, inputs) {
|
|
56
56
|
try {
|
|
57
|
-
const returnValue =
|
|
57
|
+
const returnValue = callback();
|
|
58
58
|
if (returnValue instanceof Promise) {
|
|
59
59
|
return returnValue.catch((error) => {
|
|
60
60
|
if (inputs.catchCallback) {
|
package/dist/cjs/index.js
CHANGED
|
@@ -51,7 +51,6 @@ __exportStar(require("./augments/regexp"), exports);
|
|
|
51
51
|
__exportStar(require("./augments/string/prefixes"), exports);
|
|
52
52
|
__exportStar(require("./augments/string/search-params"), exports);
|
|
53
53
|
__exportStar(require("./augments/string/suffixes"), exports);
|
|
54
|
-
__exportStar(require("./augments/string/url"), exports);
|
|
55
54
|
__exportStar(require("./augments/string/uuid"), exports);
|
|
56
55
|
__exportStar(require("./augments/time"), exports);
|
|
57
56
|
__exportStar(require("./augments/truncate-number"), exports);
|
|
@@ -44,9 +44,9 @@ export function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
|
44
44
|
error.message = `${prependMessage}: ${error.message}`;
|
|
45
45
|
return error;
|
|
46
46
|
}
|
|
47
|
-
export function wrapInTry(inputs) {
|
|
47
|
+
export function wrapInTry(callback, inputs) {
|
|
48
48
|
try {
|
|
49
|
-
const returnValue =
|
|
49
|
+
const returnValue = callback();
|
|
50
50
|
if (returnValue instanceof Promise) {
|
|
51
51
|
return returnValue.catch((error) => {
|
|
52
52
|
if (inputs.catchCallback) {
|
package/dist/esm/index.js
CHANGED
|
@@ -35,7 +35,6 @@ export * from './augments/regexp';
|
|
|
35
35
|
export * from './augments/string/prefixes';
|
|
36
36
|
export * from './augments/string/search-params';
|
|
37
37
|
export * from './augments/string/suffixes';
|
|
38
|
-
export * from './augments/string/url';
|
|
39
38
|
export * from './augments/string/uuid';
|
|
40
39
|
export * from './augments/time';
|
|
41
40
|
export * from './augments/truncate-number';
|
|
@@ -9,12 +9,10 @@ export declare function combineErrorMessages(errors?: ReadonlyArray<Error | stri
|
|
|
9
9
|
export declare function extractErrorMessage(maybeError: unknown): string;
|
|
10
10
|
export declare function ensureError(maybeError: unknown): Error;
|
|
11
11
|
export declare function ensureErrorAndPrependMessage(maybeError: unknown, prependMessage: string): Error;
|
|
12
|
-
export type
|
|
13
|
-
callback: () => CallbackReturn;
|
|
14
|
-
} & RequireExactlyOne<{
|
|
12
|
+
export type TryWrapConfig<FallbackReturn> = RequireExactlyOne<{
|
|
15
13
|
fallbackValue: FallbackReturn;
|
|
16
14
|
catchCallback: (error: unknown) => FallbackReturn;
|
|
17
15
|
}>;
|
|
18
|
-
export declare function wrapInTry<CallbackReturn, FallbackReturn>(
|
|
16
|
+
export declare function wrapInTry<CallbackReturn, FallbackReturn>(callback: () => CallbackReturn, inputs: TryWrapConfig<FallbackReturn>): FallbackReturn | CallbackReturn;
|
|
19
17
|
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction<PromiseLike<any>>>(callback: CallbackGeneric): Promise<Error | Awaited<ReturnType<CallbackGeneric>>>;
|
|
20
18
|
export declare function executeAndReturnError<CallbackGeneric extends NoInputsFunction>(callback: CallbackGeneric): Error | ReturnType<CallbackGeneric>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -35,7 +35,6 @@ export * from './augments/regexp';
|
|
|
35
35
|
export * from './augments/string/prefixes';
|
|
36
36
|
export * from './augments/string/search-params';
|
|
37
37
|
export * from './augments/string/suffixes';
|
|
38
|
-
export * from './augments/string/url';
|
|
39
38
|
export * from './augments/string/uuid';
|
|
40
39
|
export * from './augments/time';
|
|
41
40
|
export * from './augments/truncate-number';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@augment-vir/common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "24.0.0",
|
|
4
4
|
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/electrovir/augment-vir/issues"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"browser-or-node": "^2.1.1",
|
|
28
28
|
"run-time-assertions": "^1.0.0",
|
|
29
|
-
"type-fest": "^4.
|
|
29
|
+
"type-fest": "^4.12.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"typescript": "5.3.3"
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.joinUrlParts = void 0;
|
|
4
|
-
const protocolSplit = '://';
|
|
5
|
-
/**
|
|
6
|
-
* Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
|
|
7
|
-
* removes consecutive slashes in the path.
|
|
8
|
-
*
|
|
9
|
-
* @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
|
|
10
|
-
*/
|
|
11
|
-
function joinUrlParts(...urlParts) {
|
|
12
|
-
const rawJoined = urlParts.join('/');
|
|
13
|
-
const [protocol, rawRest = '',] = rawJoined.includes(protocolSplit)
|
|
14
|
-
? rawJoined.split(protocolSplit)
|
|
15
|
-
: [
|
|
16
|
-
'',
|
|
17
|
-
rawJoined,
|
|
18
|
-
];
|
|
19
|
-
let mapSearchParamsStarted = false;
|
|
20
|
-
let reduceSearchParamsStarted = false;
|
|
21
|
-
const fixedRest = rawRest
|
|
22
|
-
.replace(/\/{2,}/g, '/')
|
|
23
|
-
.split('/')
|
|
24
|
-
.map((part) => {
|
|
25
|
-
if (part.includes('?') || mapSearchParamsStarted) {
|
|
26
|
-
mapSearchParamsStarted = true;
|
|
27
|
-
return part;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
return part;
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
.reduce((fillingUpArray, currentEntry, currentIndex, inputArray) => {
|
|
34
|
-
if (reduceSearchParamsStarted) {
|
|
35
|
-
return fillingUpArray;
|
|
36
|
-
}
|
|
37
|
-
const nextEntry = inputArray[currentIndex + 1];
|
|
38
|
-
let newEntry = currentEntry;
|
|
39
|
-
const nextHasQuestion = !currentEntry.includes('?') && nextEntry?.startsWith('?');
|
|
40
|
-
if (nextEntry?.startsWith('?') || nextHasQuestion) {
|
|
41
|
-
reduceSearchParamsStarted = true;
|
|
42
|
-
let foundHash = false;
|
|
43
|
-
const subsequentSearchParams = inputArray
|
|
44
|
-
.slice(nextHasQuestion ? currentIndex + 2 : currentIndex + 1)
|
|
45
|
-
.reduce((joinedParams, currentParam) => {
|
|
46
|
-
if (currentParam.includes('#')) {
|
|
47
|
-
foundHash = true;
|
|
48
|
-
}
|
|
49
|
-
if (foundHash) {
|
|
50
|
-
return joinedParams.concat(currentParam);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
return [
|
|
54
|
-
joinedParams,
|
|
55
|
-
currentParam,
|
|
56
|
-
].join('&');
|
|
57
|
-
}
|
|
58
|
-
}, '');
|
|
59
|
-
newEntry = [
|
|
60
|
-
currentEntry,
|
|
61
|
-
nextEntry,
|
|
62
|
-
subsequentSearchParams,
|
|
63
|
-
].join('');
|
|
64
|
-
}
|
|
65
|
-
return fillingUpArray.concat(newEntry);
|
|
66
|
-
}, []);
|
|
67
|
-
return [
|
|
68
|
-
protocol,
|
|
69
|
-
protocol ? protocolSplit : '',
|
|
70
|
-
fixedRest.join('/'),
|
|
71
|
-
].join('');
|
|
72
|
-
}
|
|
73
|
-
exports.joinUrlParts = joinUrlParts;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const protocolSplit = '://';
|
|
2
|
-
/**
|
|
3
|
-
* Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
|
|
4
|
-
* removes consecutive slashes in the path.
|
|
5
|
-
*
|
|
6
|
-
* @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
|
|
7
|
-
*/
|
|
8
|
-
export function joinUrlParts(...urlParts) {
|
|
9
|
-
const rawJoined = urlParts.join('/');
|
|
10
|
-
const [protocol, rawRest = '',] = rawJoined.includes(protocolSplit)
|
|
11
|
-
? rawJoined.split(protocolSplit)
|
|
12
|
-
: [
|
|
13
|
-
'',
|
|
14
|
-
rawJoined,
|
|
15
|
-
];
|
|
16
|
-
let mapSearchParamsStarted = false;
|
|
17
|
-
let reduceSearchParamsStarted = false;
|
|
18
|
-
const fixedRest = rawRest
|
|
19
|
-
.replace(/\/{2,}/g, '/')
|
|
20
|
-
.split('/')
|
|
21
|
-
.map((part) => {
|
|
22
|
-
if (part.includes('?') || mapSearchParamsStarted) {
|
|
23
|
-
mapSearchParamsStarted = true;
|
|
24
|
-
return part;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
return part;
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
.reduce((fillingUpArray, currentEntry, currentIndex, inputArray) => {
|
|
31
|
-
if (reduceSearchParamsStarted) {
|
|
32
|
-
return fillingUpArray;
|
|
33
|
-
}
|
|
34
|
-
const nextEntry = inputArray[currentIndex + 1];
|
|
35
|
-
let newEntry = currentEntry;
|
|
36
|
-
const nextHasQuestion = !currentEntry.includes('?') && nextEntry?.startsWith('?');
|
|
37
|
-
if (nextEntry?.startsWith('?') || nextHasQuestion) {
|
|
38
|
-
reduceSearchParamsStarted = true;
|
|
39
|
-
let foundHash = false;
|
|
40
|
-
const subsequentSearchParams = inputArray
|
|
41
|
-
.slice(nextHasQuestion ? currentIndex + 2 : currentIndex + 1)
|
|
42
|
-
.reduce((joinedParams, currentParam) => {
|
|
43
|
-
if (currentParam.includes('#')) {
|
|
44
|
-
foundHash = true;
|
|
45
|
-
}
|
|
46
|
-
if (foundHash) {
|
|
47
|
-
return joinedParams.concat(currentParam);
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return [
|
|
51
|
-
joinedParams,
|
|
52
|
-
currentParam,
|
|
53
|
-
].join('&');
|
|
54
|
-
}
|
|
55
|
-
}, '');
|
|
56
|
-
newEntry = [
|
|
57
|
-
currentEntry,
|
|
58
|
-
nextEntry,
|
|
59
|
-
subsequentSearchParams,
|
|
60
|
-
].join('');
|
|
61
|
-
}
|
|
62
|
-
return fillingUpArray.concat(newEntry);
|
|
63
|
-
}, []);
|
|
64
|
-
return [
|
|
65
|
-
protocol,
|
|
66
|
-
protocol ? protocolSplit : '',
|
|
67
|
-
fixedRest.join('/'),
|
|
68
|
-
].join('');
|
|
69
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Joins all given arguments together as if they were parts of a URL. Preserves trailing slashes and
|
|
3
|
-
* removes consecutive slashes in the path.
|
|
4
|
-
*
|
|
5
|
-
* @example: joinToUrl('https://example.com', 'path1', 'path2/', '/path3/') === 'https://example.com/path1/path2/path3/'
|
|
6
|
-
*/
|
|
7
|
-
export declare function joinUrlParts(...urlParts: ReadonlyArray<string>): string;
|