@zairakai/js-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/LICENSE +21 -0
- package/README.md +270 -0
- package/dist/arrays.cjs +210 -0
- package/dist/arrays.d.cts +119 -0
- package/dist/arrays.d.ts +119 -0
- package/dist/arrays.js +32 -0
- package/dist/chunk-27YHP2CK.js +407 -0
- package/dist/chunk-3WNRYKPG.js +37 -0
- package/dist/chunk-42CHLXT7.js +214 -0
- package/dist/chunk-6F4PWJZI.js +0 -0
- package/dist/chunk-7SXRFZBB.js +173 -0
- package/dist/chunk-F6RSTW65.js +156 -0
- package/dist/chunk-G7ZJ23DW.js +253 -0
- package/dist/chunk-IPP7PA6H.js +136 -0
- package/dist/chunk-LDSWHSRX.js +96 -0
- package/dist/chunk-TY75OOIQ.js +700 -0
- package/dist/chunk-W6JEMFAF.js +54 -0
- package/dist/chunk-XEJLBAXE.js +164 -0
- package/dist/chunk-Z7G3SIQH.js +270 -0
- package/dist/chunk-ZJPKS2MQ.js +101 -0
- package/dist/collections.cjs +797 -0
- package/dist/collections.d.cts +353 -0
- package/dist/collections.d.ts +353 -0
- package/dist/collections.js +17 -0
- package/dist/datetime.cjs +80 -0
- package/dist/datetime.d.cts +75 -0
- package/dist/datetime.d.ts +75 -0
- package/dist/datetime.js +24 -0
- package/dist/equals.cjs +121 -0
- package/dist/equals.d.cts +24 -0
- package/dist/equals.d.ts +24 -0
- package/dist/equals.js +8 -0
- package/dist/formatters.cjs +201 -0
- package/dist/formatters.d.cts +180 -0
- package/dist/formatters.d.ts +180 -0
- package/dist/formatters.js +48 -0
- package/dist/index.cjs +2906 -0
- package/dist/index.d.cts +120 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +348 -0
- package/dist/number.cjs +279 -0
- package/dist/number.d.cts +177 -0
- package/dist/number.d.ts +177 -0
- package/dist/number.js +10 -0
- package/dist/obj.cjs +427 -0
- package/dist/obj.d.cts +177 -0
- package/dist/obj.d.ts +177 -0
- package/dist/obj.js +12 -0
- package/dist/php-arrays.cjs +954 -0
- package/dist/php-arrays.d.cts +256 -0
- package/dist/php-arrays.d.ts +256 -0
- package/dist/php-arrays.js +70 -0
- package/dist/runtime.cjs +134 -0
- package/dist/runtime.d.cts +90 -0
- package/dist/runtime.d.ts +90 -0
- package/dist/runtime.js +24 -0
- package/dist/schemas.cjs +86 -0
- package/dist/schemas.d.cts +108 -0
- package/dist/schemas.d.ts +108 -0
- package/dist/schemas.js +22 -0
- package/dist/str.cjs +499 -0
- package/dist/str.d.cts +282 -0
- package/dist/str.d.ts +282 -0
- package/dist/str.js +11 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.cts +13 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +1 -0
- package/dist/validator.cjs +251 -0
- package/dist/validator.d.cts +99 -0
- package/dist/validator.d.ts +99 -0
- package/dist/validator.js +11 -0
- package/dist/validators.cjs +217 -0
- package/dist/validators.d.cts +216 -0
- package/dist/validators.d.ts +216 -0
- package/dist/validators.js +64 -0
- package/package.json +180 -0
- package/src/arrays.ts +316 -0
- package/src/collections.ts +866 -0
- package/src/datetime.ts +103 -0
- package/src/equals.ts +134 -0
- package/src/formatters.ts +342 -0
- package/src/index.ts +36 -0
- package/src/number.ts +281 -0
- package/src/obj.ts +303 -0
- package/src/php-arrays.ts +445 -0
- package/src/pipe.ts +29 -0
- package/src/runtime.ts +194 -0
- package/src/schemas.ts +136 -0
- package/src/str.ts +438 -0
- package/src/types.ts +13 -0
- package/src/validator.ts +157 -0
- package/src/validators.ts +359 -0
package/dist/obj.d.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fluent object manipulation class with state tracking.
|
|
3
|
+
*/
|
|
4
|
+
declare class Objectable<T extends Record<string, unknown>> {
|
|
5
|
+
protected value: T;
|
|
6
|
+
protected originalValue: T;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new Objectable instance.
|
|
9
|
+
*
|
|
10
|
+
* @param {T} value The initial object value
|
|
11
|
+
*/
|
|
12
|
+
constructor(value: T);
|
|
13
|
+
/**
|
|
14
|
+
* Get the current object state.
|
|
15
|
+
*
|
|
16
|
+
* @returns {T} The current object
|
|
17
|
+
*/
|
|
18
|
+
toObject(): T;
|
|
19
|
+
/**
|
|
20
|
+
* Alias for toObject().
|
|
21
|
+
*
|
|
22
|
+
* @returns {T} The current object
|
|
23
|
+
*/
|
|
24
|
+
get(): T;
|
|
25
|
+
/**
|
|
26
|
+
* Get the original state from construction.
|
|
27
|
+
*
|
|
28
|
+
* @returns {T} The original object
|
|
29
|
+
*/
|
|
30
|
+
getOriginal(): T;
|
|
31
|
+
/**
|
|
32
|
+
* Sync original state with current state (marking it as clean).
|
|
33
|
+
*
|
|
34
|
+
* @returns {this} The Objectable instance
|
|
35
|
+
*/
|
|
36
|
+
syncOriginal(): this;
|
|
37
|
+
/**
|
|
38
|
+
* Determine if any attribute has been modified.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} [key] Optional key to check specifically
|
|
41
|
+
* @returns {boolean} True if dirty, false otherwise
|
|
42
|
+
*/
|
|
43
|
+
isDirty(key?: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Determine if the object is equivalent to its original state.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} [key] Optional key to check specifically
|
|
48
|
+
* @returns {boolean} True if clean, false otherwise
|
|
49
|
+
*/
|
|
50
|
+
isClean(key?: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Get the attributes that have been modified.
|
|
53
|
+
*
|
|
54
|
+
* @returns {Partial<T>} The dirty attributes
|
|
55
|
+
*/
|
|
56
|
+
getDirty(): Partial<T>;
|
|
57
|
+
/**
|
|
58
|
+
* Get a value by dot notation.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} key The key to retrieve
|
|
61
|
+
* @param {unknown} [defaultValue=null] The default value if not found
|
|
62
|
+
* @returns {unknown} The retrieved value
|
|
63
|
+
*/
|
|
64
|
+
dataGet(key: string, defaultValue?: unknown): unknown;
|
|
65
|
+
/**
|
|
66
|
+
* Set a value by dot notation.
|
|
67
|
+
*
|
|
68
|
+
* @param {string} key The key to set
|
|
69
|
+
* @param {unknown} value The value to set
|
|
70
|
+
* @returns {this} The Objectable instance
|
|
71
|
+
*/
|
|
72
|
+
dataSet(key: string, value: unknown): this;
|
|
73
|
+
/**
|
|
74
|
+
* Get only specified keys.
|
|
75
|
+
*
|
|
76
|
+
* @param {K[]} keys The keys to include
|
|
77
|
+
* @returns {Objectable<Pick<T, K>>} A new Objectable instance
|
|
78
|
+
*/
|
|
79
|
+
only<K extends keyof T>(keys: K[]): Objectable<Pick<T, K>>;
|
|
80
|
+
/**
|
|
81
|
+
* Get all keys except specified ones.
|
|
82
|
+
*
|
|
83
|
+
* @param {K[]} keys The keys to exclude
|
|
84
|
+
* @returns {Objectable<Omit<T, K>>} A new Objectable instance
|
|
85
|
+
*/
|
|
86
|
+
except<K extends keyof T>(keys: K[]): Objectable<Omit<T, K>>;
|
|
87
|
+
/**
|
|
88
|
+
* Map over object entries.
|
|
89
|
+
*
|
|
90
|
+
* @param {Function} callback The callback to execute
|
|
91
|
+
* @returns {Record<string, U>} The resulting object
|
|
92
|
+
*/
|
|
93
|
+
map<U>(callback: (value: T[keyof T], key: keyof T) => U): Record<string, U>;
|
|
94
|
+
/**
|
|
95
|
+
* Filter object entries.
|
|
96
|
+
*
|
|
97
|
+
* @param {Function} callback The callback to execute
|
|
98
|
+
* @returns {this} The Objectable instance
|
|
99
|
+
*/
|
|
100
|
+
filter(callback: (value: T[keyof T], key: keyof T) => boolean): this;
|
|
101
|
+
/**
|
|
102
|
+
* Merge with another object.
|
|
103
|
+
*
|
|
104
|
+
* @param {U} other The object to merge with
|
|
105
|
+
* @returns {Objectable<T & U>} A new Objectable instance
|
|
106
|
+
*/
|
|
107
|
+
merge<U extends Record<string, unknown>>(other: U): Objectable<T & U>;
|
|
108
|
+
/**
|
|
109
|
+
* Deep merge with another object (non-mutating on source).
|
|
110
|
+
*
|
|
111
|
+
* @param {Record<string, unknown>} other The object to deep merge with
|
|
112
|
+
* @returns {this} The Objectable instance
|
|
113
|
+
*/
|
|
114
|
+
mergeDeep(other: Record<string, unknown>): this;
|
|
115
|
+
/**
|
|
116
|
+
* Check if object has key.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} key The key to check
|
|
119
|
+
* @returns {boolean} True if key exists
|
|
120
|
+
*/
|
|
121
|
+
has(key: string): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Get keys.
|
|
124
|
+
*
|
|
125
|
+
* @returns {string[]} The object keys
|
|
126
|
+
*/
|
|
127
|
+
keys(): string[];
|
|
128
|
+
/**
|
|
129
|
+
* Get values.
|
|
130
|
+
*
|
|
131
|
+
* @returns {unknown[]} The object values
|
|
132
|
+
*/
|
|
133
|
+
values(): unknown[];
|
|
134
|
+
/**
|
|
135
|
+
* Clone the object.
|
|
136
|
+
*
|
|
137
|
+
* @returns {Objectable<T>} A new cloned Objectable instance
|
|
138
|
+
*/
|
|
139
|
+
clone(): Objectable<T>;
|
|
140
|
+
/**
|
|
141
|
+
* Pipe to a callback.
|
|
142
|
+
*
|
|
143
|
+
* @param {Function} callback The callback to execute
|
|
144
|
+
* @returns {U} The result of the callback
|
|
145
|
+
*/
|
|
146
|
+
pipe<U>(callback: (obj: this) => U): U;
|
|
147
|
+
/**
|
|
148
|
+
* Execute callback if condition is met.
|
|
149
|
+
*
|
|
150
|
+
* @param {boolean | Function} condition The condition to check
|
|
151
|
+
* @param {Function} callback The callback to execute
|
|
152
|
+
* @returns {this} The Objectable instance
|
|
153
|
+
*/
|
|
154
|
+
when(condition: boolean | (() => boolean), callback: (obj: this) => void): this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create a new fluent Objectable instance.
|
|
158
|
+
*
|
|
159
|
+
* @param {T} value The initial value
|
|
160
|
+
* @returns {Objectable<T>} A new Objectable instance
|
|
161
|
+
*/
|
|
162
|
+
declare const obj: <T extends Record<string, unknown>>(value: T) => Objectable<T>;
|
|
163
|
+
/**
|
|
164
|
+
* Static methods for object manipulation.
|
|
165
|
+
*/
|
|
166
|
+
declare const Obj: {
|
|
167
|
+
/** Create a new Objectable instance */
|
|
168
|
+
of: <T extends Record<string, unknown>>(value: T) => Objectable<T>;
|
|
169
|
+
/** Get object keys */
|
|
170
|
+
keys: (value: Record<string, unknown>) => string[];
|
|
171
|
+
/** Get object values */
|
|
172
|
+
values: (value: Record<string, unknown>) => unknown[];
|
|
173
|
+
/** Merge objects */
|
|
174
|
+
merge: (target: Record<string, unknown>, ...sources: Record<string, unknown>[]) => any;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export { Obj, Objectable, obj };
|