id.ts 446 B

12345678910111213141516171819
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. let _idx = 0;
  6. export type LocalId = number;
  7. export function generateLocalId(): LocalId {
  8. // @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
  9. if (_idx === Number.MAX_SAFE_INTEGER) {
  10. _idx = 0;
  11. }
  12. return _idx++;
  13. }
  14. export function _setIdx(idx: number): void {
  15. _idx = idx;
  16. }