parent
f9591c5216
commit
306c371aef
@ -0,0 +1,18 @@
|
||||
export function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
||||
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
|
||||
const proto = Object.getPrototypeOf(value)
|
||||
return proto === Object.prototype || proto === null
|
||||
}
|
||||
|
||||
export function hasOwn<T extends object>(value: T, key: PropertyKey): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(value, key)
|
||||
}
|
||||
|
||||
export function toKebab(value: string): string {
|
||||
return value.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
|
||||
}
|
||||
|
||||
export function clonePlain<T>(value: T): T {
|
||||
if (typeof structuredClone === 'function') return structuredClone(value)
|
||||
return JSON.parse(JSON.stringify(value)) as T
|
||||
}
|
||||
Loading…
Reference in new issue