@revolugo/common 6.10.5-beta.0 → 6.10.5-beta.10
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/package.json
CHANGED
|
@@ -124,3 +124,43 @@ export function omitBy<T extends object>(
|
|
|
124
124
|
|
|
125
125
|
return result
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Creates a shallow clone of `object` excluding the given own enumerable keys.
|
|
130
|
+
* Accepts a single key or an array of keys. Symbol keys are supported.
|
|
131
|
+
* If `object` is nullish, returns an empty object.
|
|
132
|
+
*/
|
|
133
|
+
export function omit<T extends object, K extends keyof T>(
|
|
134
|
+
object: T | null | undefined,
|
|
135
|
+
keys: readonly K[] | K,
|
|
136
|
+
): Omit<T, K> {
|
|
137
|
+
if (object === null || object === undefined) {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
+
return {} as any
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const keysArray = (
|
|
143
|
+
Array.isArray(keys) ? keys : [keys]
|
|
144
|
+
) as readonly (keyof T)[]
|
|
145
|
+
const keysSet = new Set<keyof T>(keysArray as (keyof T)[])
|
|
146
|
+
|
|
147
|
+
const result: Partial<T> = {}
|
|
148
|
+
|
|
149
|
+
// Copy string/number keys
|
|
150
|
+
for (const key in object) {
|
|
151
|
+
if (Object.hasOwn(object, key) && !keysSet.has(key as keyof T)) {
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
+
;(result as any)[key] = object[key as keyof T]
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Copy symbol keys
|
|
158
|
+
for (const sym of Object.getOwnPropertySymbols(object)) {
|
|
159
|
+
if (!keysSet.has(sym as keyof T)) {
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
161
|
+
;(result as any)[sym as unknown as keyof T] = (object as any)[sym]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return result as Omit<T, K>
|
|
166
|
+
}
|