Skip to content

Object

Default export ObjectUtils.

When to use

  • Debounce: input search/auto save
  • Throttle: scroll/resize high‑frequency events
  • Once: avoid double init
  • Sleep: await delays in async flow
  • Retry: transient network errors

Import

ts
import { ObjectUtils, debounce, throttle, once, sleep, retry } from 'nex-lib'

Debounce

ts
import { debounce } from 'nex-lib'
const run = debounce((q: string) => console.log('search:', q), 300)

Throttle

ts
import { ObjectUtils } from 'nex-lib'
const onScroll = ObjectUtils.throttle(() => console.log('scroll Y:', window.scrollY), 200)

Once

ts
const init = ObjectUtils.once(() => {/* 初始化只执行一次 */})
init(); init();

Sleep

ts
await ObjectUtils.sleep(500)

Retry

ts
await ObjectUtils.retry(async () => {/* 可能失败的异步操作 */}, 3, 200)

Others

  • deepMerge<T,S>(target, source)
  • deepEqual(obj1, obj2)
  • judgeTypes(target)
  • treeFilter(tree, func)
  • filterAndRecurse(arr, predicate)
  • keys(obj) / values(obj)
  • deepClone(obj)
  • groupBy(arr, keyOrFn)
  • uniqBy(arr, keyOrFn)

Released under the ISC License.