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.
- package/README.md +1 -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/Array/random.extension.d.ts +1 -2
- package/dist/Extensions/Array/random.extension.js +1 -22
- package/dist/Extensions/Array/string.extension.d.ts +3 -4
- package/dist/Extensions/Number.d.ts +2 -2
- package/dist/Extensions/Number.js +1 -1
- package/dist/Extensions/Object/arrays.extension.d.ts +14 -0
- package/dist/Extensions/Object/arrays.extension.js +7 -2
- package/dist/Extensions/Object/extracts.extension.d.ts +6 -6
- package/dist/Extensions/Object/extracts.extension.js +10 -7
- 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 +2 -4
- package/dist/Extensions/String/index.js +4 -16
- package/dist/Extensions/String/string.extension.d.ts +6 -0
- package/dist/Extensions/String/string.extension.js +10 -0
- package/dist/Extensions/index.d.ts +2 -2
- package/dist/Extensions/index.js +2 -2
- package/dist/Types/Able.d.ts +1 -1
- package/dist/Utils/NumberUtils.d.ts +5 -0
- package/dist/Utils/NumberUtils.js +25 -1
- package/dist/Utils/StringUtils.d.ts +5 -0
- package/dist/Utils/StringUtils.js +6 -1
- package/dist/Utils/TimeUtils/index.d.ts +3 -0
- package/dist/Utils/TimeUtils/index.js +2 -0
- package/dist/Utils/TimeUtils/string.util.d.ts +3 -0
- package/dist/Utils/TimeUtils/string.util.js +19 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/docs/Classes.md +78 -3
- package/docs/Extensions.md +247 -73
- package/docs/Types.md +202 -58
- package/docs/Utils.md +335 -0
- package/docs/index.md +1 -1
- package/package.json +1 -1
- package/src/Extensions/Array/index.ts +6 -15
- package/src/Extensions/Array/random.extension.ts +2 -25
- package/src/Extensions/Array/string.extension.ts +3 -4
- package/src/Extensions/Number.ts +3 -3
- package/src/Extensions/Object/arrays.extension.ts +23 -2
- package/src/Extensions/Object/extracts.extension.ts +18 -13
- package/src/Extensions/Object/index.ts +4 -11
- package/src/Extensions/Object/properties.extension.ts +50 -2
- package/src/Extensions/String/index.ts +2 -5
- package/src/Extensions/String/string.extension.ts +11 -0
- package/src/Extensions/index.ts +2 -2
- package/src/Types/Able.ts +1 -1
- package/src/Utils/NumberUtils.ts +27 -0
- package/src/Utils/StringUtils.ts +7 -1
- package/src/Utils/TimeUtils/index.ts +2 -0
- package/src/Utils/TimeUtils/string.util.ts +13 -0
- package/src/index.ts +2 -2
- 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/Extensions/Object/properties.ts +0 -50
- 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
package/README.md
CHANGED
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
random<T_4>(this: T_4[]): T_4;
|
|
8
|
-
shuffle<T_5>(this: T_5[]): T_5[];
|
|
9
|
-
randomWithPercentages<T_6>(items: [item: T_6, weight: number][]): T_6;
|
|
10
|
-
nth<T_7, U>(this: T_7[], every: number, callback: (item: T_7, index: number, collection: T_7[], self: T_7[]) => U): U[];
|
|
11
|
-
add<T_8>(this: T_8[], ...items: T_8[]): T_8[];
|
|
12
|
-
update<T_9>(this: T_9[], old: number | T_9 | CRUD.UpdateFinder<T_9>, updated: T_9): T_9;
|
|
13
|
-
remove<T_10>(this: T_10[], value: number | T_10): T_10[];
|
|
14
|
-
take<T_11>(this: T_11[], count: number): T_11[];
|
|
15
|
-
forceArray<T_12>(arrayable: import("../..").Arrayable<T_12>): T_12[];
|
|
16
|
-
unique<T_13>(this: T_13[]): T_13[];
|
|
17
|
-
splitBy<T_14>(this: T_14[], chunkSize: number): T_14[][];
|
|
18
|
-
splitBy<T_15>(this: T_15[], splitter: (value: T_15, index: number, array: T_15[]) => boolean): T_15[][];
|
|
19
|
-
groupBy<T_16, K>(this: T_16[], keySelector: (value: T_16, index: number, array: T_16[]) => K): Map<K, T_16[]>;
|
|
20
|
-
};
|
|
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';
|
|
@@ -10,31 +10,13 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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);
|
|
24
15
|
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const String = __importStar(require("./string.extension"));
|
|
33
|
-
exports.ArrayExtensions = {
|
|
34
|
-
...Array,
|
|
35
|
-
...CRUD,
|
|
36
|
-
...Loop,
|
|
37
|
-
...Random,
|
|
38
|
-
...Sort,
|
|
39
|
-
...String,
|
|
40
|
-
};
|
|
17
|
+
__exportStar(require("./array.extension"), exports);
|
|
18
|
+
__exportStar(require("./crud.extension"), exports);
|
|
19
|
+
__exportStar(require("./loop.extension"), exports);
|
|
20
|
+
__exportStar(require("./random.extension"), exports);
|
|
21
|
+
__exportStar(require("./sort.extension"), exports);
|
|
22
|
+
__exportStar(require("./string.extension"), exports);
|
|
@@ -15,9 +15,8 @@ declare global {
|
|
|
15
15
|
* @param items An array of tuples where each tuple contains an item and its corresponding weight.
|
|
16
16
|
* @returns A randomly selected item based on the provided weights.
|
|
17
17
|
*/
|
|
18
|
-
randomWithPercentages(items: [item: T, weight: number]
|
|
18
|
+
randomWithPercentages(items: Array<[item: T, weight: number]>): T;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export declare function random<T>(this: Array<T>): T;
|
|
22
22
|
export declare function shuffle<T>(this: Array<T>): Array<T>;
|
|
23
|
-
export declare function randomWithPercentages<T>(items: [item: T, weight: number][]): T;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.shuffle = exports.random = void 0;
|
|
4
4
|
function random() {
|
|
5
5
|
const randomIndex = Math.floor(Math.random() * this.length);
|
|
6
6
|
return this[randomIndex];
|
|
@@ -12,24 +12,3 @@ function shuffle() {
|
|
|
12
12
|
}
|
|
13
13
|
exports.shuffle = shuffle;
|
|
14
14
|
Array.prototype.shuffle = shuffle;
|
|
15
|
-
function randomWithPercentages(items) {
|
|
16
|
-
if (items.length === 0)
|
|
17
|
-
throw new Error('Items array cannot be empty');
|
|
18
|
-
// Calculate total weight in case weights don't sum to 100
|
|
19
|
-
const totalWeight = items.reduce((sum, [, weight]) => sum + weight, 0);
|
|
20
|
-
if (totalWeight === 0)
|
|
21
|
-
throw new Error('Total weight must be greater than zero');
|
|
22
|
-
// Generate random number between 0 and totalWeight
|
|
23
|
-
const random = Math.random() * totalWeight;
|
|
24
|
-
// Find the item that corresponds to this random value
|
|
25
|
-
let currentWeight = 0;
|
|
26
|
-
for (const [item, weight] of items) {
|
|
27
|
-
currentWeight += weight;
|
|
28
|
-
if (random <= currentWeight) {
|
|
29
|
-
return item;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
throw new Error('Unable to select an item based on weights');
|
|
33
|
-
}
|
|
34
|
-
exports.randomWithPercentages = randomWithPercentages;
|
|
35
|
-
Array.prototype.randomWithPercentages = randomWithPercentages;
|
|
@@ -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
|
|
6
|
-
* @param
|
|
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(
|
|
9
|
+
join(separator?: string, endSeparator?: string): string;
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
export declare function join<T>(this: Array<T>, separator?: string, endSeparator?: string): string;
|
|
@@ -4,10 +4,10 @@ type Separators = {
|
|
|
4
4
|
};
|
|
5
5
|
declare global {
|
|
6
6
|
interface Number {
|
|
7
|
-
toSeparationString(separators
|
|
7
|
+
toSeparationString(separators?: Partial<Separators>): string;
|
|
8
8
|
toRomanNumeral(): string;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
export declare function toSeparationString(this: number, separators
|
|
11
|
+
export declare function toSeparationString(this: number, separators?: Partial<Separators>): string;
|
|
12
12
|
export declare function toRomanNumeral(this: number): string;
|
|
13
13
|
export {};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toRomanNumeral = exports.toSeparationString = void 0;
|
|
4
4
|
function toSeparationString(separators) {
|
|
5
|
-
const { thousand = '.', decimal = '.' } = separators;
|
|
5
|
+
const { thousand = '.', decimal = '.' } = separators || {};
|
|
6
6
|
const [integerPart, decimalPart] = this.toString().split('.');
|
|
7
7
|
const formattedInteger = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousand);
|
|
8
8
|
return decimalPart ? `${formattedInteger}${decimal}${decimalPart}` : formattedInteger;
|
|
@@ -6,6 +6,18 @@ declare global {
|
|
|
6
6
|
* @param from Object to destruct
|
|
7
7
|
*/
|
|
8
8
|
array<From extends {} = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
|
|
9
|
+
/**
|
|
10
|
+
* Destructures object into array of property keys or values depending on selector
|
|
11
|
+
* @param from Object to destruct
|
|
12
|
+
* @param selector Selects whether to return keys or values
|
|
13
|
+
*/
|
|
14
|
+
array<From extends {} = {}>(from: From, selector: 'keys'): Array<keyof From>;
|
|
15
|
+
/**
|
|
16
|
+
* Destructures object into array of property keys or values depending on selector
|
|
17
|
+
* @param from Object to destruct
|
|
18
|
+
* @param selector Selects whether to return keys or values
|
|
19
|
+
*/
|
|
20
|
+
array<From extends {} = {}>(from: From, selector: 'values'): Array<ValueOf<From>>;
|
|
9
21
|
/**
|
|
10
22
|
* Destructures object into array of property keys
|
|
11
23
|
* @param from Object to destruct
|
|
@@ -14,4 +26,6 @@ declare global {
|
|
|
14
26
|
}
|
|
15
27
|
}
|
|
16
28
|
export declare function array<From extends {} = {}>(this: object, from: From): Array<[keyof From, ValueOf<From>]>;
|
|
29
|
+
export declare function array<From extends {} = {}>(this: object, from: From, selector: 'keys'): Array<keyof From>;
|
|
30
|
+
export declare function array<From extends {} = {}>(this: object, from: From, selector: 'values'): Array<ValueOf<From>>;
|
|
17
31
|
export declare function keysOf<From extends {} = {}>(this: object, from: From): Array<keyof From>;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.keysOf = exports.array = void 0;
|
|
4
|
-
function array(from) {
|
|
5
|
-
|
|
4
|
+
function array(from, selector) {
|
|
5
|
+
const entries = Object.entries(from);
|
|
6
|
+
switch (selector) {
|
|
7
|
+
case 'keys': return entries.map(([key]) => key);
|
|
8
|
+
case 'values': return entries.map(([, value]) => value);
|
|
9
|
+
default: return entries;
|
|
10
|
+
}
|
|
6
11
|
}
|
|
7
12
|
exports.array = array;
|
|
8
13
|
Object.array = array;
|
|
@@ -13,24 +13,24 @@ declare global {
|
|
|
13
13
|
*/
|
|
14
14
|
pick<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Returns the difference between two objects (properties where values differ)
|
|
17
17
|
* @param source Source object
|
|
18
18
|
* @param target Target object
|
|
19
|
-
* @param exclude Properties to exclude from
|
|
20
|
-
* @returns Object with properties
|
|
19
|
+
* @param exclude Properties to exclude from comparison
|
|
20
|
+
* @returns Object with properties where values differ between source and target, excluding specified properties
|
|
21
21
|
*/
|
|
22
|
-
difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>):
|
|
22
|
+
difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Partial<T>;
|
|
23
23
|
/**
|
|
24
24
|
* Deeply combines objects, with later objects in parameters taking precedence over earlier ones. Does not combine arrays.
|
|
25
25
|
* @param objects Objects to combine
|
|
26
26
|
* @returns Combined object
|
|
27
27
|
*/
|
|
28
|
-
combine<T extends Record<string, any | undefined>>(...objects: Array<
|
|
28
|
+
combine<T extends Record<string, any | undefined>>(...objects: Array<Combinable<T> | undefined>): T;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
export declare function omit<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Omit<From, Props>;
|
|
32
32
|
export declare function pick<From extends {}, Props extends keyof From>(from: From, ...props: Array<Props | Partial<From>>): Pick<From, Props>;
|
|
33
|
-
export declare function difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>):
|
|
33
|
+
export declare function difference<T extends object>(source: T, target: T, ...exclude: Array<keyof T>): Partial<T>;
|
|
34
34
|
type Combinable<T extends Record<string, any>> = {
|
|
35
35
|
[key in keyof T]?: T[key] extends Record<string, any> ? Combinable<T[key]> : T[key];
|
|
36
36
|
};
|
|
@@ -30,13 +30,16 @@ function pick(from, ...props) {
|
|
|
30
30
|
exports.pick = pick;
|
|
31
31
|
Object.pick = pick;
|
|
32
32
|
function difference(source, target, ...exclude) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
return [...
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
const excludeSet = new Set(exclude);
|
|
34
|
+
const allKeys = new Set([...Object.keysOf(source), ...Object.keysOf(target)]);
|
|
35
|
+
return [...allKeys].reduce((acc, key) => {
|
|
36
|
+
if (excludeSet.has(key))
|
|
37
|
+
return acc;
|
|
38
|
+
const sourceValue = source[key];
|
|
39
|
+
const targetValue = target[key];
|
|
40
|
+
if (JSON.stringify(sourceValue) !== JSON.stringify(targetValue)) {
|
|
41
|
+
acc[key] = targetValue;
|
|
42
|
+
}
|
|
40
43
|
return acc;
|
|
41
44
|
}, {});
|
|
42
45
|
}
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
combine<T_1 extends Record<string, any>>(...objects: ({ [key in keyof T_1]?: (T_1[key] extends Record<string, any> ? T_1[key] extends infer T_2 extends Record<string, any> ? { [key_1 in keyof T_2]?: (T_1[key][key_1] extends Record<string, any> ? T_1[key][key_1] extends infer T_3 extends Record<string, any> ? { [key_2 in keyof T_3]?: (T_1[key][key_1][key_2] extends Record<string, any> ? T_1[key][key_1][key_2] extends infer T_4 extends Record<string, any> ? { [key_3 in keyof T_4]?: (T_1[key][key_1][key_2][key_3] extends Record<string, any> ? T_1[key][key_1][key_2][key_3] extends infer T_5 extends Record<string, any> ? { [key_4 in keyof T_5]?: (T_1[key][key_1][key_2][key_3][key_4] extends Record<string, any> ? T_1[key][key_1][key_2][key_3][key_4] extends infer T_6 extends Record<string, any> ? { [key_5 in keyof T_6]?: (T_1[key][key_1][key_2][key_3][key_4][key_5] extends Record<string, any> ? T_1[key][key_1][key_2][key_3][key_4][key_5] extends infer T_7 extends Record<string, any> ? { [key_6 in keyof T_7]?: (T_1[key][key_1][key_2][key_3][key_4][key_5][key_6] extends Record<string, any> ? T_1[key][key_1][key_2][key_3][key_4][key_5][key_6] extends infer T_8 extends Record<string, any> ? { [key_7 in keyof T_8]?: (T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7] extends Record<string, any> ? T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7] extends infer T_9 extends Record<string, any> ? { [key_8 in keyof T_9]?: (T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8] extends Record<string, any> ? T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8] extends infer T_10 extends Record<string, any> ? { [key_9 in keyof T_10]?: (T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8][key_9] extends Record<string, any> ? T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8][key_9] extends infer T_11 extends Record<string, any> ? { [key_10 in keyof T_11]?: (T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8][key_9][key_10] extends Record<string, any> ? any : T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8][key_9][key_10]) | undefined; } : never : T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8][key_9]) | undefined; } : never : T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7][key_8]) | undefined; } : never : T_1[key][key_1][key_2][key_3][key_4][key_5][key_6][key_7]) | undefined; } : never : T_1[key][key_1][key_2][key_3][key_4][key_5][key_6]) | undefined; } : never : T_1[key][key_1][key_2][key_3][key_4][key_5]) | undefined; } : never : T_1[key][key_1][key_2][key_3][key_4]) | undefined; } : never : T_1[key][key_1][key_2][key_3]) | undefined; } : never : T_1[key][key_1][key_2]) | undefined; } : never : T_1[key][key_1]) | undefined; } : never : T_1[key]) | undefined; } | undefined)[]): T_1;
|
|
6
|
-
areEqual<T_12 extends object | null>(a?: T_12 | undefined, b?: T_12 | undefined): boolean;
|
|
7
|
-
isNullOrUndefined(obj: any): obj is null | undefined;
|
|
8
|
-
array<From_2 extends {} = {}>(this: object, from: From_2): [keyof From_2, import("../..").ValueOf<From_2>][];
|
|
9
|
-
keysOf<From_3 extends {} = {}>(this: object, from: From_3): (keyof From_3)[];
|
|
10
|
-
};
|
|
1
|
+
export * from './arrays.extension';
|
|
2
|
+
export * from './booleans.extension';
|
|
3
|
+
export * from './extracts.extension';
|
|
4
|
+
export * from './properties.extension';
|
|
@@ -10,27 +10,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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);
|
|
24
15
|
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const Properties = __importStar(require("./properties.extension"));
|
|
31
|
-
exports.ObjectExtensions = {
|
|
32
|
-
...Array,
|
|
33
|
-
...Booleans,
|
|
34
|
-
...Extracts,
|
|
35
|
-
...Properties
|
|
36
|
-
};
|
|
17
|
+
__exportStar(require("./arrays.extension"), exports);
|
|
18
|
+
__exportStar(require("./booleans.extension"), exports);
|
|
19
|
+
__exportStar(require("./extracts.extension"), exports);
|
|
20
|
+
__exportStar(require("./properties.extension"), exports);
|
|
@@ -1,6 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropertiesWith, If } from '../../Types';
|
|
2
|
+
type PrimitiveMap = {
|
|
3
|
+
string: string;
|
|
4
|
+
number: number;
|
|
5
|
+
boolean: boolean;
|
|
6
|
+
undefined: undefined;
|
|
7
|
+
null: null;
|
|
8
|
+
object: object;
|
|
9
|
+
function: Function;
|
|
10
|
+
any: any;
|
|
11
|
+
Date: Date;
|
|
12
|
+
RegExp: RegExp;
|
|
13
|
+
Promise: Promise<any>;
|
|
14
|
+
Array: Array<any>;
|
|
15
|
+
Map: Map<any, any>;
|
|
16
|
+
Set: Set<any>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Object with getPrimitiveTypes<Source, AllowFunctions extends boolean>(
|
|
20
|
+
* source: Source,
|
|
21
|
+
* allowFunctions: AllowFunctions = false
|
|
22
|
+
* ): Object with properties from source that matches primitive type
|
|
23
|
+
*/
|
|
24
|
+
export type Properties = {
|
|
25
|
+
[Key in keyof PrimitiveMap as `get${Capitalize<Key>}s`]: <Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions) => If<AllowFunctions, PropertiesWith<PrimitiveMap[Key] | ((...args: any[]) => PrimitiveMap[Key]), Source>, PropertiesWith<PrimitiveMap[Key], Source>>;
|
|
26
|
+
};
|
|
2
27
|
declare global {
|
|
3
28
|
interface ObjectConstructor {
|
|
4
29
|
properties: Properties;
|
|
5
30
|
}
|
|
6
31
|
}
|
|
32
|
+
export declare const properties: Properties;
|
|
33
|
+
export {};
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.properties = void 0;
|
|
4
|
+
const case_extension_1 = require("../String/case.extension");
|
|
5
|
+
exports.properties = [
|
|
6
|
+
'string', 'number', 'boolean', 'undefined', 'null',
|
|
7
|
+
'object', 'function', 'any',
|
|
8
|
+
'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
|
|
9
|
+
].reduce((result, primitive) => {
|
|
10
|
+
result[`get${(0, case_extension_1.convertCase)('camel', 'pascal')}s`] = function (source, withFunctions = false) {
|
|
11
|
+
return Object.keysOf(source).reduce((result, key) => {
|
|
12
|
+
if (source[key].constructor.name === primitive ||
|
|
13
|
+
(withFunctions && typeof source[key] === 'function' && source[key]).constructor.name === primitive) {
|
|
14
|
+
result[key] = source[key];
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}, {});
|
|
18
|
+
};
|
|
19
|
+
return result;
|
|
20
|
+
}, {});
|
|
21
|
+
Object.properties = exports.properties;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.properties = void 0;
|
|
4
|
+
const case_extension_1 = require("../String/case.extension");
|
|
4
5
|
exports.properties = [
|
|
5
6
|
'string', 'number', 'boolean', 'undefined', 'null',
|
|
6
7
|
'object', 'function', 'any',
|
|
7
8
|
'Date', 'RegExp', 'Promise', 'Array', 'Map', 'Set'
|
|
8
9
|
].reduce((result, primitive) => {
|
|
9
|
-
result[`get${
|
|
10
|
+
result[`get${(0, case_extension_1.convertCase)('camel', 'pascal')}s`] = function (source, withFunctions = false) {
|
|
10
11
|
return Object.keysOf(source).reduce((result, key) => {
|
|
11
12
|
if (source[key].constructor.name === primitive ||
|
|
12
13
|
(withFunctions && typeof source[key] === 'function' && source[key]).constructor.name === primitive) {
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
convertCase: <TValue extends string, To extends Case.Case[], Return extends To extends [...Case.Case[], infer To_1] ? To_1 : Case.Case>(value: TValue, from: Case.Case, ...to: To) => Return extends "upper" ? Uppercase<TValue> : Return extends "lower" ? Lowercase<TValue> : Return extends "pascal" ? Capitalize<TValue> : Return extends "camel" ? Uncapitalize<TValue> : string;
|
|
4
|
-
};
|
|
1
|
+
export * from './case.extension';
|
|
2
|
+
export * from './string.extension';
|
|
@@ -10,21 +10,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
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);
|
|
24
15
|
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
exports.StringUtils = {
|
|
29
|
-
...Case,
|
|
30
|
-
};
|
|
17
|
+
__exportStar(require("./case.extension"), exports);
|
|
18
|
+
__exportStar(require("./string.extension"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.truncate = void 0;
|
|
4
|
+
function truncate(length, ellipsis = "...") {
|
|
5
|
+
if (this.length <= length)
|
|
6
|
+
return this;
|
|
7
|
+
return this.slice(0, length - ellipsis.length) + ellipsis;
|
|
8
|
+
}
|
|
9
|
+
exports.truncate = truncate;
|
|
10
|
+
String.prototype.truncate = truncate;
|
package/dist/Extensions/index.js
CHANGED
|
@@ -15,8 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Array"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./Function"), exports);
|
|
19
19
|
__exportStar(require("./Map"), exports);
|
|
20
|
-
__exportStar(require("./Object"), exports);
|
|
21
20
|
__exportStar(require("./Number"), exports);
|
|
21
|
+
__exportStar(require("./Object"), exports);
|
|
22
22
|
__exportStar(require("./String"), exports);
|
package/dist/Types/Able.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
1
|
export declare function between(min: number, max: number): number;
|
|
2
|
+
export declare function randomWithPercentages<T>(items: [item: T, weight: number][]): T;
|
|
3
|
+
export declare const NumberUtils: {
|
|
4
|
+
between: typeof between;
|
|
5
|
+
randomWithPercentages: typeof randomWithPercentages;
|
|
6
|
+
};
|
|
@@ -1,7 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.between = void 0;
|
|
3
|
+
exports.NumberUtils = exports.randomWithPercentages = exports.between = void 0;
|
|
4
4
|
function between(min, max) {
|
|
5
5
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
6
6
|
}
|
|
7
7
|
exports.between = between;
|
|
8
|
+
function randomWithPercentages(items) {
|
|
9
|
+
if (items.length === 0)
|
|
10
|
+
throw new Error('Items array cannot be empty');
|
|
11
|
+
// Calculate total weight in case weights don't sum to 100
|
|
12
|
+
const totalWeight = items.reduce((sum, [, weight]) => sum + weight, 0);
|
|
13
|
+
if (totalWeight === 0)
|
|
14
|
+
throw new Error('Total weight must be greater than zero');
|
|
15
|
+
// Generate random number between 0 and totalWeight
|
|
16
|
+
const random = Math.random() * totalWeight;
|
|
17
|
+
// Find the item that corresponds to this random value
|
|
18
|
+
let currentWeight = 0;
|
|
19
|
+
for (const [item, weight] of items) {
|
|
20
|
+
currentWeight += weight;
|
|
21
|
+
if (random <= currentWeight) {
|
|
22
|
+
return item;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
throw new Error('Unable to select an item based on weights');
|
|
26
|
+
}
|
|
27
|
+
exports.randomWithPercentages = randomWithPercentages;
|
|
28
|
+
exports.NumberUtils = {
|
|
29
|
+
between,
|
|
30
|
+
randomWithPercentages,
|
|
31
|
+
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export declare function classNames(...args: Array<any>): string;
|
|
2
2
|
export declare function randomId(length?: number): string;
|
|
3
3
|
export declare function pluralize(countable: number | ArrayLike<any> | Map<any, any>, singular: string, plural?: string): string;
|
|
4
|
+
export declare const StringUtils: {
|
|
5
|
+
classNames: typeof classNames;
|
|
6
|
+
randomId: typeof randomId;
|
|
7
|
+
pluralize: typeof pluralize;
|
|
8
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pluralize = exports.randomId = exports.classNames = void 0;
|
|
3
|
+
exports.StringUtils = exports.pluralize = exports.randomId = exports.classNames = void 0;
|
|
4
4
|
function classNames(...args) {
|
|
5
5
|
return args.reduce((acc, arg) => {
|
|
6
6
|
if (!arg)
|
|
@@ -45,3 +45,8 @@ function pluralize(countable, singular, plural) {
|
|
|
45
45
|
return `${singular}s`;
|
|
46
46
|
}
|
|
47
47
|
exports.pluralize = pluralize;
|
|
48
|
+
exports.StringUtils = {
|
|
49
|
+
classNames,
|
|
50
|
+
randomId,
|
|
51
|
+
pluralize
|
|
52
|
+
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const TimeUtils: {
|
|
2
|
+
ensureStartZero(num: number): string;
|
|
3
|
+
get12HourFormat(hour: number): string;
|
|
4
|
+
get24HourFormat(hour: number): string;
|
|
2
5
|
throttle<T>(throttleId: string, callback: () => T, cooldown: number): T;
|
|
3
6
|
wrapInThrottle<T_1>(callback: (...args: T_1[]) => void, cooldown: number): (...args: T_1[]) => void;
|
|
4
7
|
isThrottleOnCooldown(throttleId: string): boolean;
|
|
@@ -27,8 +27,10 @@ exports.TimeUtils = void 0;
|
|
|
27
27
|
const Debounce = __importStar(require("./debounce.util"));
|
|
28
28
|
const Functions = __importStar(require("./functions.util"));
|
|
29
29
|
const Throttle = __importStar(require("./throttle.util"));
|
|
30
|
+
const StringUtils = __importStar(require("./string.util"));
|
|
30
31
|
exports.TimeUtils = {
|
|
31
32
|
...Functions,
|
|
32
33
|
...Debounce,
|
|
33
34
|
...Throttle,
|
|
35
|
+
...StringUtils,
|
|
34
36
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get24HourFormat = exports.get12HourFormat = exports.ensureStartZero = void 0;
|
|
4
|
+
function ensureStartZero(num) {
|
|
5
|
+
return num < 10 ? `0${num}` : num.toString();
|
|
6
|
+
}
|
|
7
|
+
exports.ensureStartZero = ensureStartZero;
|
|
8
|
+
function get12HourFormat(hour) {
|
|
9
|
+
if (hour === 0)
|
|
10
|
+
return '12am';
|
|
11
|
+
if (hour > 12)
|
|
12
|
+
return `${hour - 12}pm`;
|
|
13
|
+
return `${hour}am`;
|
|
14
|
+
}
|
|
15
|
+
exports.get12HourFormat = get12HourFormat;
|
|
16
|
+
function get24HourFormat(hour) {
|
|
17
|
+
return ensureStartZero(hour);
|
|
18
|
+
}
|
|
19
|
+
exports.get24HourFormat = get24HourFormat;
|