@pol-studios/utils 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/index.d.ts +1 -0
- package/dist/array/index.js +136 -0
- package/dist/async/index.d.ts +1 -0
- package/dist/async/index.js +67 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cache/index.js +42 -0
- package/dist/color/index.d.ts +1 -0
- package/dist/color/index.js +16 -0
- package/dist/date/index.d.ts +2 -0
- package/dist/date/index.js +102 -0
- package/dist/dev/index.d.ts +1 -0
- package/dist/dev/index.js +21 -0
- package/dist/device/index.d.ts +1 -0
- package/dist/device/index.js +31 -0
- package/dist/enum/index.d.ts +1 -0
- package/dist/enum/index.js +19 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +198 -0
- package/dist/format/index.d.ts +1 -0
- package/dist/format/index.js +36 -0
- package/dist/index-B2oAfh_i.d.ts +63 -0
- package/dist/index-BDWEMkWa.d.ts +56 -0
- package/dist/index-BSNY-QEc.d.ts +15 -0
- package/dist/index-BaA8cg0E.d.ts +100 -0
- package/dist/index-Btn_GVfm.d.ts +13 -0
- package/dist/index-BxUoIlv_.d.ts +39 -0
- package/dist/index-ByjfWGR4.d.ts +151 -0
- package/dist/index-C-YwC08Y.d.ts +45 -0
- package/dist/index-C062CkPL.d.ts +31 -0
- package/dist/index-C8CxeaqZ.d.ts +24 -0
- package/dist/index-CZbs1QQN.d.ts +102 -0
- package/dist/index-Cp7KyTeB.d.ts +23 -0
- package/dist/index-CrplC0qf.d.ts +29 -0
- package/dist/index-Cvl_0aDq.d.ts +14 -0
- package/dist/index-D_IvPWYI.d.ts +77 -0
- package/dist/index-DdaZnk7j.d.ts +28 -0
- package/dist/index-vLuR45Km.d.ts +27 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +1279 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +115 -0
- package/dist/state/index.d.ts +1 -0
- package/dist/state/index.js +17 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +55 -0
- package/dist/tailwind/index.d.ts +2 -0
- package/dist/tailwind/index.js +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +37 -0
- package/dist/uuid/index.d.ts +1 -0
- package/dist/uuid/index.js +10 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +123 -0
- package/package.json +50 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/internal/isUsable.ts
|
|
2
|
+
function isUsable(value) {
|
|
3
|
+
return value !== void 0 && value !== null && (typeof value !== "number" || isNaN(value) === false);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/format/currency.ts
|
|
7
|
+
function formatCurrency(value) {
|
|
8
|
+
if (isUsable(value) === false) return "";
|
|
9
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
10
|
+
style: "currency",
|
|
11
|
+
currency: "USD"
|
|
12
|
+
});
|
|
13
|
+
return formatter.format(value);
|
|
14
|
+
}
|
|
15
|
+
var toUsdString = formatCurrency;
|
|
16
|
+
function toNumberString(value) {
|
|
17
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
18
|
+
maximumFractionDigits: 2
|
|
19
|
+
});
|
|
20
|
+
return formatter.format(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/format/decimal.ts
|
|
24
|
+
function toDecimalString(num, decimalPlaces) {
|
|
25
|
+
if (isUsable(num) === false) return "";
|
|
26
|
+
return num.toLocaleString("en-US", {
|
|
27
|
+
minimumFractionDigits: decimalPlaces,
|
|
28
|
+
maximumFractionDigits: decimalPlaces
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
formatCurrency,
|
|
33
|
+
toDecimalString,
|
|
34
|
+
toNumberString,
|
|
35
|
+
toUsdString
|
|
36
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
interface ErrorMapping {
|
|
2
|
+
code?: string;
|
|
3
|
+
pattern?: RegExp;
|
|
4
|
+
message: string;
|
|
5
|
+
action?: string;
|
|
6
|
+
}
|
|
7
|
+
interface UserFriendlyError {
|
|
8
|
+
message: string;
|
|
9
|
+
action?: string;
|
|
10
|
+
}
|
|
11
|
+
interface PostgrestError {
|
|
12
|
+
code: string;
|
|
13
|
+
message: string;
|
|
14
|
+
details?: string;
|
|
15
|
+
hint?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Maps a technical error to a user-friendly error message
|
|
19
|
+
*/
|
|
20
|
+
declare function getUserFriendlyError(error: Error | PostgrestError | any): UserFriendlyError;
|
|
21
|
+
/**
|
|
22
|
+
* Checks if an error is a Supabase PostgREST error
|
|
23
|
+
*/
|
|
24
|
+
declare function isPostgrestError(error: any): error is PostgrestError;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if an error is a network error
|
|
27
|
+
*/
|
|
28
|
+
declare function isNetworkError(error: any): boolean;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Maps form validation errors to user-friendly field-specific messages
|
|
32
|
+
*/
|
|
33
|
+
interface ValidationErrorMapping {
|
|
34
|
+
pattern?: RegExp;
|
|
35
|
+
message: string;
|
|
36
|
+
action?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Maps a validation error message to a user-friendly field-specific message
|
|
40
|
+
*/
|
|
41
|
+
declare function getFormFieldError(error: string | Error | null | undefined): {
|
|
42
|
+
message: string;
|
|
43
|
+
action?: string;
|
|
44
|
+
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts field name from error message for better context
|
|
47
|
+
*/
|
|
48
|
+
declare function extractFieldName(errorMessage: string): string | null;
|
|
49
|
+
|
|
50
|
+
type index_ErrorMapping = ErrorMapping;
|
|
51
|
+
type index_PostgrestError = PostgrestError;
|
|
52
|
+
type index_UserFriendlyError = UserFriendlyError;
|
|
53
|
+
type index_ValidationErrorMapping = ValidationErrorMapping;
|
|
54
|
+
declare const index_extractFieldName: typeof extractFieldName;
|
|
55
|
+
declare const index_getFormFieldError: typeof getFormFieldError;
|
|
56
|
+
declare const index_getUserFriendlyError: typeof getUserFriendlyError;
|
|
57
|
+
declare const index_isNetworkError: typeof isNetworkError;
|
|
58
|
+
declare const index_isPostgrestError: typeof isPostgrestError;
|
|
59
|
+
declare namespace index {
|
|
60
|
+
export { type index_ErrorMapping as ErrorMapping, type index_PostgrestError as PostgrestError, type index_UserFriendlyError as UserFriendlyError, type index_ValidationErrorMapping as ValidationErrorMapping, index_extractFieldName as extractFieldName, index_getFormFieldError as getFormFieldError, index_getUserFriendlyError as getUserFriendlyError, index_isNetworkError as isNetworkError, index_isPostgrestError as isPostgrestError };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { type ErrorMapping as E, type PostgrestError as P, type UserFriendlyError as U, type ValidationErrorMapping as V, isPostgrestError as a, isNetworkError as b, getFormFieldError as c, extractFieldName as e, getUserFriendlyError as g, index as i };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Moment } from 'moment';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the current date/time in UTC
|
|
5
|
+
*/
|
|
6
|
+
declare function getUtcDate(): Date;
|
|
7
|
+
/**
|
|
8
|
+
* Converts a Date to UTC
|
|
9
|
+
*/
|
|
10
|
+
declare function toUtcDate(date: Date | undefined | null): Date | null;
|
|
11
|
+
/**
|
|
12
|
+
* Returns the current moment in UTC
|
|
13
|
+
*/
|
|
14
|
+
declare function getUtcMoment(): Moment;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Compares two Moment dates for equality
|
|
18
|
+
*/
|
|
19
|
+
declare function areDatesEqual(date1: Moment, date2: Moment): boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* JSON reviver function that converts date strings to Moment objects
|
|
23
|
+
*/
|
|
24
|
+
declare function dateReviver(key: any, value: any): any;
|
|
25
|
+
/**
|
|
26
|
+
* JSON reviver function that converts date strings to Date objects
|
|
27
|
+
*/
|
|
28
|
+
declare function parseWithDate(key: any, value: any): any;
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a Date object is valid
|
|
31
|
+
*/
|
|
32
|
+
declare function isValidDate(date: Date): boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Adds the duration between two dates to the first date
|
|
36
|
+
*/
|
|
37
|
+
declare function addDates(date1: Moment, date2: Moment): Moment;
|
|
38
|
+
/**
|
|
39
|
+
* Adds a number of days to a Moment date
|
|
40
|
+
*/
|
|
41
|
+
declare function addDays(date1: Moment, days: number): Moment;
|
|
42
|
+
|
|
43
|
+
declare const index_addDates: typeof addDates;
|
|
44
|
+
declare const index_addDays: typeof addDays;
|
|
45
|
+
declare const index_areDatesEqual: typeof areDatesEqual;
|
|
46
|
+
declare const index_dateReviver: typeof dateReviver;
|
|
47
|
+
declare const index_getUtcDate: typeof getUtcDate;
|
|
48
|
+
declare const index_getUtcMoment: typeof getUtcMoment;
|
|
49
|
+
declare const index_isValidDate: typeof isValidDate;
|
|
50
|
+
declare const index_parseWithDate: typeof parseWithDate;
|
|
51
|
+
declare const index_toUtcDate: typeof toUtcDate;
|
|
52
|
+
declare namespace index {
|
|
53
|
+
export { index_addDates as addDates, index_addDays as addDays, index_areDatesEqual as areDatesEqual, index_dateReviver as dateReviver, index_getUtcDate as getUtcDate, index_getUtcMoment as getUtcMoment, index_isValidDate as isValidDate, index_parseWithDate as parseWithDate, index_toUtcDate as toUtcDate };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { getUtcMoment as a, areDatesEqual as b, isValidDate as c, dateReviver as d, addDates as e, addDays as f, getUtcDate as g, index as i, parseWithDate as p, toUtcDate as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ClassValue } from 'clsx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merges Tailwind CSS classes with conflict resolution
|
|
5
|
+
* Combines clsx for conditional classes with tailwind-merge for deduplication
|
|
6
|
+
*/
|
|
7
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
8
|
+
|
|
9
|
+
declare const index_ClassValue: typeof ClassValue;
|
|
10
|
+
declare const index_cn: typeof cn;
|
|
11
|
+
declare namespace index {
|
|
12
|
+
export { index_ClassValue as ClassValue, index_cn as cn };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { cn as c, index as i };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
declare function isUsable(value: any): value is {};
|
|
2
|
+
|
|
3
|
+
type ItemType<T> = T extends Array<infer U> ? U : T;
|
|
4
|
+
type KeyOfStringOrNumber<T> = {
|
|
5
|
+
[K in keyof T]: K extends symbol ? never : K;
|
|
6
|
+
}[keyof T];
|
|
7
|
+
|
|
8
|
+
type EntityType = 'Project' | 'Client' | 'ProjectDatabase';
|
|
9
|
+
type EntityPermissionLevel = 'ReadOnly' | 'AdminReadOnly' | 'ReadWrite' | 'Admin';
|
|
10
|
+
type PermissionEffect = 'allow' | 'deny';
|
|
11
|
+
type EntityAction = 'view' | 'adminView' | 'edit' | 'create' | 'delete' | 'share';
|
|
12
|
+
interface EntityPermissionCheck {
|
|
13
|
+
canView: boolean;
|
|
14
|
+
canAdminView: boolean;
|
|
15
|
+
canEdit: boolean;
|
|
16
|
+
canCreate: boolean;
|
|
17
|
+
canDelete: boolean;
|
|
18
|
+
canShare: boolean;
|
|
19
|
+
permissionLevel: EntityPermissionLevel | null;
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
/** Whether access was explicitly denied */
|
|
22
|
+
isDenied?: boolean;
|
|
23
|
+
}
|
|
24
|
+
interface EntityAccessRecord {
|
|
25
|
+
id: number;
|
|
26
|
+
userId: string;
|
|
27
|
+
entityType: EntityType;
|
|
28
|
+
entityId: number;
|
|
29
|
+
permission: EntityPermissionLevel;
|
|
30
|
+
/** Permission effect - 'allow' grants access, 'deny' explicitly blocks */
|
|
31
|
+
effect: PermissionEffect;
|
|
32
|
+
inheritedFromClientId?: number | null;
|
|
33
|
+
inheritFromProject?: boolean;
|
|
34
|
+
/** User ID who granted this permission */
|
|
35
|
+
grantedBy?: string | null;
|
|
36
|
+
/** ISO timestamp when permission was granted */
|
|
37
|
+
grantedAt?: string;
|
|
38
|
+
/** ISO timestamp when permission expires, null for never */
|
|
39
|
+
expiresAt?: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Metadata stored in storage.objects.metadata JSONB column
|
|
44
|
+
* Used to track custom attachment properties after consolidation
|
|
45
|
+
*/
|
|
46
|
+
interface StorageObjectMetadata {
|
|
47
|
+
/** Processing status for async operations (e.g., embedding generation) */
|
|
48
|
+
processingStatus: "None" | "Processing" | "Error";
|
|
49
|
+
/** Uppercase content type derived from MIME (e.g., "JPEG", "PDF", "MP4") */
|
|
50
|
+
contentType: string;
|
|
51
|
+
/** Image/video height in pixels */
|
|
52
|
+
contentHeight?: number;
|
|
53
|
+
/** Image/video width in pixels */
|
|
54
|
+
contentWidth?: number;
|
|
55
|
+
/** Original filename before UUID renaming */
|
|
56
|
+
originalFileName?: string;
|
|
57
|
+
/** Legacy attachment ID for rollback/migration tracking */
|
|
58
|
+
legacyAttachmentId?: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get content type from metadata or infer from file path extension
|
|
62
|
+
*/
|
|
63
|
+
declare function getContentType(metadata: StorageObjectMetadata | null | undefined, path: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Check if content type represents an image
|
|
66
|
+
*/
|
|
67
|
+
declare function isImageType(contentType: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Check if content type represents a video
|
|
70
|
+
*/
|
|
71
|
+
declare function isVideoType(contentType: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Check if content type represents a PDF document
|
|
74
|
+
*/
|
|
75
|
+
declare function isPdfType(contentType: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Check if content type represents a renderable file (image, video, or PDF)
|
|
78
|
+
*/
|
|
79
|
+
declare function isRenderableType(contentType: string): boolean;
|
|
80
|
+
|
|
81
|
+
type index_EntityAccessRecord = EntityAccessRecord;
|
|
82
|
+
type index_EntityAction = EntityAction;
|
|
83
|
+
type index_EntityPermissionCheck = EntityPermissionCheck;
|
|
84
|
+
type index_EntityPermissionLevel = EntityPermissionLevel;
|
|
85
|
+
type index_EntityType = EntityType;
|
|
86
|
+
type index_ItemType<T> = ItemType<T>;
|
|
87
|
+
type index_KeyOfStringOrNumber<T> = KeyOfStringOrNumber<T>;
|
|
88
|
+
type index_PermissionEffect = PermissionEffect;
|
|
89
|
+
type index_StorageObjectMetadata = StorageObjectMetadata;
|
|
90
|
+
declare const index_getContentType: typeof getContentType;
|
|
91
|
+
declare const index_isImageType: typeof isImageType;
|
|
92
|
+
declare const index_isPdfType: typeof isPdfType;
|
|
93
|
+
declare const index_isRenderableType: typeof isRenderableType;
|
|
94
|
+
declare const index_isUsable: typeof isUsable;
|
|
95
|
+
declare const index_isVideoType: typeof isVideoType;
|
|
96
|
+
declare namespace index {
|
|
97
|
+
export { type index_EntityAccessRecord as EntityAccessRecord, type index_EntityAction as EntityAction, type index_EntityPermissionCheck as EntityPermissionCheck, type index_EntityPermissionLevel as EntityPermissionLevel, type index_EntityType as EntityType, type index_ItemType as ItemType, type index_KeyOfStringOrNumber as KeyOfStringOrNumber, type index_PermissionEffect as PermissionEffect, type index_StorageObjectMetadata as StorageObjectMetadata, index_getContentType as getContentType, index_isImageType as isImageType, index_isPdfType as isPdfType, index_isRenderableType as isRenderableType, index_isUsable as isUsable, index_isVideoType as isVideoType };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { type EntityType as E, type ItemType as I, type KeyOfStringOrNumber as K, type PermissionEffect as P, type StorageObjectMetadata as S, type EntityPermissionLevel as a, type EntityAction as b, type EntityPermissionCheck as c, type EntityAccessRecord as d, isImageType as e, isVideoType as f, getContentType as g, isPdfType as h, index as i, isRenderableType as j, isUsable as k };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a new UUID v4-like string.
|
|
3
|
+
* Note: This is not cryptographically secure and uses Math.random().
|
|
4
|
+
* @returns A UUID string in the format xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
|
5
|
+
*/
|
|
6
|
+
declare function newUuid(): string;
|
|
7
|
+
|
|
8
|
+
declare const index_newUuid: typeof newUuid;
|
|
9
|
+
declare namespace index {
|
|
10
|
+
export { index_newUuid as newUuid };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { index as i, newUuid as n };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
type ValidationRule<T = string> = {
|
|
2
|
+
validate: (value: T) => boolean;
|
|
3
|
+
message: string;
|
|
4
|
+
};
|
|
5
|
+
type ValidationResult = {
|
|
6
|
+
isValid: boolean;
|
|
7
|
+
error?: string;
|
|
8
|
+
};
|
|
9
|
+
declare function validateValue<T>(value: T, rules: ValidationRule<T>[]): ValidationResult;
|
|
10
|
+
declare function validateEmail(email: string): ValidationResult;
|
|
11
|
+
declare function validateRequired(value: string | number | null | undefined): ValidationResult;
|
|
12
|
+
declare function validateMinLength(min: number): (value: string) => ValidationResult;
|
|
13
|
+
declare function validateMaxLength(max: number): (value: string) => ValidationResult;
|
|
14
|
+
declare function validatePattern(pattern: RegExp, message: string): (value: string) => ValidationResult;
|
|
15
|
+
|
|
16
|
+
type PasswordStrength = "weak" | "fair" | "good" | "strong";
|
|
17
|
+
interface PasswordStrengthResult {
|
|
18
|
+
strength: PasswordStrength;
|
|
19
|
+
score: number;
|
|
20
|
+
feedback: string[];
|
|
21
|
+
}
|
|
22
|
+
declare function calculatePasswordStrength(password: string): PasswordStrengthResult;
|
|
23
|
+
|
|
24
|
+
type index_PasswordStrength = PasswordStrength;
|
|
25
|
+
type index_PasswordStrengthResult = PasswordStrengthResult;
|
|
26
|
+
type index_ValidationResult = ValidationResult;
|
|
27
|
+
type index_ValidationRule<T = string> = ValidationRule<T>;
|
|
28
|
+
declare const index_calculatePasswordStrength: typeof calculatePasswordStrength;
|
|
29
|
+
declare const index_validateEmail: typeof validateEmail;
|
|
30
|
+
declare const index_validateMaxLength: typeof validateMaxLength;
|
|
31
|
+
declare const index_validateMinLength: typeof validateMinLength;
|
|
32
|
+
declare const index_validatePattern: typeof validatePattern;
|
|
33
|
+
declare const index_validateRequired: typeof validateRequired;
|
|
34
|
+
declare const index_validateValue: typeof validateValue;
|
|
35
|
+
declare namespace index {
|
|
36
|
+
export { type index_PasswordStrength as PasswordStrength, type index_PasswordStrengthResult as PasswordStrengthResult, type index_ValidationResult as ValidationResult, type index_ValidationRule as ValidationRule, index_calculatePasswordStrength as calculatePasswordStrength, index_validateEmail as validateEmail, index_validateMaxLength as validateMaxLength, index_validateMinLength as validateMinLength, index_validatePattern as validatePattern, index_validateRequired as validateRequired, index_validateValue as validateValue };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { type PasswordStrength as P, type ValidationRule as V, type ValidationResult as a, validateEmail as b, validateRequired as c, validateMinLength as d, validateMaxLength as e, validatePattern as f, type PasswordStrengthResult as g, calculatePasswordStrength as h, index as i, validateValue as v };
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sort an array of objects by a property
|
|
3
|
+
* @param items - The array to sort
|
|
4
|
+
* @param property - The property to sort by
|
|
5
|
+
* @param isAscending - Whether to sort ascending (default: false for descending)
|
|
6
|
+
* @returns A new sorted array
|
|
7
|
+
*/
|
|
8
|
+
declare function sortBy<T>(items: T[], property: keyof T, isAscending?: boolean): T[];
|
|
9
|
+
/**
|
|
10
|
+
* Sort an array using a custom accessor function
|
|
11
|
+
* @param items - The array to sort
|
|
12
|
+
* @param func - Function that extracts the value to sort by
|
|
13
|
+
* @param isAscending - Whether to sort ascending (default: false for descending)
|
|
14
|
+
* @returns A new sorted array
|
|
15
|
+
*/
|
|
16
|
+
declare function sort<T>(items: T[], func: (item: T) => any, isAscending?: boolean): T[];
|
|
17
|
+
/**
|
|
18
|
+
* Select the item with the minimum value based on a selector function
|
|
19
|
+
* @param items - The array to search
|
|
20
|
+
* @param action - Function that extracts the value to compare
|
|
21
|
+
* @returns The item with the minimum value
|
|
22
|
+
*/
|
|
23
|
+
declare function selectByMin<T>(items: T[], action: (item: T) => any): T;
|
|
24
|
+
|
|
25
|
+
interface GroupedItems<T> {
|
|
26
|
+
items: T[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Group an array by a key or function
|
|
30
|
+
* @param list - The array to group
|
|
31
|
+
* @param key - The property name or function to extract the grouping key
|
|
32
|
+
* @returns A Map of grouped items
|
|
33
|
+
*/
|
|
34
|
+
declare function groupBy<T>(list: T[], key: (keyof T & string) | ((item: T) => any)): Map<any, T[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Group an array by multiple criteria
|
|
37
|
+
* @param items - The array to group
|
|
38
|
+
* @param criteria - Array of property names to group by
|
|
39
|
+
* @returns Array of grouped items
|
|
40
|
+
*/
|
|
41
|
+
declare function groupByMultipleCriteria<T>(items: Array<T>, criteria: Array<keyof T>): Array<GroupedItems<T>>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Split an array into chunks of a specified size
|
|
45
|
+
* @param array - The array to chunk
|
|
46
|
+
* @param chunkSize - The size of each chunk
|
|
47
|
+
* @returns An array of chunks
|
|
48
|
+
* @throws Error if chunkSize is less than or equal to 0
|
|
49
|
+
* @example chunk([1, 2, 3, 4, 5], 2) // [[1, 2], [3, 4], [5]]
|
|
50
|
+
*/
|
|
51
|
+
declare function chunk<T>(array: T[], chunkSize: number): T[][];
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use `chunk` instead
|
|
54
|
+
* Split an array into chunks of a specified size
|
|
55
|
+
* @param array - The array to chunk
|
|
56
|
+
* @param chunkSize - The size of each chunk
|
|
57
|
+
* @returns An array of chunks
|
|
58
|
+
*/
|
|
59
|
+
declare const chunkArray: typeof chunk;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Extract unique values from an array of objects by a specified key
|
|
63
|
+
* @param array - The array to process
|
|
64
|
+
* @param key - The key to extract unique values from
|
|
65
|
+
* @returns An array of unique values
|
|
66
|
+
* @example unique([{id: 1}, {id: 2}, {id: 1}], 'id') // [1, 2]
|
|
67
|
+
*/
|
|
68
|
+
declare function unique<T>(array: T[], key: keyof T): any[];
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use `unique` instead
|
|
71
|
+
* Extract unique values from an array of objects by a specified key
|
|
72
|
+
* @param array - The array to process
|
|
73
|
+
* @param key - The key to extract unique values from
|
|
74
|
+
* @returns An array of unique values
|
|
75
|
+
*/
|
|
76
|
+
declare const mapUnique: typeof unique;
|
|
77
|
+
/**
|
|
78
|
+
* @deprecated Use `unique` instead - note: original had typo in name
|
|
79
|
+
* Extract unique values from an array of objects by a specified key
|
|
80
|
+
* @param array - The array to process
|
|
81
|
+
* @param key - The key to extract unique values from
|
|
82
|
+
* @returns An array of unique values
|
|
83
|
+
*/
|
|
84
|
+
declare const mapUnqiue: typeof unique;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Create an array of numbers in a range
|
|
88
|
+
* @param size - The number of elements
|
|
89
|
+
* @param startAt - The starting value (default: 0)
|
|
90
|
+
* @returns A readonly array of numbers
|
|
91
|
+
* @example range(5) // [0, 1, 2, 3, 4]
|
|
92
|
+
* @example range(5, 1) // [1, 2, 3, 4, 5]
|
|
93
|
+
*/
|
|
94
|
+
declare function range(size: number, startAt?: number): ReadonlyArray<number>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Calculate the sum of an array of numbers with fallback
|
|
98
|
+
* @param itemsArray - The array of numbers to sum
|
|
99
|
+
* @param defaultValue - The default value if array is empty or invalid (default: 0)
|
|
100
|
+
* @returns The sum of the array or the default value
|
|
101
|
+
*/
|
|
102
|
+
declare function tryGetSum(itemsArray: number[], defaultValue?: number): number;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Calculate the average of an array of numbers with fallback
|
|
106
|
+
* @param items - The array of numbers
|
|
107
|
+
* @param defaultValue - The default value if array is empty or invalid (default: 0)
|
|
108
|
+
* @returns The average of the array or the default value
|
|
109
|
+
*/
|
|
110
|
+
declare function tryGetAverage(items: number[], defaultValue?: number): number;
|
|
111
|
+
/**
|
|
112
|
+
* Calculate the average of an array of numbers
|
|
113
|
+
* @param arr - The array of numbers
|
|
114
|
+
* @returns The average of the array
|
|
115
|
+
* @note This function does not handle empty arrays - use tryGetAverage for that
|
|
116
|
+
*/
|
|
117
|
+
declare function getAverage(arr: number[]): number;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Convert an array of objects to a keyed object
|
|
121
|
+
* @param array - The array to convert
|
|
122
|
+
* @param key - The key to use as the object key
|
|
123
|
+
* @returns A record keyed by the specified property
|
|
124
|
+
* @example convertArrayToObject([{id: 1, name: 'a'}, {id: 2, name: 'b'}], 'id')
|
|
125
|
+
* // { 1: {id: 1, name: 'a'}, 2: {id: 2, name: 'b'} }
|
|
126
|
+
*/
|
|
127
|
+
declare function convertArrayToObject<T extends {
|
|
128
|
+
[key in K]: number;
|
|
129
|
+
}, K extends keyof T>(array: T[], key: K): Record<string, T>;
|
|
130
|
+
|
|
131
|
+
type index_GroupedItems<T> = GroupedItems<T>;
|
|
132
|
+
declare const index_chunk: typeof chunk;
|
|
133
|
+
declare const index_chunkArray: typeof chunkArray;
|
|
134
|
+
declare const index_convertArrayToObject: typeof convertArrayToObject;
|
|
135
|
+
declare const index_getAverage: typeof getAverage;
|
|
136
|
+
declare const index_groupBy: typeof groupBy;
|
|
137
|
+
declare const index_groupByMultipleCriteria: typeof groupByMultipleCriteria;
|
|
138
|
+
declare const index_mapUnique: typeof mapUnique;
|
|
139
|
+
declare const index_mapUnqiue: typeof mapUnqiue;
|
|
140
|
+
declare const index_range: typeof range;
|
|
141
|
+
declare const index_selectByMin: typeof selectByMin;
|
|
142
|
+
declare const index_sort: typeof sort;
|
|
143
|
+
declare const index_sortBy: typeof sortBy;
|
|
144
|
+
declare const index_tryGetAverage: typeof tryGetAverage;
|
|
145
|
+
declare const index_tryGetSum: typeof tryGetSum;
|
|
146
|
+
declare const index_unique: typeof unique;
|
|
147
|
+
declare namespace index {
|
|
148
|
+
export { type index_GroupedItems as GroupedItems, index_chunk as chunk, index_chunkArray as chunkArray, index_convertArrayToObject as convertArrayToObject, index_getAverage as getAverage, index_groupBy as groupBy, index_groupByMultipleCriteria as groupByMultipleCriteria, index_mapUnique as mapUnique, index_mapUnqiue as mapUnqiue, index_range as range, index_selectByMin as selectByMin, index_sort as sort, index_sortBy as sortBy, index_tryGetAverage as tryGetAverage, index_tryGetSum as tryGetSum, index_unique as unique };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export { type GroupedItems as G, sort as a, selectByMin as b, groupByMultipleCriteria as c, chunk as d, chunkArray as e, mapUnqiue as f, groupBy as g, tryGetAverage as h, index as i, getAverage as j, convertArrayToObject as k, mapUnique as m, range as r, sortBy as s, tryGetSum as t, unique as u };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a promise that resolves after the specified number of milliseconds
|
|
3
|
+
*/
|
|
4
|
+
declare function delay(ms: number): Promise<void>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Debounces a function call by the specified wait time
|
|
8
|
+
*/
|
|
9
|
+
declare function debounce<T extends (...args: any[]) => void>(func: T, wait: number): void;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Executes an array of async tasks with a concurrency limit
|
|
13
|
+
* @param tasks - Array of functions that return promises
|
|
14
|
+
* @param concurrency - Maximum number of concurrent tasks
|
|
15
|
+
* @returns Promise resolving to an array of results in the same order as input tasks
|
|
16
|
+
*/
|
|
17
|
+
declare function concurrent<T>(tasks: Array<() => Promise<T>>, concurrency: number): Promise<T[]>;
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `concurrent` instead
|
|
20
|
+
* Executes an array of async tasks with a concurrency limit
|
|
21
|
+
*/
|
|
22
|
+
declare const promiseAllWithConcurrencyLimit: typeof concurrent;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A semaphore implementation for controlling concurrent access
|
|
26
|
+
*/
|
|
27
|
+
declare class Semaphore {
|
|
28
|
+
private tasks;
|
|
29
|
+
private count;
|
|
30
|
+
constructor(count: number);
|
|
31
|
+
acquire(): Promise<void>;
|
|
32
|
+
release(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type index_Semaphore = Semaphore;
|
|
36
|
+
declare const index_Semaphore: typeof Semaphore;
|
|
37
|
+
declare const index_concurrent: typeof concurrent;
|
|
38
|
+
declare const index_debounce: typeof debounce;
|
|
39
|
+
declare const index_delay: typeof delay;
|
|
40
|
+
declare const index_promiseAllWithConcurrencyLimit: typeof promiseAllWithConcurrencyLimit;
|
|
41
|
+
declare namespace index {
|
|
42
|
+
export { index_Semaphore as Semaphore, index_concurrent as concurrent, index_debounce as debounce, index_delay as delay, index_promiseAllWithConcurrencyLimit as promiseAllWithConcurrencyLimit };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { Semaphore as S, debounce as a, concurrent as c, delay as d, index as i, promiseAllWithConcurrencyLimit as p };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current viewport width indicates a small device (mobile).
|
|
3
|
+
* @returns true if window width is 640px or less
|
|
4
|
+
*/
|
|
5
|
+
declare function isSmallDevice(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Checks if the current device is an iPhone based on user agent.
|
|
8
|
+
* @returns true if running on an iPhone
|
|
9
|
+
*/
|
|
10
|
+
declare function isIphone(): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the app was launched as a Progressive Web App (PWA).
|
|
13
|
+
* Supports both iOS (navigator.standalone) and Android/other devices (display-mode: standalone).
|
|
14
|
+
* @returns true if running as a PWA, false if running in browser
|
|
15
|
+
*/
|
|
16
|
+
declare function isPwaLaunched(): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Asynchronously checks if the device has a camera available.
|
|
19
|
+
* @returns Promise resolving to true if a video input device exists
|
|
20
|
+
*/
|
|
21
|
+
declare function hasCameraAsync(): Promise<boolean>;
|
|
22
|
+
|
|
23
|
+
declare const index_hasCameraAsync: typeof hasCameraAsync;
|
|
24
|
+
declare const index_isIphone: typeof isIphone;
|
|
25
|
+
declare const index_isPwaLaunched: typeof isPwaLaunched;
|
|
26
|
+
declare const index_isSmallDevice: typeof isSmallDevice;
|
|
27
|
+
declare namespace index {
|
|
28
|
+
export { index_hasCameraAsync as hasCameraAsync, index_isIphone as isIphone, index_isPwaLaunched as isPwaLaunched, index_isSmallDevice as isSmallDevice };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { isSmallDevice as a, isIphone as b, isPwaLaunched as c, hasCameraAsync as h, index as i };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object with the original item's properties merged with updates.
|
|
3
|
+
* Immutable update pattern - returns a new object without modifying the original.
|
|
4
|
+
* @param item - The original object
|
|
5
|
+
* @param updates - Partial object with properties to update
|
|
6
|
+
* @returns A new object with merged properties
|
|
7
|
+
*/
|
|
8
|
+
declare function withUpdate<T>(item: T, updates: Partial<T>): T;
|
|
9
|
+
/**
|
|
10
|
+
* Compares two objects and returns only the properties that have changed.
|
|
11
|
+
* Performs shallow comparison of property values.
|
|
12
|
+
* @param oldObj - The original object
|
|
13
|
+
* @param newObj - The new object to compare against
|
|
14
|
+
* @returns A partial object containing only the changed properties with their new values
|
|
15
|
+
*/
|
|
16
|
+
declare function getObjectChanges<T extends Record<string, any>>(oldObj: T, newObj: T): Partial<T>;
|
|
17
|
+
|
|
18
|
+
declare const index_getObjectChanges: typeof getObjectChanges;
|
|
19
|
+
declare const index_withUpdate: typeof withUpdate;
|
|
20
|
+
declare namespace index {
|
|
21
|
+
export { index_getObjectChanges as getObjectChanges, index_withUpdate as withUpdate };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { getObjectChanges as g, index as i, withUpdate as w };
|