@augment-vir/common 12.11.2 → 12.12.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.
@@ -1,4 +1,27 @@
1
+ import { ArrayElement } from './type';
1
2
  export type AnyFunction<ReturnGeneric = any> = (...args: any[]) => ReturnGeneric;
2
3
  export type NoInputsFunction<ReturnGeneric = any> = () => ReturnGeneric;
4
+ /**
5
+ * Accepts an "Arguments" and "Return" generic to quickly make a function type. If "Arguments" is an
6
+ * array, it is spread into the full function's Parameters list. If any argument should be an array,
7
+ * instead of a rest parameter, put it inside of a tuple. If no arguments should be possible, pass
8
+ * void to "Arguments". If you need an optional argument, pass it inside of a tuple.
9
+ *
10
+ * @example
11
+ * TypedFunction<string, number>; // (input: string) => number
12
+ *
13
+ * @example
14
+ * TypedFunction<string[], number>; // (...inputs: string[]) => number
15
+ *
16
+ * @example
17
+ * TypedFunction<[string[]], number>; // (input: string[]) => number
18
+ *
19
+ * @example
20
+ * TypedFunction<[string, number], number>; // (input1: string, input2: number) => number
21
+ *
22
+ * @example
23
+ * TypedFunction<[string | undefined], number>; // (input1: string|undefined) => number
24
+ */
25
+ export type TypedFunction<Arguments, Return> = Arguments extends readonly any[] ? number extends Arguments['length'] ? (...args: ArrayElement<Arguments>[]) => Return : (...args: Arguments) => Return : void extends Arguments ? () => Return : (arg: Arguments) => Return;
3
26
  export declare function isTruthy<T>(input: T): input is NonNullable<T>;
4
27
  //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1,8 @@
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. This also encodes each part of the
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;
8
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1,29 @@
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. This also encodes each part of the
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
+ const fixedRest = rawRest
20
+ .replace(/\/{2,}/g, '/')
21
+ .split('/')
22
+ .map((part) => encodeURIComponent(part));
23
+ return [
24
+ protocol,
25
+ protocol ? protocolSplit : '',
26
+ fixedRest.join('/'),
27
+ ].join('');
28
+ }
29
+ exports.joinUrlParts = joinUrlParts;
@@ -58,5 +58,4 @@ export type NoInfer<T> = [T][T extends any ? 0 : never];
58
58
  * input.
59
59
  */
60
60
  export declare function ensureType<ExpectedType = never>(input: NoInfer<ExpectedType>): NoInfer<ExpectedType>;
61
- export type TypedFunction<ParametersGeneric extends any[], ReturnTypeGeneric> = (...args: ParametersGeneric) => ReturnTypeGeneric;
62
61
  //# sourceMappingURL=type.d.ts.map
@@ -22,6 +22,7 @@ export * from './augments/object/typed-has-property';
22
22
  export * from './augments/promise';
23
23
  export * from './augments/regexp';
24
24
  export * from './augments/runtime-type-of';
25
+ export * from './augments/string/url';
25
26
  export * from './augments/truncate-number';
26
27
  export * from './augments/tuple';
27
28
  export * from './augments/type';
package/dist/cjs/index.js CHANGED
@@ -38,6 +38,7 @@ __exportStar(require("./augments/object/typed-has-property"), exports);
38
38
  __exportStar(require("./augments/promise"), exports);
39
39
  __exportStar(require("./augments/regexp"), exports);
40
40
  __exportStar(require("./augments/runtime-type-of"), exports);
41
+ __exportStar(require("./augments/string/url"), exports);
41
42
  __exportStar(require("./augments/truncate-number"), exports);
42
43
  __exportStar(require("./augments/tuple"), exports);
43
44
  __exportStar(require("./augments/type"), exports);
@@ -1,4 +1,27 @@
1
+ import { ArrayElement } from './type';
1
2
  export type AnyFunction<ReturnGeneric = any> = (...args: any[]) => ReturnGeneric;
2
3
  export type NoInputsFunction<ReturnGeneric = any> = () => ReturnGeneric;
4
+ /**
5
+ * Accepts an "Arguments" and "Return" generic to quickly make a function type. If "Arguments" is an
6
+ * array, it is spread into the full function's Parameters list. If any argument should be an array,
7
+ * instead of a rest parameter, put it inside of a tuple. If no arguments should be possible, pass
8
+ * void to "Arguments". If you need an optional argument, pass it inside of a tuple.
9
+ *
10
+ * @example
11
+ * TypedFunction<string, number>; // (input: string) => number
12
+ *
13
+ * @example
14
+ * TypedFunction<string[], number>; // (...inputs: string[]) => number
15
+ *
16
+ * @example
17
+ * TypedFunction<[string[]], number>; // (input: string[]) => number
18
+ *
19
+ * @example
20
+ * TypedFunction<[string, number], number>; // (input1: string, input2: number) => number
21
+ *
22
+ * @example
23
+ * TypedFunction<[string | undefined], number>; // (input1: string|undefined) => number
24
+ */
25
+ export type TypedFunction<Arguments, Return> = Arguments extends readonly any[] ? number extends Arguments['length'] ? (...args: ArrayElement<Arguments>[]) => Return : (...args: Arguments) => Return : void extends Arguments ? () => Return : (arg: Arguments) => Return;
3
26
  export declare function isTruthy<T>(input: T): input is NonNullable<T>;
