@augment-vir/common 23.4.0 → 25.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 -2
- package/dist/esm/augments/error.js +2 -2
- package/dist/esm/index.js +0 -2
- package/dist/types/augments/error.d.ts +2 -4
- package/dist/types/index.d.ts +0 -2
- package/package.json +2 -2
- package/dist/cjs/augments/string/search-params.js +0 -52
- package/dist/cjs/augments/string/url.js +0 -73
- package/dist/esm/augments/string/search-params.js +0 -47
- package/dist/esm/augments/string/url.js +0 -69
- package/dist/types/augments/string/search-params.d.ts +0 -5
- 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
|
@@ -49,9 +49,7 @@ __exportStar(require("./augments/promise/wait"), exports);
|
|
|
49
49
|
__exportStar(require("./augments/random"), exports);
|
|
50
50
|
__exportStar(require("./augments/regexp"), exports);
|
|
51
51
|
__exportStar(require("./augments/string/prefixes"), exports);
|
|
52
|
-
__exportStar(require("./augments/string/search-params"), exports);
|
|
53
52
|
__exportStar(require("./augments/string/suffixes"), exports);
|
|
54
|
-
__exportStar(require("./augments/string/url"), exports);
|
|
55
53
|
__exportStar(require("./augments/string/uuid"), exports);
|
|
56
54
|
__exportStar(require("./augments/time"), exports);
|
|
57
55
|
__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
|
@@ -33,9 +33,7 @@ export * from './augments/promise/wait';
|
|
|
33
33
|
export * from './augments/random';
|
|
34
34
|
export * from './augments/regexp';
|
|
35
35
|
export * from './augments/string/prefixes';
|
|
36
|
-
export * from './augments/string/search-params';
|
|
37
36
|
export * from './augments/string/suffixes';
|
|
38
|
-
export * from './augments/string/url';
|
|
39
37
|
export * from './augments/string/uuid';
|
|
40
38
|
export * from './augments/time';
|
|
41
39
|
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
|
@@ -33,9 +33,7 @@ export * from './augments/promise/wait';
|
|
|
33
33
|
export * from './augments/random';
|
|
34
34
|
export * from './augments/regexp';
|
|
35
35
|
export * from './augments/string/prefixes';
|
|
36
|
-
export * from './augments/string/search-params';
|
|
37
36
|
export * from './augments/string/suffixes';
|
|
38
|
-
export * from './augments/string/url';
|
|
39
37
|
export * from './augments/string/uuid';
|
|
40
38
|
export * from './augments/time';
|
|
41
39
|
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": "25.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,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.urlToSearchParamsObject = exports.objectToSearchParamsString = void 0;
|
|
4
|
-
const run_time_assertions_1 = require("run-time-assertions");
|
|
5
|
-
const boolean_1 = require("../boolean");
|
|
6
|
-
const common_string_1 = require("../common-string");
|
|
7
|
-
const matches_object_shape_1 = require("../object/matches-object-shape");
|
|
8
|
-
const prefixes_1 = require("./prefixes");
|
|
9
|
-
function objectToSearchParamsString(inputObject) {
|
|
10
|
-
const valueStrings = Object.entries(inputObject)
|
|
11
|
-
.map(([key, value,]) => {
|
|
12
|
-
if (value == undefined) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
return `${key}=${String(value)}`;
|
|
16
|
-
})
|
|
17
|
-
.filter(boolean_1.isTruthy);
|
|
18
|
-
if (valueStrings.length) {
|
|
19
|
-
return `?${valueStrings.join('&')}`;
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return '';
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.objectToSearchParamsString = objectToSearchParamsString;
|
|
26
|
-
function splitSearchString(searchString) {
|
|
27
|
-
const params = (0, prefixes_1.removePrefix)({ value: searchString, prefix: '?' }).split('&');
|
|
28
|
-
const paramEntries = params
|
|
29
|
-
.map((param) => {
|
|
30
|
-
const [key, ...everythingElse] = (0, common_string_1.typedSplit)(param, '=');
|
|
31
|
-
const value = everythingElse.join('');
|
|
32
|
-
if (!value && !key) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
return [
|
|
36
|
-
key,
|
|
37
|
-
value,
|
|
38
|
-
];
|
|
39
|
-
})
|
|
40
|
-
.filter(boolean_1.isTruthy);
|
|
41
|
-
return paramEntries;
|
|
42
|
-
}
|
|
43
|
-
function urlToSearchParamsObject(inputUrl, verifyShape) {
|
|
44
|
-
const ensuredUrl = (0, run_time_assertions_1.isRunTimeType)(inputUrl, 'string') ? new URL(inputUrl) : inputUrl;
|
|
45
|
-
const searchEntries = splitSearchString(ensuredUrl.search);
|
|
46
|
-
const paramsObject = Object.fromEntries(searchEntries);
|
|
47
|
-
if (verifyShape) {
|
|
48
|
-
(0, matches_object_shape_1.assertMatchesObjectShape)(paramsObject, verifyShape);
|
|
49
|
-
}
|
|
50
|
-
return paramsObject;
|
|
51
|
-
}
|
|
52
|
-
exports.urlToSearchParamsObject = urlToSearchParamsObject;
|
|
@@ -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,47 +0,0 @@
|
|
|
1
|
-
import { isRunTimeType } from 'run-time-assertions';
|
|
2
|
-
import { isTruthy } from '../boolean';
|
|
3
|
-
import { typedSplit } from '../common-string';
|
|
4
|
-
import { assertMatchesObjectShape } from '../object/matches-object-shape';
|
|
5
|
-
import { removePrefix } from './prefixes';
|
|
6
|
-
export function objectToSearchParamsString(inputObject) {
|
|
7
|
-
const valueStrings = Object.entries(inputObject)
|
|
8
|
-
.map(([key, value,]) => {
|
|
9
|
-
if (value == undefined) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
return `${key}=${String(value)}`;
|
|
13
|
-
})
|
|
14
|
-
.filter(isTruthy);
|
|
15
|
-
if (valueStrings.length) {
|
|
16
|
-
return `?${valueStrings.join('&')}`;
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
return '';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function splitSearchString(searchString) {
|
|
23
|
-
const params = removePrefix({ value: searchString, prefix: '?' }).split('&');
|
|
24
|
-
const paramEntries = params
|
|
25
|
-
.map((param) => {
|
|
26
|
-
const [key, ...everythingElse] = typedSplit(param, '=');
|
|
27
|
-
const value = everythingElse.join('');
|
|
28
|
-
if (!value && !key) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
return [
|
|
32
|
-
key,
|
|
33
|
-
value,
|
|
34
|
-
];
|
|
35
|
-
})
|
|
36
|
-
.filter(isTruthy);
|
|
37
|
-
return paramEntries;
|
|
38
|
-
}
|
|
39
|
-
export function urlToSearchParamsObject(inputUrl, verifyShape) {
|
|
40
|
-
const ensuredUrl = isRunTimeType(inputUrl, 'string') ? new URL(inputUrl) : inputUrl;
|
|
41
|
-
const searchEntries = splitSearchString(ensuredUrl.search);
|
|
42
|
-
const paramsObject = Object.fromEntries(searchEntries);
|
|
43
|
-
if (verifyShape) {
|
|
44
|
-
assertMatchesObjectShape(paramsObject, verifyShape);
|
|
45
|
-
}
|
|
46
|
-
return paramsObject;
|
|
47
|
-
}
|
|
@@ -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,5 +0,0 @@
|
|
|
1
|
-
import { Primitive } from 'type-fest';
|
|
2
|
-
export type SearchParamObjectBase = Record<string, Exclude<Primitive, symbol>>;
|
|
3
|
-
export declare function objectToSearchParamsString(inputObject: SearchParamObjectBase): string;
|
|
4
|
-
export declare function urlToSearchParamsObject<VerifyShapeGeneric extends SearchParamObjectBase>(inputUrl: string | Pick<URL, 'search'>, verifyShape: VerifyShapeGeneric): VerifyShapeGeneric;
|
|
5
|
-
export declare function urlToSearchParamsObject<VerifyShapeGeneric extends SearchParamObjectBase>(inputUrl: string | Pick<URL, 'search'>, verifyShape?: VerifyShapeGeneric | undefined): Record<string, string>;
|
|
@@ -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;
|