@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.
Files changed (54) hide show
  1. package/dist/array/index.d.ts +1 -0
  2. package/dist/array/index.js +136 -0
  3. package/dist/async/index.d.ts +1 -0
  4. package/dist/async/index.js +67 -0
  5. package/dist/cache/index.d.ts +1 -0
  6. package/dist/cache/index.js +42 -0
  7. package/dist/color/index.d.ts +1 -0
  8. package/dist/color/index.js +16 -0
  9. package/dist/date/index.d.ts +2 -0
  10. package/dist/date/index.js +102 -0
  11. package/dist/dev/index.d.ts +1 -0
  12. package/dist/dev/index.js +21 -0
  13. package/dist/device/index.d.ts +1 -0
  14. package/dist/device/index.js +31 -0
  15. package/dist/enum/index.d.ts +1 -0
  16. package/dist/enum/index.js +19 -0
  17. package/dist/error/index.d.ts +1 -0
  18. package/dist/error/index.js +198 -0
  19. package/dist/format/index.d.ts +1 -0
  20. package/dist/format/index.js +36 -0
  21. package/dist/index-B2oAfh_i.d.ts +63 -0
  22. package/dist/index-BDWEMkWa.d.ts +56 -0
  23. package/dist/index-BSNY-QEc.d.ts +15 -0
  24. package/dist/index-BaA8cg0E.d.ts +100 -0
  25. package/dist/index-Btn_GVfm.d.ts +13 -0
  26. package/dist/index-BxUoIlv_.d.ts +39 -0
  27. package/dist/index-ByjfWGR4.d.ts +151 -0
  28. package/dist/index-C-YwC08Y.d.ts +45 -0
  29. package/dist/index-C062CkPL.d.ts +31 -0
  30. package/dist/index-C8CxeaqZ.d.ts +24 -0
  31. package/dist/index-CZbs1QQN.d.ts +102 -0
  32. package/dist/index-Cp7KyTeB.d.ts +23 -0
  33. package/dist/index-CrplC0qf.d.ts +29 -0
  34. package/dist/index-Cvl_0aDq.d.ts +14 -0
  35. package/dist/index-D_IvPWYI.d.ts +77 -0
  36. package/dist/index-DdaZnk7j.d.ts +28 -0
  37. package/dist/index-vLuR45Km.d.ts +27 -0
  38. package/dist/index.d.ts +84 -0
  39. package/dist/index.js +1279 -0
  40. package/dist/object/index.d.ts +1 -0
  41. package/dist/object/index.js +115 -0
  42. package/dist/state/index.d.ts +1 -0
  43. package/dist/state/index.js +17 -0
  44. package/dist/string/index.d.ts +1 -0
  45. package/dist/string/index.js +55 -0
  46. package/dist/tailwind/index.d.ts +2 -0
  47. package/dist/tailwind/index.js +9 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/index.js +37 -0
  50. package/dist/uuid/index.d.ts +1 -0
  51. package/dist/uuid/index.js +10 -0
  52. package/dist/validation/index.d.ts +1 -0
  53. package/dist/validation/index.js +123 -0
  54. package/package.json +50 -0
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Create a new object with specified keys omitted
3
+ * @param obj - The source object
4
+ * @param keys - The key(s) to omit
5
+ * @returns A new object without the specified keys
6
+ * @example omit({a: 1, b: 2, c: 3}, ['a', 'b']) // {c: 3}
7
+ */
8
+ declare function omit<T extends Record<string, any>, K extends (keyof T & string) | string>(obj: T, keys: K | K[]): Omit<T, K>;
9
+
10
+ /**
11
+ * Create a new object with only the specified keys
12
+ * @param obj - The source object
13
+ * @param keys - The keys to include
14
+ * @returns A new object with only the specified keys
15
+ * @example pick({a: 1, b: 2, c: 3}, ['a', 'b']) // {a: 1, b: 2}
16
+ */
17
+ declare function pick<T extends {}, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
18
+ /**
19
+ * @deprecated Use `pick` instead
20
+ * Create a new object with only the specified keys
21
+ * @param obj - The source object
22
+ * @param keys - The keys to include
23
+ * @returns A new object with only the specified keys
24
+ */
25
+ declare const includeOnly: typeof pick;
26
+
27
+ /**
28
+ * Get the difference between two objects
29
+ * @param oldValue - The original object
30
+ * @param newValue - The new object to compare against
31
+ * @returns An object containing only the changed values
32
+ * @example diff({a: 1, b: 2}, {a: 1, b: 3}) // {b: 3}
33
+ */
34
+ declare function diff(oldValue: Record<string, any>, newValue: Record<string, any>): Record<string, any>;
35
+
36
+ /**
37
+ * Get a value from an object using a dot-notation path
38
+ * @param obj - The object to get the value from
39
+ * @param path - The dot-notation path (e.g., "user.address.city")
40
+ * @returns The value at the path, or undefined if not found
41
+ * @example getPath({user: {name: 'John'}}, 'user.name') // 'John'
42
+ */
43
+ declare function getPath(obj: any, path: string): any;
44
+ /**
45
+ * @deprecated Use `getPath` instead
46
+ * Get a value from an object using a dot-notation path
47
+ * @param obj - The object to get the value from
48
+ * @param path - The dot-notation path
49
+ * @returns The value at the path, or undefined if not found
50
+ */
51
+ declare const getValueByPath: typeof getPath;
52
+
53
+ /**
54
+ * Set a value in an object using a dot-notation path
55
+ * Creates intermediate objects if they don't exist
56
+ * @param obj - The object to modify
57
+ * @param path - The dot-notation path (e.g., "user.address.city")
58
+ * @param value - The value to set
59
+ * @example setPath({}, 'user.name', 'John') // mutates obj to {user: {name: 'John'}}
60
+ */
61
+ declare function setPath(obj: any, path: string, value: any): void;
62
+ /**
63
+ * @deprecated Use `setPath` instead
64
+ * Set a value in an object using a dot-notation path
65
+ * @param obj - The object to modify
66
+ * @param path - The dot-notation path
67
+ * @param value - The value to set
68
+ */
69
+ declare const setValueByPath: typeof setPath;
70
+
71
+ /**
72
+ * Perform a shallow deep equality check on two objects
73
+ * Compares object keys and their values at one level
74
+ * @param obj1 - First object to compare
75
+ * @param obj2 - Second object to compare
76
+ * @returns true if objects have the same keys with equal values
77
+ * @example deepEquals({a: 1, b: 2}, {a: 1, b: 2}) // true
78
+ */
79
+ declare function deepEquals<T extends Record<string, any>>(obj1: T, obj2: T): boolean;
80
+ /**
81
+ * Alias for deepEquals - check if two objects are equal
82
+ * @param obj1 - First object to compare
83
+ * @param obj2 - Second object to compare
84
+ * @returns true if objects are equal
85
+ */
86
+ declare const isDeepEqual: typeof deepEquals;
87
+
88
+ declare const index_deepEquals: typeof deepEquals;
89
+ declare const index_diff: typeof diff;
90
+ declare const index_getPath: typeof getPath;
91
+ declare const index_getValueByPath: typeof getValueByPath;
92
+ declare const index_includeOnly: typeof includeOnly;
93
+ declare const index_isDeepEqual: typeof isDeepEqual;
94
+ declare const index_omit: typeof omit;
95
+ declare const index_pick: typeof pick;
96
+ declare const index_setPath: typeof setPath;
97
+ declare const index_setValueByPath: typeof setValueByPath;
98
+ declare namespace index {
99
+ export { index_deepEquals as deepEquals, index_diff as diff, index_getPath as getPath, index_getValueByPath as getValueByPath, index_includeOnly as includeOnly, index_isDeepEqual as isDeepEqual, index_omit as omit, index_pick as pick, index_setPath as setPath, index_setValueByPath as setValueByPath };
100
+ }
101
+
102
+ export { includeOnly as a, getValueByPath as b, setValueByPath as c, diff as d, deepEquals as e, isDeepEqual as f, getPath as g, index as i, omit as o, pick as p, setPath as s };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Extracts all string values from a TypeScript enum.
3
+ * Filters out numeric keys that TypeScript adds for reverse mapping in numeric enums.
4
+ * @param enumObject - The enum object to extract values from
5
+ * @returns An array of enum values (excluding numeric reverse-mapping keys)
6
+ */
7
+ declare function getEnumValues<T extends Record<string, unknown>>(enumObject: T): Array<T[keyof T]>;
8
+ /**
9
+ * Parses a string value into an enum member.
10
+ * Supports both string enum keys and numeric enum values.
11
+ * @param enumType - The enum type to parse into
12
+ * @param value - The string value to parse
13
+ * @returns The matching enum member, or undefined if no match found
14
+ */
15
+ declare function parseStringToEnum<T extends object>(enumType: T, value: string): T[keyof T] | undefined;
16
+
17
+ declare const index_getEnumValues: typeof getEnumValues;
18
+ declare const index_parseStringToEnum: typeof parseStringToEnum;
19
+ declare namespace index {
20
+ export { index_getEnumValues as getEnumValues, index_parseStringToEnum as parseStringToEnum };
21
+ }
22
+
23
+ export { getEnumValues as g, index as i, parseStringToEnum as p };
@@ -0,0 +1,29 @@
1
+ type AsyncFunction<T> = () => Promise<T>;
2
+ /**
3
+ * Caches the result of an asynchronous function based on a key and duration.
4
+ * Ensures only one execution occurs at a time for the same key.
5
+ *
6
+ * @param key - Unique identifier for the cached data.
7
+ * @param fn - The asynchronous function to execute and cache.
8
+ * @param duration - Cache duration in milliseconds.
9
+ * @returns A promise resolving to the function's result.
10
+ */
11
+ declare function cacheFunction<T>(key: string, fn: AsyncFunction<T>, duration: number): Promise<T>;
12
+ /**
13
+ * Clears a specific cache entry by key.
14
+ * @param key - The cache key to clear.
15
+ */
16
+ declare function clearCache(key: string): void;
17
+ /**
18
+ * Clears all cache entries.
19
+ */
20
+ declare function clearAllCache(): void;
21
+
22
+ declare const index_cacheFunction: typeof cacheFunction;
23
+ declare const index_clearAllCache: typeof clearAllCache;
24
+ declare const index_clearCache: typeof clearCache;
25
+ declare namespace index {
26
+ export { index_cacheFunction as cacheFunction, index_clearAllCache as clearAllCache, index_clearCache as clearCache };
27
+ }
28
+
29
+ export { clearCache as a, clearAllCache as b, cacheFunction as c, index as i };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Determines if a hex color is dark based on its luminance.
3
+ * Uses the ITU-R BT.709 formula for calculating relative luminance.
4
+ * @param c - A hex color string (e.g., "#000000" or "#fff")
5
+ * @returns true if the color is considered dark (luma < 70)
6
+ */
7
+ declare function isDarkColor(c: string): boolean;
8
+
9
+ declare const index_isDarkColor: typeof isDarkColor;
10
+ declare namespace index {
11
+ export { index_isDarkColor as isDarkColor };
12
+ }
13
+
14
+ export { isDarkColor as a, index as i };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Convert a string to camelCase
3
+ * @param str - The string to convert
4
+ * @returns The camelCased string
5
+ * @example camelize("hello world") // "helloWorld"
6
+ */
7
+ declare function camelize(str: string): string;
8
+
9
+ /**
10
+ * Convert a string to PascalCase
11
+ * @param str - The string to convert
12
+ * @returns The PascalCased string
13
+ * @example pascalize("hello world") // "Hello World"
14
+ */
15
+ declare function pascalize(str: string): string;
16
+ /**
17
+ * Convert a string to PascalCase with spaces between words
18
+ * Handles camelCase, snake_case, kebab-case, and other delimiters
19
+ * @param input - The string to convert
20
+ * @returns The PascalCased string with spaces
21
+ * @example pascalizeWithSpaces("bazQux") // "Baz Qux"
22
+ * @example pascalizeWithSpaces("hello_world") // "Hello World"
23
+ */
24
+ declare function pascalizeWithSpaces(input: string): string;
25
+
26
+ /**
27
+ * Generate a URL-friendly slug from a string
28
+ * @param text - Input text to convert to slug
29
+ * @returns URL-safe slug (lowercase, hyphens, no special chars)
30
+ * @example slugify("Version 2.0") // "version-2-0"
31
+ */
32
+ declare function slugify(text: string): string;
33
+ /**
34
+ * @deprecated Use `slugify` instead
35
+ * Generate a URL-friendly slug from a string
36
+ * @param text - Input text to convert to slug
37
+ * @returns URL-safe slug (lowercase, hyphens, no special chars)
38
+ */
39
+ declare const generateSlug: typeof slugify;
40
+
41
+ /**
42
+ * Sanitize a string by escaping quotes for safe use in queries
43
+ * @param value - The string to sanitize
44
+ * @returns The sanitized string with escaped quotes
45
+ * @example sanitizeInput('O"Brien') // 'O""Brien'
46
+ */
47
+ declare function sanitizeInput(value: string): string;
48
+
49
+ /**
50
+ * Check if a string is blank (null, undefined, or only whitespace)
51
+ * @param value - The string to check
52
+ * @returns true if the string is null, undefined, or only whitespace
53
+ * @example isBlank(" ") // true
54
+ * @example isBlank("hello") // false
55
+ */
56
+ declare function isBlank(value: string | undefined | null): boolean;
57
+ /**
58
+ * @deprecated Use `isBlank` instead
59
+ * Check if a string is null, undefined, or only whitespace
60
+ * @param value - The string to check
61
+ * @returns true if the string is null, undefined, or only whitespace
62
+ */
63
+ declare const isNullOrWhitespace: typeof isBlank;
64
+
65
+ declare const index_camelize: typeof camelize;
66
+ declare const index_generateSlug: typeof generateSlug;
67
+ declare const index_isBlank: typeof isBlank;
68
+ declare const index_isNullOrWhitespace: typeof isNullOrWhitespace;
69
+ declare const index_pascalize: typeof pascalize;
70
+ declare const index_pascalizeWithSpaces: typeof pascalizeWithSpaces;
71
+ declare const index_sanitizeInput: typeof sanitizeInput;
72
+ declare const index_slugify: typeof slugify;
73
+ declare namespace index {
74
+ export { index_camelize as camelize, index_generateSlug as generateSlug, index_isBlank as isBlank, index_isNullOrWhitespace as isNullOrWhitespace, index_pascalize as pascalize, index_pascalizeWithSpaces as pascalizeWithSpaces, index_sanitizeInput as sanitizeInput, index_slugify as slugify };
75
+ }
76
+
77
+ export { pascalizeWithSpaces as a, sanitizeInput as b, camelize as c, isBlank as d, isNullOrWhitespace as e, generateSlug as g, index as i, pascalize as p, slugify as s };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Formats a number as a USD currency string
3
+ */
4
+ declare function formatCurrency(value: number | bigint): string;
5
+ /**
6
+ * @deprecated Use `formatCurrency` instead
7
+ * Formats a number as a USD currency string
8
+ */
9
+ declare const toUsdString: typeof formatCurrency;
10
+ /**
11
+ * Formats a number with up to 2 decimal places
12
+ */
13
+ declare function toNumberString(value: number | bigint): string;
14
+
15
+ /**
16
+ * Formats a number as a decimal string with the specified number of decimal places
17
+ */
18
+ declare function toDecimalString(num: number, decimalPlaces?: number | undefined): string;
19
+
20
+ declare const index_formatCurrency: typeof formatCurrency;
21
+ declare const index_toDecimalString: typeof toDecimalString;
22
+ declare const index_toNumberString: typeof toNumberString;
23
+ declare const index_toUsdString: typeof toUsdString;
24
+ declare namespace index {
25
+ export { index_formatCurrency as formatCurrency, index_toDecimalString as toDecimalString, index_toNumberString as toNumberString, index_toUsdString as toUsdString };
26
+ }
27
+
28
+ export { toNumberString as a, toDecimalString as b, formatCurrency as f, index as i, toUsdString as t };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Checks if the current environment is development mode.
3
+ * @returns true if WITH_MODE environment variable is set to "development"
4
+ */
5
+ declare function isDevEnvironment(): boolean;
6
+ /**
7
+ * Alias for isDevEnvironment.
8
+ * Checks if the current environment is development mode.
9
+ * @returns true if WITH_MODE environment variable is set to "development"
10
+ */
11
+ declare function isDev(): boolean;
12
+ /**
13
+ * Logs messages to the console only in development environment.
14
+ * Useful for debug logging that should not appear in production.
15
+ * @param message - The primary message to log
16
+ * @param optionalParams - Additional parameters to log
17
+ */
18
+ declare function debugLog(message?: any, ...optionalParams: any[]): void;
19
+
20
+ declare const index_debugLog: typeof debugLog;
21
+ declare const index_isDev: typeof isDev;
22
+ declare const index_isDevEnvironment: typeof isDevEnvironment;
23
+ declare namespace index {
24
+ export { index_debugLog as debugLog, index_isDev as isDev, index_isDevEnvironment as isDevEnvironment };
25
+ }
26
+
27
+ export { isDevEnvironment as a, isDev as b, debugLog as d, index as i };
@@ -0,0 +1,84 @@
1
+ export { c as camelize, g as generateSlug, d as isBlank, e as isNullOrWhitespace, p as pascalize, a as pascalizeWithSpaces, b as sanitizeInput, s as slugify, i as string } from './index-D_IvPWYI.js';
2
+ export { G as GroupedItems, i as array, d as chunk, e as chunkArray, k as convertArrayToObject, j as getAverage, g as groupBy, c as groupByMultipleCriteria, m as mapUnique, f as mapUnqiue, r as range, b as selectByMin, a as sort, s as sortBy, h as tryGetAverage, t as tryGetSum, u as unique } from './index-ByjfWGR4.js';
3
+ export { e as deepEquals, d as diff, g as getPath, b as getValueByPath, a as includeOnly, f as isDeepEqual, i as object, o as omit, p as pick, s as setPath, c as setValueByPath } from './index-CZbs1QQN.js';
4
+ export { e as addDates, f as addDays, b as areDatesEqual, i as date, d as dateReviver, g as getUtcDate, a as getUtcMoment, c as isValidDate, p as parseWithDate, t as toUtcDate } from './index-BDWEMkWa.js';
5
+ export { S as Semaphore, i as async, c as concurrent, a as debounce, d as delay, p as promiseAllWithConcurrencyLimit } from './index-C-YwC08Y.js';
6
+ export { i as format, f as formatCurrency, b as toDecimalString, a as toNumberString, t as toUsdString } from './index-DdaZnk7j.js';
7
+ export { c as cn, i as tailwind } from './index-BSNY-QEc.js';
8
+ export { i as cache, c as cacheFunction, b as clearAllCache, a as clearCache } from './index-CrplC0qf.js';
9
+ export { d as EntityAccessRecord, b as EntityAction, c as EntityPermissionCheck, a as EntityPermissionLevel, E as EntityType, I as ItemType, K as KeyOfStringOrNumber, P as PermissionEffect, S as StorageObjectMetadata, g as getContentType, e as isImageType, h as isPdfType, j as isRenderableType, f as isVideoType, i as types } from './index-BaA8cg0E.js';
10
+ export { i as color, a as isDarkColor } from './index-Cvl_0aDq.js';
11
+ export { P as PasswordStrength, g as PasswordStrengthResult, a as ValidationResult, V as ValidationRule, h as calculatePasswordStrength, b as validateEmail, e as validateMaxLength, d as validateMinLength, f as validatePattern, c as validateRequired, v as validateValue, i as validation } from './index-BxUoIlv_.js';
12
+ export { E as ErrorMapping, P as PostgrestError, U as UserFriendlyError, V as ValidationErrorMapping, i as error, e as extractFieldName, c as getFormFieldError, g as getUserFriendlyError, b as isNetworkError, a as isPostgrestError } from './index-B2oAfh_i.js';
13
+ export { i as device, h as hasCameraAsync, b as isIphone, c as isPwaLaunched, a as isSmallDevice } from './index-C062CkPL.js';
14
+ export { n as newUuid, i as uuid } from './index-Btn_GVfm.js';
15
+ export { g as getObjectChanges, i as state, w as withUpdate } from './index-C8CxeaqZ.js';
16
+ export { i as enumUtils, g as getEnumValues, p as parseStringToEnum } from './index-Cp7KyTeB.js';
17
+ export { d as debugLog, i as dev, b as isDev, a as isDevEnvironment } from './index-vLuR45Km.js';
18
+ export { ClassValue } from 'clsx';
19
+ import 'moment';
20
+
21
+ declare const AccessKeys: {
22
+ readonly Timesheet: "timesheet";
23
+ readonly TimesheetAdmin: "admin_timesheet";
24
+ readonly InternalAdmin: "internal";
25
+ readonly Invoicing: "invoicing";
26
+ readonly ExpenseReport: "expense_report";
27
+ readonly ExpenseReportAdmin: "admin_expense_report";
28
+ readonly ProjectAdmin: "admin_project";
29
+ readonly FixtureCatalog: "fixture_catalog";
30
+ readonly ProjectDatabase: "project_database";
31
+ readonly Owner: "owner";
32
+ readonly User: "user";
33
+ };
34
+
35
+ declare const index$2_AccessKeys: typeof AccessKeys;
36
+ declare namespace index$2 {
37
+ export { index$2_AccessKeys as AccessKeys };
38
+ }
39
+
40
+ /**
41
+ * Downloads a file from a URL and triggers a browser download.
42
+ * @param url - The URL to fetch the file from
43
+ * @param fileName - The name to save the file as
44
+ */
45
+ declare function getFile(url: string | Request, fileName: string): Promise<void>;
46
+ /**
47
+ * Downloads text content as a file.
48
+ * @param text - The text content to download
49
+ */
50
+ declare function downloadFile(text: string): Promise<void>;
51
+ /**
52
+ * Downloads a file using a POST request.
53
+ * @param url - The URL to POST to
54
+ * @param fileName - The name to save the file as
55
+ * @param queryParams - The query parameters to send in the POST body
56
+ */
57
+ declare function getFilePost(url: string, fileName: string, queryParams: string): Promise<void>;
58
+
59
+ declare const index$1_downloadFile: typeof downloadFile;
60
+ declare const index$1_getFile: typeof getFile;
61
+ declare const index$1_getFilePost: typeof getFilePost;
62
+ declare namespace index$1 {
63
+ export { index$1_downloadFile as downloadFile, index$1_getFile as getFile, index$1_getFilePost as getFilePost };
64
+ }
65
+
66
+ /**
67
+ * Gets a unique key based on the call stack, useful for caching and deduplication.
68
+ * Filters out React-related stack frames to get a stable key.
69
+ * @returns A string key derived from the filtered call stack
70
+ */
71
+ declare function getCallerUniqueKey(): string;
72
+
73
+ declare const index_getCallerUniqueKey: typeof getCallerUniqueKey;
74
+ declare namespace index {
75
+ export { index_getCallerUniqueKey as getCallerUniqueKey };
76
+ }
77
+
78
+ /**
79
+ * Check if a value is usable (not null, not undefined, and if a number, not NaN)
80
+ * @internal
81
+ */
82
+ declare function isUsable(value: any): value is {};
83
+
84
+ export { AccessKeys, index$2 as constants, index$1 as download, downloadFile, getCallerUniqueKey, getFile, getFilePost, isUsable, index as meta };