danholibraryjs 2.0.0 → 2.0.1
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/README.md +0 -1
- package/_package.github-release.json +6 -0
- package/_package.npm-release.json +6 -0
- package/dist/Extensions/Array/index.d.ts +6 -20
- package/dist/Extensions/Array/index.js +8 -26
- package/dist/Extensions/Object/index.d.ts +4 -10
- package/dist/Extensions/Object/index.js +6 -22
- package/dist/Extensions/Object/properties.extension.d.ts +28 -1
- package/dist/Extensions/Object/properties.extension.js +19 -2
- package/dist/Extensions/Object/properties.js +2 -1
- package/dist/Extensions/String/index.d.ts +1 -4
- package/dist/Extensions/String/index.js +3 -16
- package/dist/Extensions/index.d.ts +2 -2
- package/dist/Extensions/index.js +2 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/docs/Classes.md +78 -3
- package/docs/Extensions.md +219 -78
- package/docs/Types.md +202 -58
- package/docs/index.md +0 -1
- package/package.json +1 -1
- package/src/Extensions/Array/index.ts +6 -15
- package/src/Extensions/Object/index.ts +4 -11
- package/src/Extensions/Object/properties.extension.ts +50 -2
- package/src/Extensions/Object/properties.ts +2 -1
- package/src/Extensions/String/index.ts +1 -5
- package/src/Extensions/index.ts +2 -2
- package/src/index.ts +0 -1
- package/dist/Extensions/Array.d.ts +0 -52
- package/dist/Extensions/Array.js +0 -51
- package/dist/Extensions/Document.d.ts +0 -27
- package/dist/Extensions/Document.js +0 -32
- package/dist/Extensions/String.d.ts +0 -36
- package/dist/Extensions/String.js +0 -25
- package/dist/Functions/CopyToClipboard.d.ts +0 -7
- package/dist/Functions/CopyToClipboard.js +0 -15
- package/dist/Functions/GetCSSProperty.d.ts +0 -15
- package/dist/Functions/GetCSSProperty.js +0 -26
- package/dist/Functions/GetNestedProperty.d.ts +0 -9
- package/dist/Functions/GetNestedProperty.js +0 -23
- package/dist/Functions/HTMLEvent.d.ts +0 -11
- package/dist/Functions/HTMLEvent.js +0 -14
- package/dist/Functions/SetNavigationSelected.d.ts +0 -9
- package/dist/Functions/SetNavigationSelected.js +0 -25
- package/dist/Functions/index.d.ts +0 -5
- package/dist/Functions/index.js +0 -21
- package/dist/Utils/ApiUtil/ApiTypes.d.ts +0 -15
- package/dist/Utils/ApiUtil/ApiTypes.js +0 -15
- package/dist/Utils/ApiUtil/RequestUtil.d.ts +0 -19
- package/dist/Utils/ApiUtil/RequestUtil.js +0 -73
- package/dist/Utils/ApiUtil/index.d.ts +0 -20
- package/dist/Utils/ApiUtil/index.js +0 -33
- package/dist/Utils/FormUtil.d.ts +0 -6
- package/dist/Utils/FormUtil.js +0 -35
- package/docs/Functions.md +0 -61
- package/src/Extensions/Document.ts +0 -58
- package/src/Functions/CopyToClipboard.ts +0 -10
- package/src/Functions/GetCSSProperty.ts +0 -27
- package/src/Functions/GetNestedProperty.ts +0 -29
- package/src/Functions/HTMLEvent.ts +0 -13
- package/src/Functions/SetNavigationSelected.ts +0 -19
- package/src/Functions/index.ts +0 -5
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import IReplacement from "../Interfaces/IReplacement";
|
|
2
|
-
declare global {
|
|
3
|
-
interface String {
|
|
4
|
-
/**
|
|
5
|
-
* Uppercases first letter of string
|
|
6
|
-
*/
|
|
7
|
-
toPascalCase(): string;
|
|
8
|
-
/**
|
|
9
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '_')
|
|
10
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
11
|
-
*/
|
|
12
|
-
toSnakeCase(replaceOptions?: IReplacement): string;
|
|
13
|
-
/**
|
|
14
|
-
* Replaces "replacer" (default: ' ') with "replacement" (default: '-')
|
|
15
|
-
* @param replaceOptions This is practically your stereotypical String.replace, if you really want it to be
|
|
16
|
-
*/
|
|
17
|
-
toKebabCase(replaceOptions?: IReplacement): string;
|
|
18
|
-
/**
|
|
19
|
-
* String.substring but accepting negative numbers to cut from length
|
|
20
|
-
* @param start Start of string. 0 indexed, if negative number, subtracts number from length
|
|
21
|
-
* @param end End of string. 0 indexed, if negative number, substracts number from length
|
|
22
|
-
*/
|
|
23
|
-
clip(start: number, end?: number): string;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
declare function toPascalCase(this: string): string;
|
|
27
|
-
declare function toSnakeCase(this: string, replaceOptions: IReplacement): string;
|
|
28
|
-
declare function toKebabCase(this: string, replaceOptions: IReplacement): string;
|
|
29
|
-
declare function clip(this: string, start: number, end?: number): string;
|
|
30
|
-
export declare const StringExtensions: {
|
|
31
|
-
toPascalCase: typeof toPascalCase;
|
|
32
|
-
toSnakeCase: typeof toSnakeCase;
|
|
33
|
-
toKebabCase: typeof toKebabCase;
|
|
34
|
-
clip: typeof clip;
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StringExtensions = void 0;
|
|
4
|
-
function toPascalCase() {
|
|
5
|
-
return this.substring(0, 1).toUpperCase() + this.substring(1);
|
|
6
|
-
}
|
|
7
|
-
String.prototype.toPascalCase = toPascalCase;
|
|
8
|
-
function spaceReplacer(self, replacer, replacement) {
|
|
9
|
-
return self.replace(new RegExp(`${typeof replacer == 'string' ? replacer : replacer.source}+`), replacement);
|
|
10
|
-
}
|
|
11
|
-
function toSnakeCase(replaceOptions) {
|
|
12
|
-
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '_');
|
|
13
|
-
}
|
|
14
|
-
String.prototype.toSnakeCase = toSnakeCase;
|
|
15
|
-
function toKebabCase(replaceOptions) {
|
|
16
|
-
return spaceReplacer(this, replaceOptions.replacer || ' ', replaceOptions.replacement || '-');
|
|
17
|
-
}
|
|
18
|
-
String.prototype.toKebabCase = toKebabCase;
|
|
19
|
-
function clip(start, end) {
|
|
20
|
-
return this.substring(start < 0 ? this.length - start : start, end && end < 0 ? this.length + end : end);
|
|
21
|
-
}
|
|
22
|
-
String.prototype.clip = clip;
|
|
23
|
-
exports.StringExtensions = {
|
|
24
|
-
toPascalCase, toSnakeCase, toKebabCase, clip
|
|
25
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
3
|
-
* @param value Value to clipboard
|
|
4
|
-
* @param response Alerts if response is given
|
|
5
|
-
*/
|
|
6
|
-
export declare function CopyToClipboard(value: string, response?: string): Promise<void>;
|
|
7
|
-
export default CopyToClipboard;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CopyToClipboard = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
6
|
-
* @param value Value to clipboard
|
|
7
|
-
* @param response Alerts if response is given
|
|
8
|
-
*/
|
|
9
|
-
async function CopyToClipboard(value, response) {
|
|
10
|
-
await navigator.clipboard.writeText(value);
|
|
11
|
-
if (response)
|
|
12
|
-
alert(response);
|
|
13
|
-
}
|
|
14
|
-
exports.CopyToClipboard = CopyToClipboard;
|
|
15
|
-
exports.default = CopyToClipboard;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
type CSSReturnTypes = {
|
|
2
|
-
string: string;
|
|
3
|
-
number: number;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
7
|
-
* Basically, you can get your --color-primary from :root
|
|
8
|
-
*
|
|
9
|
-
* @param property Name of the property to get
|
|
10
|
-
* @param type Type of the property to parse
|
|
11
|
-
* @param query Query to get the element that has the property
|
|
12
|
-
* @returns Property value converted to type
|
|
13
|
-
*/
|
|
14
|
-
export declare function GetCSSProperty<Type extends keyof CSSReturnTypes>(property: string, type: Type, query?: string): CSSReturnTypes[Type];
|
|
15
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetCSSProperty = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
6
|
-
* Basically, you can get your --color-primary from :root
|
|
7
|
-
*
|
|
8
|
-
* @param property Name of the property to get
|
|
9
|
-
* @param type Type of the property to parse
|
|
10
|
-
* @param query Query to get the element that has the property
|
|
11
|
-
* @returns Property value converted to type
|
|
12
|
-
*/
|
|
13
|
-
function GetCSSProperty(property, type, query = ":root") {
|
|
14
|
-
const rootEl = document.querySelector(query);
|
|
15
|
-
if (!rootEl)
|
|
16
|
-
throw new Error(`${query} does not exist!`);
|
|
17
|
-
const rootStyles = getComputedStyle(rootEl);
|
|
18
|
-
const cssProp = rootStyles.getPropertyValue(property);
|
|
19
|
-
if (type === 'string')
|
|
20
|
-
return cssProp;
|
|
21
|
-
const numberValue = parseInt(cssProp);
|
|
22
|
-
if (isNaN(numberValue))
|
|
23
|
-
throw new Error(`${property} is not a number!: ${cssProp}`);
|
|
24
|
-
return numberValue;
|
|
25
|
-
}
|
|
26
|
-
exports.GetCSSProperty = GetCSSProperty;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type GetNestedProperty<Parent, Key extends string> = Key extends keyof Parent ? Parent[Key] : Key extends `${infer K}.${infer Rest}` ? K extends keyof Parent ? GetNestedProperty<Parent[K], Rest> : never : never;
|
|
2
|
-
/**
|
|
3
|
-
* Gets a nested property from an object
|
|
4
|
-
* @param parent Parent object to search
|
|
5
|
-
* @param key Key to search for. Can be nested with dot notation
|
|
6
|
-
* @returns Value of key or null if not found
|
|
7
|
-
*/
|
|
8
|
-
export declare function GetNestedProperty<Parent extends object, Key extends string>(parent: Parent, key: Key): GetNestedProperty<Parent, Key> | null;
|
|
9
|
-
export default GetNestedProperty;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GetNestedProperty = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Gets a nested property from an object
|
|
6
|
-
* @param parent Parent object to search
|
|
7
|
-
* @param key Key to search for. Can be nested with dot notation
|
|
8
|
-
* @returns Value of key or null if not found
|
|
9
|
-
*/
|
|
10
|
-
function GetNestedProperty(parent, key) {
|
|
11
|
-
if (key in parent)
|
|
12
|
-
return parent[key];
|
|
13
|
-
for (const prop in parent) {
|
|
14
|
-
if (typeof parent[prop] === 'object') {
|
|
15
|
-
const result = GetNestedProperty(parent[prop], key);
|
|
16
|
-
if (result)
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
exports.GetNestedProperty = GetNestedProperty;
|
|
23
|
-
exports.default = GetNestedProperty;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create HTMLEvent object from function
|
|
3
|
-
* @param name Name of the event
|
|
4
|
-
* @param handler Handler for the event
|
|
5
|
-
* @returns Parameters as object
|
|
6
|
-
*/
|
|
7
|
-
export declare function HTMLEvent<Event extends keyof HTMLElementEventMap, ReturnType extends any>(name: Event, handler: (event: HTMLElementEventMap[Event]) => ReturnType): {
|
|
8
|
-
name: Event;
|
|
9
|
-
handler: (event: HTMLElementEventMap[Event]) => ReturnType;
|
|
10
|
-
};
|
|
11
|
-
export default HTMLEvent;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HTMLEvent = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Create HTMLEvent object from function
|
|
6
|
-
* @param name Name of the event
|
|
7
|
-
* @param handler Handler for the event
|
|
8
|
-
* @returns Parameters as object
|
|
9
|
-
*/
|
|
10
|
-
function HTMLEvent(name, handler) {
|
|
11
|
-
return { name, handler };
|
|
12
|
-
}
|
|
13
|
-
exports.HTMLEvent = HTMLEvent;
|
|
14
|
-
exports.default = HTMLEvent;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Appends classes to header's "a" elements, when navigation to "a"'s page is selected
|
|
3
|
-
* @param query The query selector for Document.querySelector
|
|
4
|
-
* @param currentPageClasses Class(es) to append header's "a" elements
|
|
5
|
-
*
|
|
6
|
-
* @borrows Document.querySelector
|
|
7
|
-
*/
|
|
8
|
-
export declare function SetNavigationSelected(query: string, ...currentPageClasses: string[]): void;
|
|
9
|
-
export default SetNavigationSelected;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SetNavigationSelected = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Appends classes to header's "a" elements, when navigation to "a"'s page is selected
|
|
6
|
-
* @param query The query selector for Document.querySelector
|
|
7
|
-
* @param currentPageClasses Class(es) to append header's "a" elements
|
|
8
|
-
*
|
|
9
|
-
* @borrows Document.querySelector
|
|
10
|
-
*/
|
|
11
|
-
function SetNavigationSelected(query, ...currentPageClasses) {
|
|
12
|
-
const header = document.querySelector(query);
|
|
13
|
-
if (!header)
|
|
14
|
-
throw { message: `Couldn't find header from query, ${query}` };
|
|
15
|
-
const children = header.children.array().filter(c => c.tagName === 'a');
|
|
16
|
-
const currentPage = document.location.href;
|
|
17
|
-
children.forEach(gc => {
|
|
18
|
-
if (gc.href != currentPage)
|
|
19
|
-
gc.classList.remove(...currentPageClasses);
|
|
20
|
-
else
|
|
21
|
-
gc.classList.add(...currentPageClasses);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
exports.SetNavigationSelected = SetNavigationSelected;
|
|
25
|
-
exports.default = SetNavigationSelected;
|
package/dist/Functions/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./CopyToClipboard"), exports);
|
|
18
|
-
__exportStar(require("./GetCSSProperty"), exports);
|
|
19
|
-
__exportStar(require("./GetNestedProperty"), exports);
|
|
20
|
-
__exportStar(require("./SetNavigationSelected"), exports);
|
|
21
|
-
__exportStar(require("./HTMLEvent"), exports);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export type TParam = string | undefined;
|
|
2
|
-
export type HttpMethods = 'GET' | 'POST' | 'PUT' | '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
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
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]
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
|
@@ -1,73 +0,0 @@
|
|
|
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;
|
|
@@ -1,20 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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;
|
package/dist/Utils/FormUtil.d.ts
DELETED
package/dist/Utils/FormUtil.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
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;
|
package/docs/Functions.md
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# [DanhoLibraryJS](../README.md)
|
|
2
|
-
|
|
3
|
-
## Functions
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
/**
|
|
7
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
8
|
-
* @param value Value to clipboard
|
|
9
|
-
* @param response Alerts if response is given
|
|
10
|
-
*/
|
|
11
|
-
async function CopyToClipboard(value: string, response?: string): Promise<void>;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
15
|
-
* Basically, you can get your --color-primary from :root
|
|
16
|
-
*
|
|
17
|
-
* @param property Name of the property to get
|
|
18
|
-
* @param type Type of the property to parse
|
|
19
|
-
* @param query Query to get the element that has the property
|
|
20
|
-
* @returns Property value converted to type
|
|
21
|
-
*/
|
|
22
|
-
function GetCSSProperty<Type extends keyof CSSReturnTypes>(property: string, type: Type, query = ":root"): CSSReturnTypes[Type];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Gets a nested property from an object
|
|
26
|
-
* @param parent Parent object to search
|
|
27
|
-
* @param key Key to search for. Can be nested with dot notation
|
|
28
|
-
* @returns Value of key or null if not found
|
|
29
|
-
*/
|
|
30
|
-
function GetNestedProperty<Parent, Key extends string>(parent: Parent, key: Key): GetNestedProperty<Parent, Key> | null;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Create HTMLEvent object from function
|
|
34
|
-
* @param name Name of the event
|
|
35
|
-
* @param handler Handler for the event
|
|
36
|
-
* @returns Parameters as object
|
|
37
|
-
*/
|
|
38
|
-
function HTMLEvent<
|
|
39
|
-
Event extends keyof HTMLElementEventMap,
|
|
40
|
-
ReturnType extends any
|
|
41
|
-
>(name: Event, handler: (event: HTMLElementEventMap[Event]) => ReturnType): {
|
|
42
|
-
name: Event,
|
|
43
|
-
handler: (event: HTMLElementEventMap[Event]) => ReturnType
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Appends classes to header's "a" elements, when navigation to "a"'s page is selected
|
|
48
|
-
* @param query The query selector for Document.querySelector
|
|
49
|
-
* @param currentPageClasses Class(es) to append header's "a" elements
|
|
50
|
-
*
|
|
51
|
-
* @borrows Document.querySelector
|
|
52
|
-
*/
|
|
53
|
-
function SetNavigationSelected(query: string, ...currentPageClasses: Array<string>): void;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Converts input into milliseconds
|
|
57
|
-
* @param input Input to convert to ms. 1s | 2m | 3h | 1M | 60000
|
|
58
|
-
* @returns Millisecond value of input
|
|
59
|
-
*/
|
|
60
|
-
function ms(input: TimeDelay): number
|
|
61
|
-
```
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { IElement } from "../Types";
|
|
2
|
-
|
|
3
|
-
declare global {
|
|
4
|
-
interface Document {
|
|
5
|
-
/**
|
|
6
|
-
* Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
|
|
7
|
-
* @param tagName HTMLElement tag name
|
|
8
|
-
* @param options Construction options, instead of assigning values after construction
|
|
9
|
-
* @param children Child elements
|
|
10
|
-
*/
|
|
11
|
-
createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]>, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
|
|
12
|
-
createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
|
|
13
|
-
createElementFromString<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K];
|
|
14
|
-
}
|
|
15
|
-
interface HTMLCollection {
|
|
16
|
-
/**
|
|
17
|
-
* Converts HTMLCollection to Element[]
|
|
18
|
-
*/
|
|
19
|
-
array(): Element[];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function createElement<Tag extends keyof HTMLElementTagNameMap>(
|
|
24
|
-
this: Document, tagName: Tag,
|
|
25
|
-
options?: Partial<HTMLElementTagNameMap[Tag]> | string,
|
|
26
|
-
...children: Array<IElement>
|
|
27
|
-
): HTMLElementTagNameMap[Tag] {
|
|
28
|
-
|
|
29
|
-
const element = Object.assign(document.createElement(tagName), typeof options === 'string' ? {} : options);
|
|
30
|
-
children ??= typeof options === 'string' ? [options] as Array<IElement> : [];
|
|
31
|
-
typeof options === 'string' && children.unshift(options);
|
|
32
|
-
|
|
33
|
-
if (!children.length) return element;
|
|
34
|
-
else if (typeof children === 'string') element.innerHTML = children;
|
|
35
|
-
else if (children instanceof Array) children.forEach(child => (
|
|
36
|
-
typeof child === 'string' ?
|
|
37
|
-
element.innerHTML += child :
|
|
38
|
-
element.appendChild(child)
|
|
39
|
-
));
|
|
40
|
-
else element.appendChild(children);
|
|
41
|
-
return element;
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
Document.prototype.createProperElement = createElement;
|
|
45
|
-
|
|
46
|
-
function createElementFromString<Tag extends keyof HTMLElementTagNameMap>(this: Document, html: string, tag?: Tag): HTMLElementTagNameMap[Tag] {
|
|
47
|
-
if (!html.startsWith(`<${tag}`)) html = `<${tag}>${html}</${tag}>`;
|
|
48
|
-
return new DOMParser().parseFromString(html, 'text/html').body.firstElementChild as HTMLElementTagNameMap[Tag];
|
|
49
|
-
}
|
|
50
|
-
Document.prototype.createElementFromString = createElementFromString;
|
|
51
|
-
|
|
52
|
-
HTMLCollection.prototype.array = function (this: HTMLCollection) {
|
|
53
|
-
return Array.from(this);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const DocumentExtensions = {
|
|
57
|
-
createElement, createElementFromString
|
|
58
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copies value to clipboard and alerts a response, if response is defined
|
|
3
|
-
* @param value Value to clipboard
|
|
4
|
-
* @param response Alerts if response is given
|
|
5
|
-
*/
|
|
6
|
-
export async function CopyToClipboard(value: string, response?: string) {
|
|
7
|
-
await navigator.clipboard.writeText(value);
|
|
8
|
-
if (response) alert(response);
|
|
9
|
-
}
|
|
10
|
-
export default CopyToClipboard;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
type CSSReturnTypes = {
|
|
2
|
-
string: string,
|
|
3
|
-
number: number
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Gets the value of "property" in type "type" from query "query"
|
|
8
|
-
* Basically, you can get your --color-primary from :root
|
|
9
|
-
*
|
|
10
|
-
* @param property Name of the property to get
|
|
11
|
-
* @param type Type of the property to parse
|
|
12
|
-
* @param query Query to get the element that has the property
|
|
13
|
-
* @returns Property value converted to type
|
|
14
|
-
*/
|
|
15
|
-
export function GetCSSProperty<Type extends keyof CSSReturnTypes>(property: string, type: Type, query = ":root"): CSSReturnTypes[Type] {
|
|
16
|
-
const rootEl = document.querySelector(query);
|
|
17
|
-
if (!rootEl) throw new Error(`${query} does not exist!`);
|
|
18
|
-
|
|
19
|
-
const rootStyles = getComputedStyle(rootEl);
|
|
20
|
-
const cssProp = rootStyles.getPropertyValue(property);
|
|
21
|
-
if (type === 'string') return cssProp as CSSReturnTypes[Type];
|
|
22
|
-
|
|
23
|
-
const numberValue = parseInt(cssProp);
|
|
24
|
-
if (isNaN(numberValue)) throw new Error(`${property} is not a number!: ${cssProp}`);
|
|
25
|
-
return numberValue as CSSReturnTypes[Type];
|
|
26
|
-
}
|
|
27
|
-
|