danholibraryjs 2.0.0 → 2.0.2

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.
Files changed (94) hide show
  1. package/README.md +1 -1
  2. package/_package.github-release.json +6 -0
  3. package/_package.npm-release.json +6 -0
  4. package/dist/Extensions/Array/index.d.ts +6 -20
  5. package/dist/Extensions/Array/index.js +8 -26
  6. package/dist/Extensions/Array/random.extension.d.ts +1 -2
  7. package/dist/Extensions/Array/random.extension.js +1 -22
  8. package/dist/Extensions/Array/string.extension.d.ts +3 -4
  9. package/dist/Extensions/Number.d.ts +2 -2
  10. package/dist/Extensions/Number.js +1 -1
  11. package/dist/Extensions/Object/arrays.extension.d.ts +14 -0
  12. package/dist/Extensions/Object/arrays.extension.js +7 -2
  13. package/dist/Extensions/Object/extracts.extension.d.ts +6 -6
  14. package/dist/Extensions/Object/extracts.extension.js +10 -7
  15. package/dist/Extensions/Object/index.d.ts +4 -10
  16. package/dist/Extensions/Object/index.js +6 -22
  17. package/dist/Extensions/Object/properties.extension.d.ts +28 -1
  18. package/dist/Extensions/Object/properties.extension.js +19 -2
  19. package/dist/Extensions/Object/properties.js +2 -1
  20. package/dist/Extensions/String/index.d.ts +2 -4
  21. package/dist/Extensions/String/index.js +4 -16
  22. package/dist/Extensions/String/string.extension.d.ts +6 -0
  23. package/dist/Extensions/String/string.extension.js +10 -0
  24. package/dist/Extensions/index.d.ts +2 -2
  25. package/dist/Extensions/index.js +2 -2
  26. package/dist/Types/Able.d.ts +1 -1
  27. package/dist/Utils/NumberUtils.d.ts +5 -0
  28. package/dist/Utils/NumberUtils.js +25 -1
  29. package/dist/Utils/StringUtils.d.ts +5 -0
  30. package/dist/Utils/StringUtils.js +6 -1
  31. package/dist/Utils/TimeUtils/index.d.ts +3 -0
  32. package/dist/Utils/TimeUtils/index.js +2 -0
  33. package/dist/Utils/TimeUtils/string.util.d.ts +3 -0
  34. package/dist/Utils/TimeUtils/string.util.js +19 -0
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.js +1 -1
  37. package/docs/Classes.md +78 -3
  38. package/docs/Extensions.md +247 -73
  39. package/docs/Types.md +202 -58
  40. package/docs/Utils.md +335 -0
  41. package/docs/index.md +1 -1
  42. package/package.json +1 -1
  43. package/src/Extensions/Array/index.ts +6 -15
  44. package/src/Extensions/Array/random.extension.ts +2 -25
  45. package/src/Extensions/Array/string.extension.ts +3 -4
  46. package/src/Extensions/Number.ts +3 -3
  47. package/src/Extensions/Object/arrays.extension.ts +23 -2
  48. package/src/Extensions/Object/extracts.extension.ts +18 -13
  49. package/src/Extensions/Object/index.ts +4 -11
  50. package/src/Extensions/Object/properties.extension.ts +50 -2
  51. package/src/Extensions/String/index.ts +2 -5
  52. package/src/Extensions/String/string.extension.ts +11 -0
  53. package/src/Extensions/index.ts +2 -2
  54. package/src/Types/Able.ts +1 -1
  55. package/src/Utils/NumberUtils.ts +27 -0
  56. package/src/Utils/StringUtils.ts +7 -1
  57. package/src/Utils/TimeUtils/index.ts +2 -0
  58. package/src/Utils/TimeUtils/string.util.ts +13 -0
  59. package/src/index.ts +2 -2
  60. package/dist/Extensions/Array.d.ts +0 -52
  61. package/dist/Extensions/Array.js +0 -51
  62. package/dist/Extensions/Document.d.ts +0 -27
  63. package/dist/Extensions/Document.js +0 -32
  64. package/dist/Extensions/String.d.ts +0 -36
  65. package/dist/Extensions/String.js +0 -25
  66. package/dist/Functions/CopyToClipboard.d.ts +0 -7
  67. package/dist/Functions/CopyToClipboard.js +0 -15
  68. package/dist/Functions/GetCSSProperty.d.ts +0 -15
  69. package/dist/Functions/GetCSSProperty.js +0 -26
  70. package/dist/Functions/GetNestedProperty.d.ts +0 -9
  71. package/dist/Functions/GetNestedProperty.js +0 -23
  72. package/dist/Functions/HTMLEvent.d.ts +0 -11
  73. package/dist/Functions/HTMLEvent.js +0 -14
  74. package/dist/Functions/SetNavigationSelected.d.ts +0 -9
  75. package/dist/Functions/SetNavigationSelected.js +0 -25
  76. package/dist/Functions/index.d.ts +0 -5
  77. package/dist/Functions/index.js +0 -21
  78. package/dist/Utils/ApiUtil/ApiTypes.d.ts +0 -15
  79. package/dist/Utils/ApiUtil/ApiTypes.js +0 -15
  80. package/dist/Utils/ApiUtil/RequestUtil.d.ts +0 -19
  81. package/dist/Utils/ApiUtil/RequestUtil.js +0 -73
  82. package/dist/Utils/ApiUtil/index.d.ts +0 -20
  83. package/dist/Utils/ApiUtil/index.js +0 -33
  84. package/dist/Utils/FormUtil.d.ts +0 -6
  85. package/dist/Utils/FormUtil.js +0 -35
  86. package/docs/Functions.md +0 -61
  87. package/src/Extensions/Document.ts +0 -58
  88. package/src/Extensions/Object/properties.ts +0 -50
  89. package/src/Functions/CopyToClipboard.ts +0 -10
  90. package/src/Functions/GetCSSProperty.ts +0 -27
  91. package/src/Functions/GetNestedProperty.ts +0 -29
  92. package/src/Functions/HTMLEvent.ts +0 -13
  93. package/src/Functions/SetNavigationSelected.ts +0 -19
  94. package/src/Functions/index.ts +0 -5
