-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(traverse): visitor can return a leave callback
- Loading branch information
1 parent
94bb8fe
commit 592d088
Showing
3 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { traverse, TraverseContext } from 'radashi' | ||
|
||
export function cloneDeep<T extends object>( | ||
root: T, | ||
map: (obj: object, context: TraverseContext) => object, | ||
filter: (obj: object, context: TraverseContext) => boolean = () => true, | ||
): T { | ||
const out = map(root) | ||
traverse(root, (value, key, parent, context) => { | ||
if (value && typeof value === 'object') { | ||
} | ||
}) | ||
} | ||
|
||
const complexTypes = [ | ||
Map, | ||
Set, | ||
Date, | ||
RegExp, | ||
Error, | ||
WeakMap, | ||
WeakSet, | ||
ArrayBuffer, | ||
SharedArrayBuffer, | ||
DataView, | ||
Int8Array, | ||
Uint8Array, | ||
Uint8ClampedArray, | ||
Int16Array, | ||
Uint16Array, | ||
Int32Array, | ||
Uint32Array, | ||
Float32Array, | ||
Float64Array, | ||
BigInt64Array, | ||
BigUint64Array, | ||
Promise, | ||
// Boxed primitive types | ||
String, | ||
Number, | ||
Boolean, | ||
] | ||
|
||
function isInstance( | ||
obj: object, | ||
constructors: (new (...args: any[]) => any)[], | ||
) { | ||
return constructors.some(constructor => obj instanceof constructor) | ||
} | ||
|
||
function isComplexObject(obj: object) { | ||
return isInstance(obj, complexTypes) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters