-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
129 additions
and
40 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2023. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
import { isObject } from './check'; | ||
|
||
/* istanbul ignore next */ | ||
const gT = (() => { | ||
if (typeof globalThis !== 'undefined') { | ||
return globalThis; | ||
} | ||
|
||
// eslint-disable-next-line no-restricted-globals | ||
if (typeof self !== 'undefined') { | ||
// eslint-disable-next-line no-restricted-globals | ||
return self; | ||
} | ||
|
||
if (typeof window !== 'undefined') { | ||
return window; | ||
} | ||
|
||
if (typeof global !== 'undefined') { | ||
return global; | ||
} | ||
|
||
throw new Error('unable to locate global object'); | ||
})(); | ||
|
||
export function clone<T>(value: T) : T { | ||
if (gT.structuredClone) { | ||
return gT.structuredClone(value); | ||
} | ||
|
||
if (isObject(value)) { | ||
return { ...value }; | ||
} | ||
|
||
if (Array.isArray(value)) { | ||
return [...value] as T; | ||
} | ||
|
||
return value; | ||
} |
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
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