@@ -1,15 +1,6 @@
1
- import * as Array from './array.extension';
2
- import * as CRUD from './crud.extension';
3
- import * as Loop from './loop.extension';
4
- import * as Random from './random.extension';
5
- import * as Sort from './sort.extension';
6
- import * as String from './string.extension';
7
-
8
- export const ArrayExtensions = {
9
- ...Array,
10
- ...CRUD,
11
- ...Loop,
12
- ...Random,
13
- ...Sort,
14
- ...String,
15
- };
1
+ export * from './array.extension';
2
+ export * from './crud.extension';
3
+ export * from './loop.extension';
4
+ export * from './random.extension';
5
+ export * from './sort.extension';
6
+ export * from './string.extension';
@@ -17,7 +17,7 @@ declare global {
17
17
  * @param items An array of tuples where each tuple contains an item and its corresponding weight.
18
18
  * @returns A randomly selected item based on the provided weights.
19
19
  */
20
- randomWithPercentages(items: [item: T, weight: number][]): T;
20
+ randomWithPercentages(items: Array<[item: T, weight: number]>): T;
21
21
  }
22
22
  }
23
23
 
@@ -30,27 +30,4 @@ Array.prototype.random = random;
30
30
  export function shuffle<T>(this: Array<T>): Array<T> {
31
31
  return this.sort(() => Math.random() - 0.5);
32
32
  }
