index.d.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export = Ids;
  2. declare class Ids {
  3. /**
  4. * Create a new id generator / cache instance.
  5. *
  6. * You may optionally provide a seed that is used internally.
  7. *
  8. * @param {Seed} [seed]
  9. */
  10. constructor(seed?: Seed);
  11. /**
  12. * Generate a next id.
  13. *
  14. * @param {Object} [element] element to bind the id to
  15. *
  16. * @return {String} id
  17. */
  18. public next(element?: any): ID;
  19. /**
  20. * Generate a next id with a given prefix.
  21. *
  22. * @param {Object} [element] element to bind the id to
  23. *
  24. * @return {String} id
  25. */
  26. public nextPrefixed(prefix: string, element?: any): ID;
  27. /**
  28. * Manually claim an existing id.
  29. *
  30. * @param {String} id
  31. * @param {String} [element] element the id is claimed by
  32. */
  33. public claim(id: ID, element?: any): void;
  34. /**
  35. * Returns true if the given id has already been assigned.
  36. *
  37. * @param {String} id
  38. * @return {Boolean}
  39. */
  40. public assigned(id: ID): boolean;
  41. /**
  42. * Unclaim an id.
  43. *
  44. * @param {String} id the id to unclaim
  45. */
  46. public unclaim(id: ID): void;
  47. /**
  48. * Clear all claimed ids.
  49. */
  50. public clear(): void;
  51. }
  52. type Seed = [number, number] | [number, number, number];
  53. type ID = string;