danholibraryjs 1.11.0 → 2.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/Classes/DanhoLogger.d.ts +23 -0
- package/dist/Classes/DanhoLogger.js +65 -0
- package/dist/Classes/Events/Event.d.ts +66 -66
- package/dist/Classes/Events/Event.js +114 -114
- package/dist/Classes/Events/EventCollection.d.ts +57 -57
- package/dist/Classes/Events/EventCollection.js +109 -109
- package/dist/Classes/Events/EventEmitter.d.ts +74 -74
- package/dist/Classes/Events/EventEmitter.js +97 -97
- package/dist/Classes/Events/index.d.ts +3 -3
- package/dist/Classes/Events/index.js +19 -19
- package/dist/Classes/Time/Date.d.ts +148 -147
- package/dist/Classes/Time/Date.js +241 -238
- package/dist/Classes/Time/Time.d.ts +66 -65
- package/dist/Classes/Time/Time.js +120 -117
- package/dist/Classes/Time/TimeProperties.d.ts +3 -3
- package/dist/Classes/Time/TimeProperties.js +2 -2
- package/dist/Classes/Time/TimeSpan.d.ts +123 -123
- package/dist/Classes/Time/TimeSpan.js +179 -179
- package/dist/Classes/Time/index.d.ts +4 -4
- package/dist/Classes/Time/index.js +20 -20
- package/dist/Classes/index.d.ts +4 -3
- package/dist/Classes/index.js +20 -19
- package/dist/Classes/store.d.ts +75 -75
- package/dist/Classes/store.js +84 -84
- package/dist/Extensions/Array/array.extension.d.ts +42 -0
- package/dist/Extensions/Array/array.extension.js +57 -0
- package/dist/Extensions/Array/crud.extension.d.ts +24 -0
- package/dist/Extensions/Array/crud.extension.js +28 -0
- package/dist/Extensions/Array/index.d.ts +20 -0
- package/dist/Extensions/Array/index.js +40 -0
- package/dist/Extensions/Array/loop.extension.d.ts +18 -0
- package/dist/Extensions/Array/loop.extension.js +23 -0
- package/dist/Extensions/Array/random.extension.d.ts +23 -0
- package/dist/Extensions/Array/random.extension.js +35 -0
- package/dist/Extensions/Array/sort.extension.d.ts +27 -0
- package/dist/Extensions/Array/sort.extension.js +31 -0
- package/dist/Extensions/Array/string.extension.d.ts +13 -0
- package/dist/Extensions/Array/string.extension.js +14 -0
- package/dist/Extensions/Array.d.ts +52 -52
- package/dist/Extensions/Array.js +51 -51
- package/dist/Extensions/Document.d.ts +27 -27
- package/dist/Extensions/Document.js +32 -32
- package/dist/Extensions/Function.d.ts +29 -14
- package/dist/Extensions/Function.js +23 -10
- package/dist/Extensions/Map.d.ts +54 -54
- package/dist/Extensions/Map.js +42 -42
- package/dist/Extensions/Number.d.ts +13 -0
- package/dist/Extensions/Number.js +40 -0
- package/dist/Extensions/Object/arrays.extension.d.ts +17 -0
- package/dist/Extensions/Object/arrays.extension.js +13 -0
- package/dist/Extensions/Object/booleans.extension.d.ts +18 -0
- package/dist/Extensions/Object/booleans.extension.js +37 -0
- package/dist/Extensions/Object/extracts.extension.d.ts +38 -0
- package/dist/Extensions/Object/extracts.extension.js +72 -0
- package/dist/Extensions/Object/index.d.ts +10 -49
- package/dist/Extensions/Object/index.js +36 -38
- package/dist/Extensions/Object/properties.d.ts +28 -28
- package/dist/Extensions/Object/properties.extension.d.ts +6 -0
- package/dist/Extensions/Object/properties.extension.js +4 -0
- package/dist/Extensions/Object/properties.js +19 -20
- package/dist/Extensions/String/case.extension.d.ts +12 -0
- package/dist/Extensions/String/case.extension.js +55 -0
- package/dist/Extensions/String/index.d.ts +4 -0
- package/dist/Extensions/String/index.js +30 -0
- package/dist/Extensions/String.d.ts +36 -36
- package/dist/Extensions/String.js +25 -25
- package/dist/Extensions/index.d.ts +6 -17
- package/dist/Extensions/index.js +22 -30
- package/dist/Functions/CopyToClipboard.d.ts +7 -7
- package/dist/Functions/CopyToClipboard.js +15 -15
- package/dist/Functions/GetCSSProperty.d.ts +15 -15
- package/dist/Functions/GetCSSProperty.js +26 -26
- package/dist/Functions/GetNestedProperty.d.ts +9 -9
- package/dist/Functions/GetNestedProperty.js +23 -23
- package/dist/Functions/HTMLEvent.d.ts +11 -11
- package/dist/Functions/HTMLEvent.js +14 -14
- package/dist/Functions/SetNavigationSelected.d.ts +9 -9
- package/dist/Functions/SetNavigationSelected.js +25 -25
- package/dist/Functions/index.d.ts +5 -5
- package/dist/Functions/index.js +21 -21
- package/dist/Interfaces/ElementOptions.d.ts +15 -15
- package/dist/Interfaces/ElementOptions.js +2 -2
- package/dist/Interfaces/IReplacement.d.ts +12 -12
- package/dist/Interfaces/IReplacement.js +2 -2
- package/dist/Interfaces/index.d.ts +2 -2
- package/dist/Interfaces/index.js +18 -18
- package/dist/Types/Able.d.ts +16 -0
- package/dist/Types/Able.js +2 -0
- package/dist/Types/Array.d.ts +6 -0
- package/dist/Types/Array.js +2 -0
- package/dist/Types/BetterTypes.d.ts +9 -9
- package/dist/Types/BetterTypes.js +2 -2
- package/dist/Types/C#.d.ts +8 -0
- package/dist/Types/C#.js +2 -0
- package/dist/Types/Date.d.ts +6 -6
- package/dist/Types/Date.js +2 -2
- package/dist/Types/Events.d.ts +10 -10
- package/dist/Types/Events.js +2 -2
- package/dist/Types/Function.d.ts +5 -0
- package/dist/Types/Function.js +2 -0
- package/dist/Types/Object.d.ts +4 -0
- package/dist/Types/Object.js +2 -0
- package/dist/Types/PropertiesWith.d.ts +34 -13
- package/dist/Types/PropertiesWith.js +2 -2
- package/dist/Types/String.d.ts +1 -0
- package/dist/Types/String.js +2 -0
- package/dist/Types/TransformTypes.d.ts +22 -16
- package/dist/Types/TransformTypes.js +2 -2
- package/dist/Types/index.d.ts +24 -65
- package/dist/Types/index.js +27 -21
- package/dist/Utils/ApiUtil/ApiTypes.d.ts +15 -15
- package/dist/Utils/ApiUtil/ApiTypes.js +15 -15
- package/dist/Utils/ApiUtil/RequestUtil.d.ts +19 -19
- package/dist/Utils/ApiUtil/RequestUtil.js +73 -73
- package/dist/Utils/ApiUtil/index.d.ts +20 -20
- package/dist/Utils/ApiUtil/index.js +33 -33
- package/dist/Utils/ApiUtils/ApiTypes.d.ts +15 -0
- package/dist/Utils/ApiUtils/ApiTypes.js +15 -0
- package/dist/Utils/ApiUtils/RequestUtil.d.ts +19 -0
- package/dist/Utils/ApiUtils/RequestUtil.js +73 -0
- package/dist/Utils/ApiUtils/index.d.ts +20 -0
- package/dist/Utils/ApiUtils/index.js +33 -0
- package/dist/Utils/ColorUtils.d.ts +11 -0
- package/dist/Utils/ColorUtils.js +93 -0
- package/dist/Utils/FormUtil.d.ts +6 -6
- package/dist/Utils/FormUtil.js +35 -35
- package/dist/Utils/FormUtils.d.ts +6 -0
- package/dist/Utils/FormUtils.js +35 -0
- package/dist/Utils/NumberUtils.d.ts +1 -0
- package/dist/Utils/NumberUtils.js +7 -0
- package/dist/Utils/PatcherUtils.d.ts +6 -0
- package/dist/Utils/PatcherUtils.js +80 -0
- package/dist/Utils/StringUtils.d.ts +3 -0
- package/dist/Utils/StringUtils.js +47 -0
- package/dist/Utils/TimeUtils/debounce.util.d.ts +22 -0
- package/dist/Utils/TimeUtils/debounce.util.js +78 -0
- package/dist/Utils/TimeUtils/functions.util.d.ts +4 -0
- package/dist/Utils/TimeUtils/functions.util.js +21 -0
- package/dist/Utils/TimeUtils/index.d.ts +15 -0
- package/dist/Utils/TimeUtils/index.js +34 -0
- package/dist/Utils/TimeUtils/throttle.util.d.ts +15 -0
- package/dist/Utils/TimeUtils/throttle.util.js +43 -0
- package/dist/Utils/index.d.ts +7 -2
- package/dist/Utils/index.js +23 -18
- package/dist/index.d.ts +5 -5
- package/dist/index.js +21 -21
- package/package.json +4 -2
- package/src/Classes/DanhoLogger.ts +78 -0
- package/src/Classes/Events/Event.ts +96 -96
- package/src/Classes/Events/EventCollection.ts +90 -90
- package/src/Classes/Events/EventEmitter.ts +68 -68
- package/src/Classes/Time/Date.ts +219 -216
- package/src/Classes/Time/Time.ts +109 -104
- package/src/Classes/Time/TimeSpan.ts +171 -171
- package/src/Classes/index.ts +1 -0
- package/src/Classes/store.ts +22 -22
- package/src/Extensions/Array/array.extension.ts +103 -0
- package/src/Extensions/Array/crud.extension.ts +46 -0
- package/src/Extensions/Array/index.ts +15 -0
- package/src/Extensions/Array/loop.extension.ts +38 -0
- package/src/Extensions/Array/random.extension.ts +56 -0
- package/src/Extensions/Array/sort.extension.ts +52 -0
- package/src/Extensions/Array/string.extension.ts +22 -0
- package/src/Extensions/Document.ts +39 -39
- package/src/Extensions/Function.ts +37 -10
- package/src/Extensions/Map.ts +56 -56
- package/src/Extensions/Number.ts +50 -0
- package/src/Extensions/Object/arrays.extension.ts +27 -0
- package/src/Extensions/Object/booleans.extension.ts +46 -0
- package/src/Extensions/Object/extracts.extension.ts +102 -0
- package/src/Extensions/Object/index.ts +9 -80
- package/src/Extensions/Object/properties.extension.ts +11 -0
- package/src/Extensions/Object/properties.ts +35 -36
- package/src/Extensions/String/case.extension.ts +95 -0
- package/src/Extensions/String/index.ts +5 -0
- package/src/Extensions/index.ts +2 -20
- package/src/Interfaces/ElementOptions.ts +7 -7
- package/src/Interfaces/IReplacement.ts +2 -2
- package/src/Types/Able.ts +22 -0
- package/src/Types/Array.ts +7 -0
- package/src/Types/C#.ts +9 -0
- package/src/Types/Date.ts +1 -1
- package/src/Types/Events.ts +12 -12
- package/src/Types/Function.ts +10 -0
- package/src/Types/Object.ts +4 -0
- package/src/Types/PropertiesWith.ts +35 -4
- package/src/Types/String.ts +1 -0
- package/src/Types/TransformTypes.ts +21 -13
- package/src/Types/index.ts +7 -69
- package/src/Utils/{ApiUtil → ApiUtils}/ApiTypes.ts +2 -1
- package/src/Utils/{ApiUtil → ApiUtils}/index.ts +1 -1
- package/src/Utils/ColorUtils.ts +102 -0
- package/src/Utils/{FormUtil.ts → FormUtils.ts} +2 -2
- package/src/Utils/NumberUtils.ts +3 -0
- package/src/Utils/PatcherUtils.ts +111 -0
- package/src/Utils/StringUtils.ts +44 -0
- package/src/Utils/TimeUtils/debounce.util.ts +85 -0
- package/src/Utils/TimeUtils/functions.util.ts +18 -0
- package/src/Utils/TimeUtils/index.ts +9 -0
- package/src/Utils/TimeUtils/throttle.util.ts +44 -0
- package/src/Utils/index.ts +8 -2
- package/src/Extensions/Array.ts +0 -95
- package/src/Extensions/String.ts +0 -54
- /package/src/Utils/{ApiUtil → ApiUtils}/RequestUtil.ts +0 -0
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { ApiUtilOptions, RequestOptions } from "./ApiTypes";
|
|
2
|
-
export declare class ApiUtil<ApiEndpoints extends string> {
|
|
3
|
-
protected __baseEndpointDev: string;
|
|
4
|
-
protected __baseEndpoint?: string;
|
|
5
|
-
protected __log: boolean;
|
|
6
|
-
constructor({ baseEndpointDev, baseEndpoint, log }: ApiUtilOptions);
|
|
7
|
-
/**
|
|
8
|
-
* Make a request to the API
|
|
9
|
-
* @param path The path to the endpoint
|
|
10
|
-
* @param options The options for the request
|
|
11
|
-
* @returns The response from the API
|
|
12
|
-
*/
|
|
13
|
-
request<TData>(path: ApiEndpoints, options?: RequestOptions): Promise<{
|
|
14
|
-
success: boolean;
|
|
15
|
-
status: number;
|
|
16
|
-
data: TData;
|
|
17
|
-
text: string;
|
|
18
|
-
}>;
|
|
19
|
-
get baseEndpoint(): string;
|
|
20
|
-
}
|
|
1
|
+
import { ApiUtilOptions, RequestOptions } from "./ApiTypes";
|
|
2
|
+
export declare class ApiUtil<ApiEndpoints extends string> {
|
|
3
|
+
protected __baseEndpointDev: string;
|
|
4
|
+
protected __baseEndpoint?: string;
|
|
5
|
+
protected __log: boolean;
|
|
6
|
+
constructor({ baseEndpointDev, baseEndpoint, log }: ApiUtilOptions);
|
|
7
|
+
/**
|
|
8
|
+
* Make a request to the API
|
|
9
|
+
* @param path The path to the endpoint
|
|
10
|
+
* @param options The options for the request
|
|
11
|
+
* @returns The response from the API
|
|
12
|
+
*/
|
|
13
|
+
request<TData>(path: ApiEndpoints, options?: RequestOptions): Promise<{
|
|
14
|
+
success: boolean;
|
|
15
|
+
status: number;
|
|
16
|
+
data: TData;
|
|
17
|
+
text: string;
|
|
18
|
+
}>;
|
|
19
|
+
get baseEndpoint(): string;
|
|
20
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiUtil = void 0;
|
|
4
|
-
const RequestUtil_1 = require("./RequestUtil");
|
|
5
|
-
class ApiUtil {
|
|
6
|
-
__baseEndpointDev;
|
|
7
|
-
__baseEndpoint;
|
|
8
|
-
__log;
|
|
9
|
-
constructor({ baseEndpointDev, baseEndpoint, log }) {
|
|
10
|
-
this.__baseEndpointDev = baseEndpointDev;
|
|
11
|
-
this.__baseEndpoint = baseEndpoint;
|
|
12
|
-
this.__log = log ?? false;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Make a request to the API
|
|
16
|
-
* @param path The path to the endpoint
|
|
17
|
-
* @param options The options for the request
|
|
18
|
-
* @returns The response from the API
|
|
19
|
-
*/
|
|
20
|
-
async request(path, options) {
|
|
21
|
-
return (0, RequestUtil_1.Request)(path, {
|
|
22
|
-
...options,
|
|
23
|
-
baseEndpoint: this.baseEndpoint
|
|
24
|
-
}, this.__log);
|
|
25
|
-
}
|
|
26
|
-
get baseEndpoint() {
|
|
27
|
-
const processExists = 'process' in globalThis;
|
|
28
|
-
// @ts-ignore -- process is not defined in the browser
|
|
29
|
-
const isDev = processExists && process.env.NODE_ENV === 'development';
|
|
30
|
-
return isDev ? this.__baseEndpointDev : this.__baseEndpoint ?? this.__baseEndpointDev;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.ApiUtil = ApiUtil;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiUtil = void 0;
|
|
4
|
+
const RequestUtil_1 = require("./RequestUtil");
|
|
5
|
+
class ApiUtil {
|
|
6
|
+
__baseEndpointDev;
|
|
7
|
+
__baseEndpoint;
|
|
8
|
+
__log;
|
|
9
|
+
constructor({ baseEndpointDev, baseEndpoint, log }) {
|
|
10
|
+
this.__baseEndpointDev = baseEndpointDev;
|
|
11
|
+
this.__baseEndpoint = baseEndpoint;
|
|
12
|
+
this.__log = log ?? false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Make a request to the API
|
|
16
|
+
* @param path The path to the endpoint
|
|
17
|
+
* @param options The options for the request
|
|
18
|
+
* @returns The response from the API
|
|
19
|
+
*/
|
|
20
|
+
async request(path, options) {
|
|
21
|
+
return (0, RequestUtil_1.Request)(path, {
|
|
22
|
+
...options,
|
|
23
|
+
baseEndpoint: this.baseEndpoint
|
|
24
|
+
}, this.__log);
|
|
25
|
+
}
|
|
26
|
+
get baseEndpoint() {
|
|
27
|
+
const processExists = 'process' in globalThis;
|
|
28
|
+
// @ts-ignore -- process is not defined in the browser
|
|
29
|
+
const isDev = processExists && process.env.NODE_ENV === 'development';
|
|
30
|
+
return isDev ? this.__baseEndpointDev : this.__baseEndpoint ?? this.__baseEndpointDev;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ApiUtil = ApiUtil;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type TParam = string | undefined;
|
|
2
|
+
export type HttpMethods = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
3
|
+
export type RequestOptions<TBody = any> = Omit<RequestInit, 'method' | 'body'> & {
|
|
4
|
+
method?: HttpMethods;
|
|
5
|
+
body?: TBody;
|
|
6
|
+
noHeaders?: boolean;
|
|
7
|
+
controller?: AbortController;
|
|
8
|
+
query?: Record<string, string | undefined>;
|
|
9
|
+
baseEndpoint?: string;
|
|
10
|
+
};
|
|
11
|
+
export type ApiUtilOptions = {
|
|
12
|
+
baseEndpointDev: string;
|
|
13
|
+
baseEndpoint?: string;
|
|
14
|
+
log?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// All possible endpoints for the API. This will generate autocomplete when using the Request function
|
|
4
|
+
// The commented code below is an example from my previous "CitizenTaxi" project to illustrate how this works
|
|
5
|
+
// export type ApiEndpoints<Param extends TParam = undefined> =
|
|
6
|
+
// | `bookings` // [GET, POST]
|
|
7
|
+
// | `bookings?citizenId=${Param}` // [GET] Guid
|
|
8
|
+
// | `bookings/${Param}` // [GET, PUT, DELETE] Guid bookingId
|
|
9
|
+
// | `notes` // [GET, POST]
|
|
10
|
+
// | `notes?citizenId=${Param}` // [GET] Guid
|
|
11
|
+
// | `notes/${Param}` // [GET, PUT, DELETE] Guid noteId
|
|
12
|
+
// | `users` // [GET, POST]
|
|
13
|
+
// | `users?role=${Param}` // [GET] enum Role
|
|
14
|
+
// | `users/${Param}` // [GET, PUT, DELETE] Guid userId
|
|
15
|
+
// | `users/authenticate`; // [POST, DELETE]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RequestOptions } from "./ApiTypes";
|
|
2
|
+
/**
|
|
3
|
+
* Makes a request to the API
|
|
4
|
+
* @param path Api endpoint to request
|
|
5
|
+
* @param options Additional options for the request
|
|
6
|
+
* @returns The response from the API
|
|
7
|
+
*/
|
|
8
|
+
export declare function Request<TData, ApiEndpoints extends string>(path: ApiEndpoints, { method, body, noHeaders, controller, query, baseEndpoint }?: RequestOptions | undefined, log?: boolean): Promise<{
|
|
9
|
+
success: boolean;
|
|
10
|
+
status: number;
|
|
11
|
+
data: TData;
|
|
12
|
+
text: string;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Ensures that the path starts with a /
|
|
16
|
+
* @param path Path string
|
|
17
|
+
* @returns Path that starts with a /
|
|
18
|
+
*/
|
|
19
|
+
export declare function ensureSlash(path: string): string;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureSlash = exports.Request = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Makes a request to the API
|
|
6
|
+
* @param path Api endpoint to request
|
|
7
|
+
* @param options Additional options for the request
|
|
8
|
+
* @returns The response from the API
|
|
9
|
+
*/
|
|
10
|
+
async function Request(path,
|
|
11
|
+
// Destructor the options object, if it's undefined then set it to an empty object
|
|
12
|
+
{ method = 'GET', body, noHeaders = false, controller = new AbortController(), query, baseEndpoint } = {}, log = false) {
|
|
13
|
+
// console.log(`Requesting ${path} with method ${method}`);
|
|
14
|
+
// Construct the endpoint for the request
|
|
15
|
+
const endpoint = (() => {
|
|
16
|
+
const result = baseEndpoint + ensureSlash(path);
|
|
17
|
+
if (path.includes('?') || !query)
|
|
18
|
+
return result;
|
|
19
|
+
// If the query object is defined, then construct a query string from it
|
|
20
|
+
const queryString = Object.entries(query)
|
|
21
|
+
.map(([key, value]) => value ? `${key}=${value}` : '')
|
|
22
|
+
.join('&');
|
|
23
|
+
return path.includes('?') ? `${result}&${queryString}` : `${result}?${queryString}`;
|
|
24
|
+
})();
|
|
25
|
+
// Construct the request init object to pass to the fetch function
|
|
26
|
+
const init = {
|
|
27
|
+
method,
|
|
28
|
+
body: body ? !noHeaders ? JSON.stringify(body) : body : undefined,
|
|
29
|
+
headers: !noHeaders ? { 'Content-Type': 'application/json' } : undefined,
|
|
30
|
+
signal: controller.signal,
|
|
31
|
+
credentials: 'include',
|
|
32
|
+
mode: 'cors'
|
|
33
|
+
};
|
|
34
|
+
// Make the request, log any errors, and throw them again
|
|
35
|
+
const res = await fetch(endpoint, init).catch(err => {
|
|
36
|
+
console.error(`Failed to [${method}] ${path}`, err);
|
|
37
|
+
throw err;
|
|
38
|
+
});
|
|
39
|
+
if (log)
|
|
40
|
+
console.log(`[${method}] ${path} responded with ${res.status}`, res);
|
|
41
|
+
// Clone the response so that it can be converted to JSON and text
|
|
42
|
+
const clone = res.clone();
|
|
43
|
+
// All successful responses are in the 200s, so check if the status code starts with 2
|
|
44
|
+
const isSuccessful = res.status.toString().startsWith('2');
|
|
45
|
+
// This try-catch block is used to catch any errors when converting the response to JSON
|
|
46
|
+
// If the response is not jsonable, then the catch will return null for the data
|
|
47
|
+
try {
|
|
48
|
+
return {
|
|
49
|
+
success: isSuccessful,
|
|
50
|
+
status: res.status,
|
|
51
|
+
data: await res.json(),
|
|
52
|
+
text: await clone.text(),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return {
|
|
57
|
+
success: isSuccessful,
|
|
58
|
+
status: res.status,
|
|
59
|
+
data: null,
|
|
60
|
+
text: await clone.text(),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Request = Request;
|
|
65
|
+
/**
|
|
66
|
+
* Ensures that the path starts with a /
|
|
67
|
+
* @param path Path string
|
|
68
|
+
* @returns Path that starts with a /
|
|
69
|
+
*/
|
|
70
|
+
function ensureSlash(path) {
|
|
71
|
+
return path.startsWith('/') ? path : '/' + path;
|
|
72
|
+
}
|
|
73
|
+
exports.ensureSlash = ensureSlash;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ApiUtilOptions, RequestOptions } from "./ApiTypes";
|
|
2
|
+
export declare class ApiUtils<ApiEndpoints extends string> {
|
|
3
|
+
protected __baseEndpointDev: string;
|
|
4
|
+
protected __baseEndpoint?: string;
|
|
5
|
+
protected __log: boolean;
|
|
6
|
+
constructor({ baseEndpointDev, baseEndpoint, log }: ApiUtilOptions);
|
|
7
|
+
/**
|
|
8
|
+
* Make a request to the API
|
|
9
|
+
* @param path The path to the endpoint
|
|
10
|
+
* @param options The options for the request
|
|
11
|
+
* @returns The response from the API
|
|
12
|
+
*/
|
|
13
|
+
request<TData>(path: ApiEndpoints, options?: RequestOptions): Promise<{
|
|
14
|
+
success: boolean;
|
|
15
|
+
status: number;
|
|
16
|
+
data: TData;
|
|
17
|
+
text: string;
|
|
18
|
+
}>;
|
|
19
|
+
get baseEndpoint(): string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiUtils = void 0;
|
|
4
|
+
const RequestUtil_1 = require("./RequestUtil");
|
|
5
|
+
class ApiUtils {
|
|
6
|
+
__baseEndpointDev;
|
|
7
|
+
__baseEndpoint;
|
|
8
|
+
__log;
|
|
9
|
+
constructor({ baseEndpointDev, baseEndpoint, log }) {
|
|
10
|
+
this.__baseEndpointDev = baseEndpointDev;
|
|
11
|
+
this.__baseEndpoint = baseEndpoint;
|
|
12
|
+
this.__log = log ?? false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Make a request to the API
|
|
16
|
+
* @param path The path to the endpoint
|
|
17
|
+
* @param options The options for the request
|
|
18
|
+
* @returns The response from the API
|
|
19
|
+
*/
|
|
20
|
+
async request(path, options) {
|
|
21
|
+
return (0, RequestUtil_1.Request)(path, {
|
|
22
|
+
...options,
|
|
23
|
+
baseEndpoint: this.baseEndpoint
|
|
24
|
+
}, this.__log);
|
|
25
|
+
}
|
|
26
|
+
get baseEndpoint() {
|
|
27
|
+
const processExists = 'process' in globalThis;
|
|
28
|
+
// @ts-ignore -- process is not defined in the browser
|
|
29
|
+
const isDev = processExists && process.env.NODE_ENV === 'development';
|
|
30
|
+
return isDev ? this.__baseEndpointDev : this.__baseEndpoint ?? this.__baseEndpointDev;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.ApiUtils = ApiUtils;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type RGB = [number, number, number];
|
|
2
|
+
export type Hex = `#${string}`;
|
|
3
|
+
export type ColorType = 'hex' | 'rgb' | 'hsl';
|
|
4
|
+
export declare function convert(value: RGB, to: Exclude<ColorType, 'rgb'>): string;
|
|
5
|
+
export declare function convert(value: string, from: Exclude<ColorType, 'rgb'>, to: 'rgb'): RGB;
|
|
6
|
+
export declare function generateRandomColor(): Hex;
|
|
7
|
+
export declare const ColorUtils: {
|
|
8
|
+
convert: typeof convert;
|
|
9
|
+
generateRandomColor: typeof generateRandomColor;
|
|
10
|
+
};
|
|
11
|
+
export default ColorUtils;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColorUtils = exports.generateRandomColor = exports.convert = void 0;
|
|
4
|
+
function convert(value, fromOrTo, to) {
|
|
5
|
+
const from = typeof value === 'string' ? fromOrTo : 'rgb';
|
|
6
|
+
const target = typeof value === 'string' ? to : fromOrTo;
|
|
7
|
+
if (from === target)
|
|
8
|
+
return value;
|
|
9
|
+
switch (from) {
|
|
10
|
+
case 'hsl': {
|
|
11
|
+
switch (target) {
|
|
12
|
+
case 'hex': return hslToHex(value);
|
|
13
|
+
case 'rgb': return hexToRgb(hslToHex(value));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
case 'rgb': {
|
|
17
|
+
switch (target) {
|
|
18
|
+
case 'hex': return hslToHex(rgbToHsl(value));
|
|
19
|
+
case 'hsl': return rgbToHsl(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
case 'hex': {
|
|
23
|
+
switch (target) {
|
|
24
|
+
case 'rgb': return hexToRgb(value);
|
|
25
|
+
case 'hsl': return rgbToHsl(hexToRgb(value));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
default: return value;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.convert = convert;
|
|
32
|
+
function generateRandomColor() {
|
|
33
|
+
return `#${Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0')}`;
|
|
34
|
+
}
|
|
35
|
+
exports.generateRandomColor = generateRandomColor;
|
|
36
|
+
exports.ColorUtils = {
|
|
37
|
+
convert,
|
|
38
|
+
generateRandomColor
|
|
39
|
+
};
|
|
40
|
+
exports.default = exports.ColorUtils;
|
|
41
|
+
function hslToHex(value) {
|
|
42
|
+
if (!value)
|
|
43
|
+
return "#000000";
|
|
44
|
+
const match = value.match(/hsl\((\d+), (\d+)%, (\d+)%\)/);
|
|
45
|
+
if (!match)
|
|
46
|
+
return value;
|
|
47
|
+
let [_, h, s, l] = match.map(Number);
|
|
48
|
+
l /= 100;
|
|
49
|
+
const a = s * Math.min(l, 1 - l) / 100;
|
|
50
|
+
const format = (value) => {
|
|
51
|
+
const k = (value + h / 30) % 12;
|
|
52
|
+
const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
53
|
+
return Math.round(255 * color).toString(16).padStart(2, '0');
|
|
54
|
+
};
|
|
55
|
+
return `#${format(0)}${format(8)}${format(4)}`;
|
|
56
|
+
}
|
|
57
|
+
function hexToRgb(hex) {
|
|
58
|
+
if (!hex)
|
|
59
|
+
return [0, 0, 0];
|
|
60
|
+
const match = hex.match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
|
|
61
|
+
if (!match)
|
|
62
|
+
return [0, 0, 0];
|
|
63
|
+
let colorString = match[0];
|
|
64
|
+
if (match[0].length === 3)
|
|
65
|
+
colorString = colorString.split('').map(char => char + char).join('');
|
|
66
|
+
const integer = parseInt(colorString, 16);
|
|
67
|
+
const r = (integer >> 16) & 0xFF;
|
|
68
|
+
const g = (integer >> 8) & 0xFF;
|
|
69
|
+
const b = integer & 0xFF;
|
|
70
|
+
return [r, g, b];
|
|
71
|
+
}
|
|
72
|
+
function rgbToHsl(rgb) {
|
|
73
|
+
let [r, g, b] = rgb.map(x => x / 255);
|
|
74
|
+
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
75
|
+
let h = 0, s = 0, l = (max + min) / 2;
|
|
76
|
+
if (max !== min) {
|
|
77
|
+
const d = max - min;
|
|
78
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
79
|
+
switch (max) {
|
|
80
|
+
case r:
|
|
81
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
82
|
+
break;
|
|
83
|
+
case g:
|
|
84
|
+
h = (b - r) / d + 2;
|
|
85
|
+
break;
|
|
86
|
+
case b:
|
|
87
|
+
h = (r - g) / d + 4;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
h /= 6;
|
|
91
|
+
}
|
|
92
|
+
return `hsl(${Math.round(h * 360)}, ${Math.round(s * 100)}%, ${Math.round(l * 100)}%)`;
|
|
93
|
+
}
|
package/dist/Utils/FormUtil.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Serialize a form into an object
|
|
3
|
-
* @param form The form to serialize
|
|
4
|
-
* @returns An object of type T from the form
|
|
5
|
-
*/
|
|
6
|
-
export declare function serializeForm<T extends object>(form: HTMLFormElement, log?: boolean): T;
|
|
1
|
+
/**
|
|
2
|
+
* Serialize a form into an object
|
|
3
|
+
* @param form The form to serialize
|
|
4
|
+
* @returns An object of type T from the form
|
|
5
|
+
*/
|
|
6
|
+
export declare function serializeForm<T extends object>(form: HTMLFormElement, log?: boolean): T;
|
package/dist/Utils/FormUtil.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serializeForm = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Serialize a form into an object
|
|
6
|
-
* @param form The form to serialize
|
|
7
|
-
* @returns An object of type T from the form
|
|
8
|
-
*/
|
|
9
|
-
function serializeForm(form, log = false) {
|
|
10
|
-
const children = Array.from(form.children);
|
|
11
|
-
const formData = children.reduce((acc, child) => {
|
|
12
|
-
// Find inputs and selects
|
|
13
|
-
const elements = Array.from(child.querySelectorAll('input, select'));
|
|
14
|
-
if (['INPUT', 'SELECT'].includes(child.tagName))
|
|
15
|
-
elements.push(child);
|
|
16
|
-
for (const element of Array.from(elements)) {
|
|
17
|
-
if (element.type === 'submit')
|
|
18
|
-
continue; // Ignore submit buttons
|
|
19
|
-
const name = element.getAttribute('name');
|
|
20
|
-
if (!name) {
|
|
21
|
-
console.error('[DanhoLibraryRJS] [FormUtil]: name attribute is required', { element });
|
|
22
|
-
throw new Error('name attribute is required');
|
|
23
|
-
}
|
|
24
|
-
const value = element.value;
|
|
25
|
-
if (value === null)
|
|
26
|
-
console.warn(`${name}.value returned null`, { element });
|
|
27
|
-
if (log)
|
|
28
|
-
console.log(`[DanhoLibraryRJS] [FormUtil]`, { name, value });
|
|
29
|
-
acc[name] = /^\d$/.test(value) ? parseInt(value) : value;
|
|
30
|
-
}
|
|
31
|
-
return acc;
|
|
32
|
-
}, {});
|
|
33
|
-
return formData;
|
|
34
|
-
}
|
|
35
|
-
exports.serializeForm = serializeForm;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeForm = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Serialize a form into an object
|
|
6
|
+
* @param form The form to serialize
|
|
7
|
+
* @returns An object of type T from the form
|
|
8
|
+
*/
|
|
9
|
+
function serializeForm(form, log = false) {
|
|
10
|
+
const children = Array.from(form.children);
|
|
11
|
+
const formData = children.reduce((acc, child) => {
|
|
12
|
+
// Find inputs and selects
|
|
13
|
+
const elements = Array.from(child.querySelectorAll('input, select'));
|
|
14
|
+
if (['INPUT', 'SELECT'].includes(child.tagName))
|
|
15
|
+
elements.push(child);
|
|
16
|
+
for (const element of Array.from(elements)) {
|
|
17
|
+
if (element.type === 'submit')
|
|
18
|
+
continue; // Ignore submit buttons
|
|
19
|
+
const name = element.getAttribute('name');
|
|
20
|
+
if (!name) {
|
|
21
|
+
console.error('[DanhoLibraryRJS] [FormUtil]: name attribute is required', { element });
|
|
22
|
+
throw new Error('name attribute is required');
|
|
23
|
+
}
|
|
24
|
+
const value = element.value;
|
|
25
|
+
if (value === null)
|
|
26
|
+
console.warn(`${name}.value returned null`, { element });
|
|
27
|
+
if (log)
|
|
28
|
+
console.log(`[DanhoLibraryRJS] [FormUtil]`, { name, value });
|
|
29
|
+
acc[name] = /^\d$/.test(value) ? parseInt(value) : value;
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
return formData;
|
|
34
|
+
}
|
|
35
|
+
exports.serializeForm = serializeForm;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeForm = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Serialize a form into an object
|
|
6
|
+
* @param form The form to serialize
|
|
7
|
+
* @returns An object of type T from the form
|
|
8
|
+
*/
|
|
9
|
+
function serializeForm(form, log = false) {
|
|
10
|
+
const children = Array.from(form.children);
|
|
11
|
+
const formData = children.reduce((acc, child) => {
|
|
12
|
+
// Find inputs and selects
|
|
13
|
+
const elements = Array.from(child.querySelectorAll('input, select'));
|
|
14
|
+
if (['INPUT', 'SELECT'].includes(child.tagName))
|
|
15
|
+
elements.push(child);
|
|
16
|
+
for (const element of Array.from(elements)) {
|
|
17
|
+
if (element.type === 'submit')
|
|
18
|
+
continue; // Ignore submit buttons
|
|
19
|
+
const name = element.getAttribute('name');
|
|
20
|
+
if (!name) {
|
|
21
|
+
console.error('[DanhoLibraryJS] [FormUtil]: name attribute is required', { element });
|
|
22
|
+
throw new Error('name attribute is required');
|
|
23
|
+
}
|
|
24
|
+
const value = element.value;
|
|
25
|
+
if (value === null)
|
|
26
|
+
console.warn(`${name}.value returned null`, { element });
|
|
27
|
+
if (log)
|
|
28
|
+
console.log(`[DanhoLibraryJS] [FormUtil]`, { name, value });
|
|
29
|
+
acc[name] = /^\d$/.test(value) ? parseInt(value) : value;
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
}, {});
|
|
33
|
+
return formData;
|
|
34
|
+
}
|
|
35
|
+
exports.serializeForm = serializeForm;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function between(min: number, max: number): number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type PatchEvent = 'before' | 'instead' | 'after';
|
|
2
|
+
type PatcherReplacement<TTarget extends object, TProperty extends keyof TTarget, TPatchEvent extends PatchEvent> = (TPatchEvent extends 'before' ? TTarget[TProperty] extends (...args: infer TArgs) => any ? (...args: TArgs) => TArgs | void : (current: TTarget[TProperty], update: TTarget[TProperty]) => TTarget[TProperty] | void : TPatchEvent extends 'instead' ? TTarget[TProperty] extends (...args: infer TArgs) => infer TReturn ? (...args: TArgs) => TReturn : (current: TTarget[TProperty], update: TTarget[TProperty]) => TTarget[TProperty] : TTarget[TProperty] extends (...args: infer TArgs) => any ? (...args: TArgs) => void : (previous: TTarget[TProperty], updated: TTarget[TProperty]) => void);
|
|
3
|
+
export declare function patch<TTarget extends object, TProperty extends keyof TTarget, TPatchEvent extends PatchEvent, TPatchReplacement extends PatcherReplacement<TTarget, TProperty, TPatchEvent>>(target: TTarget, property: TProperty, event: TPatchEvent, replacement: TPatchReplacement): (() => TTarget[TProperty] & Function) | (() => TTarget) | undefined;
|
|
4
|
+
export declare function unpatch<TTarget extends object, TProperty extends keyof TTarget>(target: TTarget, property: TProperty): void;
|
|
5
|
+
export declare function unpatchAll(): void;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unpatchAll = exports.unpatch = exports.patch = void 0;
|
|
4
|
+
const PATCHES = new Map();
|
|
5
|
+
function patch(target, property, event, replacement) {
|
|
6
|
+
if (!target || !property || !replacement)
|
|
7
|
+
return;
|
|
8
|
+
else if (!(property in target))
|
|
9
|
+
throw Error(`Property "${String(property)}" does not exist on target`);
|
|
10
|
+
const original = target[property];
|
|
11
|
+
if (!PATCHES.has(target))
|
|
12
|
+
PATCHES.set(target, new Map());
|
|
13
|
+
const targetPatches = PATCHES.get(target);
|
|
14
|
+
if (!targetPatches.has(property))
|
|
15
|
+
targetPatches.set(property, []);
|
|
16
|
+
const unpatch = (() => {
|
|
17
|
+
if (typeof original === 'function') {
|
|
18
|
+
switch (event) {
|
|
19
|
+
case 'before': {
|
|
20
|
+
target[property] = function (...args) {
|
|
21
|
+
const updatedArgs = replacement.apply(target, args);
|
|
22
|
+
return original.apply(target, updatedArgs || args);
|
|
23
|
+
};
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
case 'instead': {
|
|
27
|
+
target[property] = function (...args) {
|
|
28
|
+
return replacement.apply(target, args);
|
|
29
|
+
};
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case 'after': {
|
|
33
|
+
target[property] = function (...args) {
|
|
34
|
+
const result = original.apply(target, args);
|
|
35
|
+
replacement.apply(target, args);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return () => target[property] = original;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
let currentValue = target[property];
|
|
45
|
+
const propertyDescriptor = Object.getOwnPropertyDescriptor(target, property);
|
|
46
|
+
const valuePatch = (update) => {
|
|
47
|
+
update ??= currentValue;
|
|
48
|
+
const result = event !== 'after' ? replacement(currentValue, update) || currentValue : currentValue;
|
|
49
|
+
if (event === 'after')
|
|
50
|
+
replacement(currentValue, update);
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(target, property, {
|
|
54
|
+
get: () => valuePatch(),
|
|
55
|
+
set: valuePatch,
|
|
56
|
+
});
|
|
57
|
+
return () => Object.defineProperty(target, property, propertyDescriptor);
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
targetPatches.get(property).push({ event, replacement, original, unpatch });
|
|
61
|
+
return unpatch;
|
|
62
|
+
}
|
|
63
|
+
exports.patch = patch;
|
|
64
|
+
function unpatch(target, property) {
|
|
65
|
+
const targetPatches = PATCHES.get(target);
|
|
66
|
+
if (!targetPatches?.has(property))
|
|
67
|
+
return;
|
|
68
|
+
targetPatches.get(property).forEach(patch => patch.unpatch());
|
|
69
|
+
targetPatches.delete(property);
|
|
70
|
+
}
|
|
71
|
+
exports.unpatch = unpatch;
|
|
72
|
+
function unpatchAll() {
|
|
73
|
+
PATCHES.forEach(properties => {
|
|
74
|
+
properties.forEach(patches => {
|
|
75
|
+
patches.forEach(patch => patch.unpatch());
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
PATCHES.clear();
|
|
79
|
+
}
|
|
80
|
+
exports.unpatchAll = unpatchAll;
|