33
- Array.prototype.shuffle = shuffle;
34
-
35
- export function randomWithPercentages<T>(items: [item: T, weight: number][]): T {
36
- if (items.length === 0) throw new Error('Items array cannot be empty');
37
-
38
- // Calculate total weight in case weights don't sum to 100
39
- const totalWeight = items.reduce((sum, [, weight]) => sum + weight, 0);
40
- if (totalWeight === 0) throw new Error('Total weight must be greater than zero');
41
-
42
- // Generate random number between 0 and totalWeight
43
- const random = Math.random() * totalWeight;
44
-
45
- // Find the item that corresponds to this random value
46
- let currentWeight = 0;
47
- for (const [item, weight] of items) {
48
- currentWeight += weight;
49
- if (random <= currentWeight) {
50
- return item;
51
- }
52
- }
53
-
54
- throw new Error('Unable to select an item based on weights');
55
- }
56
- Array.prototype.randomWithPercentages = randomWithPercentages;
33
+ Array.prototype.shuffle = shuffle;
@@ -2,12 +2,11 @@ declare global {
2
2
  interface Array<T> {
3
3
  /**
4
4
  * Joins the elements of the array into a string, with optional custom separators.
5
- * @param args An array of strings or undefined values to be used as separators between elements.
6
- * @param separator The default separator to use between elements if args is not provided or undefined.
7
- * @param endSeparator The separator to use before the last element.
5
+ * @param separator The default separator to use between elements. Defaults to ','.
6
+ * @param endSeparator The separator to use before the last element. Default is '&'.
8
7
  * @returns A string with the joined elements.
9
8
  */
10
- join(args?: Array<string | undefined>, separator?: string, endSeparator?: string): string;
9
+ join(separator?: string, endSeparator?: string): string;
11
10
  }
12
11
  }
13
12
 
