index.d.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export class Sorter<T> {
  2. /**
  3. * An array of the topologically sorted nodes. This list is renewed upon each call to topo.add().
  4. */
  5. nodes: T[];
  6. /**
  7. * Adds a node or list of nodes to be added and topologically sorted
  8. *
  9. * @param nodes - A mixed value or array of mixed values to be added as nodes to the topologically sorted list.
  10. * @param options - Optional sorting information about the nodes.
  11. *
  12. * @returns Returns an array of the topologically sorted nodes.
  13. */
  14. add(nodes: T | T[], options?: Options): T[];
  15. /**
  16. * Merges another Sorter object into the current object.
  17. *
  18. * @param others - The other object or array of objects to be merged into the current one.
  19. *
  20. * @returns Returns an array of the topologically sorted nodes.
  21. */
  22. merge(others: Sorter<T> | Sorter<T>[]): T[];
  23. /**
  24. * Sorts the nodes array (only required if the manual option is used when adding items)
  25. */
  26. sort(): T[];
  27. }
  28. export interface Options {
  29. /**
  30. * The sorting group the added items belong to
  31. */
  32. readonly group?: string;
  33. /**
  34. * The group or groups the added items must come before
  35. */
  36. readonly before?: string | string[];
  37. /**
  38. * The group or groups the added items must come after
  39. */
  40. readonly after?: string | string[];
  41. /**
  42. * A number used to sort items with equal before/after requirements
  43. */
  44. readonly sort?: number;
  45. /**
  46. * If true, the array is not sorted automatically until sort() is called
  47. */
  48. readonly manual?: boolean;
  49. }