Skip to content

Commit

Permalink
refactor!: make clone more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jul 3, 2024
1 parent 2564381 commit a6d708e
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/object/clone.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
import { isPrimitive } from 'radashi'

/**
* Creates a shallow copy of the given obejct/value.
* @param {*} obj value to clone @returns {*} shallow clone of the
* given value
*/
export function clone<T>(obj: T): T {
// Primitive values do not need cloning.
if (isPrimitive(obj)) {
return obj
}

// Binding a function to an empty object creates a copy function.
if (typeof obj === 'function') {
return obj.bind({})
}

export function clone<T extends object>(obj: T): T {
const proto = Object.getPrototypeOf(obj)
const newObj =
typeof proto?.constructor === 'function'
Expand Down

0 comments on commit a6d708e

Please sign in to comment.