@@ -5,13 +5,13 @@ type Separators = {
5
5
 
6
6
  declare global {
7
7
  interface Number {
8
- toSeparationString(separators: Partial<Separators>): string;
8
+ toSeparationString(separators?: Partial<Separators>): string;
9
9
  toRomanNumeral(): string;
10
10
  }
11
11
  }
12
12
 
13
- export function toSeparationString(this: number, separators: Partial<Separators>): string {
14
- const { thousand = '.', decimal = '.' } = separators;
13
+ export function toSeparationString(this: number, separators?: Partial<Separators>): string {
14
+ const { thousand = '.', decimal = '.' } = separators || {};
15
15
  const [integerPart, decimalPart] = this.toString().split('.');
16
16
  const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousand);
17
17
  return decimalPart ? `${formattedInteger}${decimal}${decimalPart}` : formattedInteger;
@@ -7,6 +7,18 @@ declare global {
7
7
  * @param from Object to destruct
8
8
  */
9
9
  array<From extends {} = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
10
+ /**
11
+ * Destructures object into array of property keys or values depending on selector
12
+ * @param from Object to destruct
13
+ * @param selector Selects whether to return keys or values
14
+ */
15
+ array<From extends {} = {}>(from: From, selector: 'keys'): Array<keyof From>;
16
+ /**
17
+ * Destructures object into array of property keys or values depending on selector
18
+ * @param from Object to destruct
19
+ * @param selector Selects whether to return keys or values
20
+ */
21
+ array<From extends {} = {}>(from: From, selector: 'values'): Array<ValueOf<From>>;
10
22
 
11
23
  /**
12
24
  * Destructures object into array of property keys
@@ -16,8 +28,17 @@ declare global {
16
28
  }
17
29
  }
18
30
 
19
- export function array<From extends {} = {}>(this: object, from: From): Array<[keyof From, ValueOf<From>]> {
20
- return Object.entries(from) as Array<[keyof From, ValueOf<From>]>;
31
+ export function array<From extends {} = {}>(this: object, from: From): Array<[keyof From, ValueOf<From>]>;
32
+ export function array<From extends {} = {}>(this: object, from: From, selector: 'keys'): Array<keyof From>;
33
+ export function array<From extends {} = {}>(this: object, from: From, selector: 'values'): Array<ValueOf<From>>;
34
+ export function array<From extends {} = {}>(this: object, from: From, selector?: 'keys' | 'values') {
35
+ const entries = Object.entries(from) as Array<[keyof From, ValueOf<From>]>;
36
+
37
+ switch (selector) {
38
+ case 'keys': return entries.map(([key]) => key);
39
+ case 'values': return entries.map(([, value]) => value);
40
+ default: return entries;
41
+ }
21
42
  }
22
43
  Object.array = array;
23
44
 
@@ -15,20 +15,20 @@ declare global {
15
15
  pick<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
16
16
 
17
17
  /**
18
- * Receive an object with properties that are not in union of source and target objects
18
+ * Returns the difference between two objects (properties where values differ)
19
19
  * @param source Source object
20
20
  * @param target Target object
21
- * @param exclude Properties to exclude from difference
22
- * @returns Object with properties that are not in union of source and target objects, excluding specified properties
21
+ * @param exclude Properties to exclude from comparison
22
+ * @returns Object with properties where values differ between source and target, excluding specified properties
23
23
  */
24
- difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Omit<T, keyof T>;
24
+ difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Partial<T>;
25
25
 
26
26
  /**
27
27
  * Deeply combines objects, with later objects in parameters taking precedence over earlier ones. Does not combine arrays.
28
28
  * @param objects Objects to combine
29
29
  * @returns Combined object
30
30
  */
31
- combine<T extends Record<string, any | undefined>>(...objects: Array<Partial<T> | undefined>): T;
31
+ combine<T extends Record<string, any | undefined>>(...objects: Array<Combinable<T> | undefined>): T;
32
32
  }
33
33
  }
34
34
 
@@ -60,16 +60,21 @@ export function pick<From extends {}, Props extends keyof From>(from: From, ...p
60
60
  }
61
61
  Object.pick = pick;
62
62
 
63
- export function difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Omit<T, keyof T> {
64
- const diffKeys = new Set([...Object.keysOf(source), ...Object.keysOf(target)]);
65
- exclude?.forEach(key => diffKeys.delete(key));
63
+ export function difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Partial<T> {
64
+ const excludeSet = new Set(exclude);
65
+ const allKeys = new Set([...Object.keysOf(source), ...Object.keysOf(target)]);
66
66
 
67
- return [...diffKeys.values()].reduce((acc, key, i, arr) => {
68
- const sourceValue = JSON.stringify(source[key]);
69
- const targetValue = JSON.stringify(target[key]);
70
- if (sourceValue !== targetValue) acc[key] = target[key];
67
+ return [...allKeys].reduce((acc, key) => {
68
+ if (excludeSet.has(key)) return acc;
69
+
70
+ const sourceValue = (source as any)[key];
71
+ const targetValue = (target as any)[key];
72
+
73
+ if (JSON.stringify(sourceValue) !== JSON.stringify(targetValue)) {
74
+ acc[key] = targetValue;
75
+ }
71
76
  return acc;
72
- }, {} as T);
77
+ }, {} as any) as Partial<T>;
73
78
  }
74
79
  Object.difference = difference;
75
80
 
@@ -1,11 +1,4 @@
1
- import * as Array from './arrays.extension';
2
- import * as Booleans from './booleans.extension';
3
- import * as Extracts from './extracts.extension';
4
- import * as Properties from './properties.extension';
5
-
6
- export const ObjectExtensions = {
7
- ...Array,
8
- ...Booleans,
9
- ...Extracts,
10
- ...Properties
11
- };
1
+ export * from './arrays.extension';
2
+ export * from './booleans.extension';
3
+ export * from './extracts.extension';
4
+ export * from './properties.extension';
@@ -1,4 +1,37 @@
1
- import { Properties, properties } from "./properties";
1
+ import { PropertiesWith, If } from '../../Types';
2
+ import { convertCase } from '../String/case.extension';
3
+
4
+ type PrimitiveMap = {
5
+ string: string;
6
+ number: number;
7
+ boolean: boolean;
8
+ undefined: undefined;
9
+ null: null;
10
+ object: object;
11
+ function: Function;
12
+ any: any;
13
+ Date: Date;
14
+ RegExp: RegExp;
15
+ Promise: Promise<any>;
16
+ Array: Array<any>;
17
+ Map: Map<any, any>;
18
+ Set: Set<any>;
19
+ };
20
+
21
+ /**
22
+ * Object with getPrimitiveTypes<Source, AllowFunctions extends boolean>(
23
+ * source: Source,
24
+ * allowFunctions: AllowFunctions = false
25
+ * ): Object with properties from source that matches primitive type
26
+ */
27
+ export type Properties = {
28
+ [Key in keyof PrimitiveMap as `get${Capitalize<Key>}s`]:
29
+ <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions) =>
30
+ If<AllowFunctions,
31
+ PropertiesWith<PrimitiveMap[Key] | ((...args: any[]) => PrimitiveMap[Key]), Source>,
32
+ PropertiesWith<PrimitiveMap[Key], Source>
33
+ >
34
+ };
2
35
 
3
36
  declare global {
4
37
  interface ObjectConstructor {
@@ -6,6 +39,21 @@ declare global {
6
39
  }
7
40
  }
8
41
 
9
-
42
+ export const properties: Properties = [
43
+ 'string', 'number', 'boolean', 'undefined', 'null',
44
+ 'object', 'function', 'any',
45
+ 'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
46
+ ].reduce((result, primitive) => {
47
+ result[`get${convertCase('camel', 'pascal')}s` as keyof Properties] = function <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions: AllowFunctions = false as AllowFunctions) {
48
+ return Object.keysOf<Source>(source).reduce((result, key) => {
49
+ if ((source[key] as any).constructor.name === primitive ||
50
+ (withFunctions && typeof source[key] === 'function' && source[key] as any).constructor.name === primitive) {
51
+ result[key] = source[key];
52
+ }
53
+ return result;
54
+ }, {} as any);
55
+ };
56
+ return result;
57
+ }, {} as Properties);
10
58
 
11
59
  Object.properties = properties;
@@ -1,5 +1,2 @@
1
- import * as Case from './case.extension';
2
-
3
- export const StringUtils = {
4
- ...Case,
5
- }
1
+ export * from './case.extension';
2
+ export * from './string.extension';
@@ -0,0 +1,11 @@
1
+ declare global {
2
+ interface String {
3
+ truncate(length: number, ellipsis?: string): string;
4
+ }
5
+ }
6
+
7
+ export function truncate(this: string, length: number, ellipsis: string = "..."): string {
8
+ if (this.length <= length) return this;
9
+ return this.slice(0, length - ellipsis.length) + ellipsis;
10
+ }
11
+ String.prototype.truncate = truncate;
@@ -1,6 +1,6 @@
1
1
  export * from './Array';
2
- export * from './Document';
2
+ export * from './Function';
3
3
  export * from './Map';
4
- export * from './Object';
5
4
  export * from './Number';
5
+ export * from './Object';
6
6
  export * from './String';
package/src/Types/Able.ts CHANGED
@@ -6,7 +6,7 @@ export type Functionable<T, Args extends any[] = []> = T | ((...args: Args) => T
6
6
  /**
7
7
  * Item is Promise<T> or T
8
8
  */
9
- export type Promisable<T> = T | Promise<T>;
9
+ export type Promiseable<T> = T | Promise<T>;
10
10
 
11
11
  /**
12
12
  * Item is T or null
@@ -1,3 +1,30 @@
1
1
  export function between(min: number, max: number): number {
2
2
  return Math.floor(Math.random() * (max - min + 1)) + min;
3
+ }
4
+
5
+ export function randomWithPercentages<T>(items: [item: T, weight: number][]): T {
6
+ if (items.length === 0) throw new Error('Items array cannot be empty');
7
+
8
+ // Calculate total weight in case weights don't sum to 100
9
+ const totalWeight = items.reduce((sum, [, weight]) => sum + weight, 0);
10
+ if (totalWeight === 0) throw new Error('Total weight must be greater than zero');
11
+
12
+ // Generate random number between 0 and totalWeight
13
+ const random = Math.random() * totalWeight;
14
+
15
+ // Find the item that corresponds to this random value
16
+ let currentWeight = 0;
17
+ for (const [item, weight] of items) {
18
+ currentWeight += weight;
19
+ if (random <= currentWeight) {
20
+ return item;
21
+ }
22
+ }
23
+
24
+ throw new Error('Unable to select an item based on weights');
25
+ }
26
+
27
+ export const NumberUtils = {
28
+ between,
29
+ randomWithPercentages,
3
30
  }
@@ -41,4 +41,10 @@ export function pluralize(countable: number | ArrayLike<any> | Map<any, any>, si
41
41
  if (count === 1) return singular;
42
42
  if (plural) return plural;
43
43
  return `${singular}s`;
44
- }
44
+ }
45
+
46
+ export const StringUtils = {
47
+ classNames,
48
+ randomId,
49
+ pluralize
50
+ };
@@ -1,9 +1,11 @@
1
1
  import * as Debounce from './debounce.util';
2
2
  import * as Functions from './functions.util';
3
3
  import * as Throttle from './throttle.util';
4
+ import * as StringUtils from './string.util';
4
5
 
5
6
  export const TimeUtils = {
6
7
  ...Functions,
7
8
  ...Debounce,
8
9
  ...Throttle,
10
+ ...StringUtils,
9
11
  };
@@ -0,0 +1,13 @@
1
+ export function ensureStartZero(num: number): string {
2
+ return num < 10 ? `0${num}` : num.toString();
3
+ }
4
+
5
+ export function get12HourFormat(hour: number): string {
6
+ if (hour === 0) return '12am';
7
+ if (hour > 12) return `${hour - 12}pm`;
8
+ return `${hour}am`;
9
+ }
10
+
11
+ export function get24HourFormat(hour: number): string {
12
+ return ensureStartZero(hour);
13
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './Classes';
2
2
  export * from './Extensions';
3
- export * from './Functions';
4
3
  export * from './Interfaces';
5
- export * from './Types';
4
+ export * from './Types';
5
+ export * from './Utils';
@@ -1,52 +0,0 @@
1
- export type UpdateFinder<T> = (item: T, index: number, self: Array<T>) => boolean;
2
- declare global {
3
- interface Array<T> {
4
- /**
5
- * Pushes items to array and returns self with new items
6
- * @param items Items to add to array
7
- */
8
- add(...items: Array<T>): this;
9
- /**
10
- * Update an item in array
11
- * @param old The old value or index to update
12
- * @param updated Updated value
13
- */
14
- update(old: T | number | UpdateFinder<T>, updated: T): T;
15
- /**
16
- * Removes item from array and returns self without item
17
- * @param item Item or index to remove
18
- */
19
- remove(item: T | number): this;
20
- /**
21
- * Returns a random element from array
22
- */
23
- random(): T;
24
- /**
25
- * Returns item matching index. If negative number, subtracts number from length
26
- * @param i Index of item
27
- */
28
- index(i: number): T;
29
- /**
30
- * For every x in array, execute callback
31
- * @param every i.e every 2nd item in array
32
- * @param callback Function to execute
33
- * @returns Array of results
34
- */
35
- nth<U>(every: number, callback: (item: T, index: number, collection: Array<T>, self: this) => U): Array<U>;
36
- }
37
- }
38
- declare function add<T>(this: Array<T>, ...items: Array<T>): T[];
39
- declare function update<T>(this: Array<T>, old: T | number | UpdateFinder<T>, updated: T): T;
40
- declare function remove<T>(this: Array<T>, value: T | number): Array<T>;
41
- declare function random<T>(this: Array<T>): T;
42
- declare function index<T>(this: Array<T>, i: number): T;
43
- declare function nth<T, U>(this: Array<T>, every: number, callback: (item: T, index: number, collection: Array<T>, self: Array<T>) => U): Array<U>;
44
- export declare const ArrayExtensions: {
45
- add: typeof add;
46
- update: typeof update;
47
- remove: typeof remove;
48
- random: typeof random;
49
- index: typeof index;
50
- nth: typeof nth;
51
- };
52
- export {};
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayExtensions = void 0;
4
- function add(...items) {
5
- this.push(...items);
6
- return this;
7
- }
8
- Array.prototype.add = add;
9
- function update(old, updated) {
10
- const item = typeof old === 'number' ? this[old]
11
- : typeof old === 'function' ? this.find(old)
12
- : old;
13
- if (!item)
14
- throw new Error('Old was not found in array!');
15
- const index = this.indexOf(item);
16
- return this[index] = updated;
17
- }
18
- Array.prototype.update = update;
19
- function remove(value) {
20
- const index = typeof value === 'number' ? value : this.indexOf(value);
21
- if (index > -1)
22
- this.splice(index, 1);
23
- return this;
24
- }
25
- Array.prototype.remove = remove;
26
- function random() {
27
- const randomIndex = Math.round(Math.random() * this.length);
28
- return this[randomIndex];
29
- }
30
- Array.prototype.random = random;
31
- function index(i) {
32
- return this[i < 0 ? this.length + i : i];
33
- }
34
- Array.prototype.index = index;
35
- function nth(every, callback) {
36
- const result = new Array();
37
- let collection = new Array();
38
- for (let i = 0; i < this.length; i++) {
39
- collection.push(this[i]);
40
- if (i % every === 0) {
41
- result.push(callback(this[i], i, collection, this));
42
- collection = new Array();
43
- }
44
- }
45
- return result;
46
- }
47
- Array.prototype.nth = nth;
48
- exports.ArrayExtensions = {
49
- add, update, remove,
50
- random, index, nth
51
- };
@@ -1,27 +0,0 @@
1
- import { IElement } from "../Types";
2
- declare global {
3
- interface Document {
4
- /**
5
- * Creates an element like Document#createElement, however with construction options to assign values in construction instead of after construction.
6
- * @param tagName HTMLElement tag name
7
- * @param options Construction options, instead of assigning values after construction
8
- * @param children Child elements
9
- */
10
- createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]>, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
11
- createProperElement<Tag extends keyof HTMLElementTagNameMap>(tagName: Tag, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
12
- createElementFromString<K extends keyof HTMLElementTagNameMap>(html: string, parentTag?: K): HTMLElementTagNameMap[K];
13
- }
14
- interface HTMLCollection {
15
- /**
16
- * Converts HTMLCollection to Element[]
17
- */
18
- array(): Element[];
19
- }
20
- }
21
- declare function createElement<Tag extends keyof HTMLElementTagNameMap>(this: Document, tagName: Tag, options?: Partial<HTMLElementTagNameMap[Tag]> | string, ...children: Array<IElement>): HTMLElementTagNameMap[Tag];
22
- declare function createElementFromString<Tag extends keyof HTMLElementTagNameMap>(this: Document, html: string, tag?: Tag): HTMLElementTagNameMap[Tag];
23
- export declare const DocumentExtensions: {
24
- createElement: typeof createElement;
25
- createElementFromString: typeof createElementFromString;
26
- };
27
- export {};
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DocumentExtensions = void 0;
4
- function createElement(tagName, options, ...children) {
5
- const element = Object.assign(document.createElement(tagName), typeof options === 'string' ? {} : options);
6
- children ??= typeof options === 'string' ? [options] : [];
7
- typeof options === 'string' && children.unshift(options);
8
- if (!children.length)
9
- return element;
10
- else if (typeof children === 'string')
11
- element.innerHTML = children;
12
- else if (children instanceof Array)
13
- children.forEach(child => (typeof child === 'string' ?
14
- element.innerHTML += child :
15
- element.appendChild(child)));
16
- else
17
- element.appendChild(children);
18
- return element;
19
- }
20
- Document.prototype.createProperElement = createElement;
21
- function createElementFromString(html, tag) {
22
- if (!html.startsWith(`<${tag}`))
23
- html = `<${tag}>${html}</${tag}>`;
24
- return new DOMParser().parseFromString(html, 'text/html').body.firstElementChild;
25
- }
26
- Document.prototype.createElementFromString = createElementFromString;
27
- HTMLCollection.prototype.array = function () {
28
- return Array.from(this);
29
- };
30
- exports.DocumentExtensions = {
31
- createElement, createElementFromString
32
- };
@@ -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;