4
27
  //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1,8 @@
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. This also encodes each part of the
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;
8
+ //# sourceMappingURL=url.d.ts.map
@@ -0,0 +1,25 @@
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. This also encodes each part of the
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
+ const fixedRest = rawRest
17
+ .replace(/\/{2,}/g, '/')
18
+ .split('/')
19
+ .map((part) => encodeURIComponent(part));
20
+ return [
21
+ protocol,
22
+ protocol ? protocolSplit : '',
23
+ fixedRest.join('/'),
24
+ ].join('');
25
+ }
@@ -58,5 +58,4 @@ export type NoInfer<T> = [T][T extends any ? 0 : never];
58
58
  * input.
59
59
  */
60
60
  export declare function ensureType<ExpectedType = never>(input: NoInfer<ExpectedType>): NoInfer<ExpectedType>;
61
- export type TypedFunction<ParametersGeneric extends any[], ReturnTypeGeneric> = (...args: ParametersGeneric) => ReturnTypeGeneric;
62
61
  //# sourceMappingURL=type.d.ts.map
@@ -22,6 +22,7 @@ export * from './augments/object/typed-has-property';
22
22
  export * from './augments/promise';
23
23
  export * from './augments/regexp';
24
24
  export * from './augments/runtime-type-of';
25
+ export * from './augments/string/url';
25
26
  export * from './augments/truncate-number';
26
27
  export * from './augments/tuple';
27
28
  export * from './augments/type';
package/dist/esm/index.js CHANGED
@@ -22,6 +22,7 @@ export * from './augments/object/typed-has-property';
22
22
  export * from './augments/promise';
23
23
  export * from './augments/regexp';
24
24
  export * from './augments/runtime-type-of';
25
+ export * from './augments/string/url';
25
26
  export * from './augments/truncate-number';
26
27
  export * from './augments/tuple';
27
28
  export * from './augments/type';
@@ -1,4 +1,27 @@
1
+ import { ArrayElement } from './type';
1
2
  export type AnyFunction<ReturnGeneric = any> = (...args: any[]) => ReturnGeneric;
2
3
  export type NoInputsFunction<ReturnGeneric = any> = () => ReturnGeneric;
4
+ /**
5
+ * Accepts an "Arguments" and "Return" generic to quickly make a function type. If "Arguments" is an
6
+ * array, it is spread into the full function's Parameters list. If any argument should be an array,
7
+ * instead of a rest parameter, put it inside of a tuple. If no arguments should be possible, pass
8
+ * void to "Arguments". If you need an optional argument, pass it inside of a tuple.
9
+ *
10
+ * @example
11
+ * TypedFunction<string, number>; // (input: string) => number
12
+ *
13
+ * @example
14
+ * TypedFunction<string[], number>; // (...inputs: string[]) => number
15
+ *
16
+ * @example
17
+ * TypedFunction<[string[]], number>; // (input: string[]) => number
18
+ *
19
+ * @example
20
+ * TypedFunction<[string, number], number>; // (input1: string, input2: number) => number
21
+ *
22
+ * @example
23
+ * TypedFunction<[string | undefined], number>; // (input1: string|undefined) => number
24
+ */
25
+ export type TypedFunction<Arguments, Return> = Arguments extends readonly any[] ? number extends Arguments['length'] ? (...args: ArrayElement<Arguments>[]) => Return : (...args: Arguments) => Return : void extends Arguments ? () => Return : (arg: Arguments) => Return;
3
26
  export declare function isTruthy<T>(input: T): input is NonNullable<T>;
4
27
  //# sourceMappingURL=function.d.ts.map
@@ -0,0 +1,8 @@
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. This also encodes each part of the
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;
8
+ //# sourceMappingURL=url.d.ts.map
@@ -58,5 +58,4 @@ export type NoInfer<T> = [T][T extends any ? 0 : never];
58
58
  * input.
59
59
  */
60
60
  export declare function ensureType<ExpectedType = never>(input: NoInfer<ExpectedType>): NoInfer<ExpectedType>;
61
- export type TypedFunction<ParametersGeneric extends any[], ReturnTypeGeneric> = (...args: ParametersGeneric) => ReturnTypeGeneric;
62
61
  //# sourceMappingURL=type.d.ts.map
@@ -22,6 +22,7 @@ export * from './augments/object/typed-has-property';
22
22
  export * from './augments/promise';
23
23
  export * from './augments/regexp';
24
24
  export * from './augments/runtime-type-of';
25
+ export * from './augments/string/url';
25
26
  export * from './augments/truncate-number';
26
27
  export * from './augments/tuple';
27
28
  export * from './augments/type';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "12.11.2",
3
+ "version": "12.12.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"
@@ -24,7 +24,7 @@
24
24
  "test:types": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "type-fest": "^3.6.0"
27
+ "type-fest": "^3.6.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "typescript": "^4.9.5"