Skip to content

Commit

Permalink
feat(utils): 新增getGlobalThis方法
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Dec 3, 2024
1 parent 29a9670 commit da12ef9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ module.exports = {
[
"^(assert|buffer|child_process|cluster|console|constants|crypto|dgram|dns|domain|events|fs|http|https|module|net|os|path|punycode|querystring|readline|repl|stream|string_decoder|sys|timers|tls|tty|url|util|vm|zlib|freelist|v8|process|async_hooks|http2|perf_hooks)(/.*|$)",
],
["^(node)(:.*|$)"],
// Packages. `react|vue` related packages come first.
["^(react|vue|vite)", "^@?\\w"],
["^(@tmagic)(/.*|$)"],
Expand Down
18 changes: 18 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
Expand Down Expand Up @@ -36,6 +37,23 @@ import type { EditorNodeInfo } from '@editor/type';

export * from './dom';

// for typeof global checks without @types/node
declare let global: {};

let _globalThis: any;
export const getGlobalThis = (): any =>
_globalThis ||
(_globalThis =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {});

export const sleep = (ms: number): Promise<void> =>
new Promise((resolve) => {
const timer = setTimeout(() => {
Expand Down

0 comments on commit da12ef9

Please sign in to comment.