story.d.ts 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Passage } from "./passage";
  2. export interface StoryAPI {
  3. /**
  4. * The DOM ID of the story (created from the slugified story title).
  5. * @since 2.0.0
  6. */
  7. readonly domId: string;
  8. /**
  9. * The title of the story.
  10. * @since 2.0.0
  11. */
  12. readonly title: string;
  13. /**
  14. * Returns the Passage object referenced by the given title, or an empty Passage object on failure.
  15. * @param passageTitle The title of the Passage object to return.
  16. * @since 2.0.0
  17. */
  18. get(passageTitle: string): Passage;
  19. /**
  20. * Returns whether a Passage object referenced by the given title exists.
  21. * @param passageTitle The title of the Passage object whose existence will be verified.
  22. * @since 2.0.0
  23. */
  24. has(passageTitle: string): boolean;
  25. /**
  26. * Returns an array of Passage objects each of which must contain a property matching the given name,
  27. * whose value matches the given needle, or an empty array, if no matches are made.
  28. * @param propertyName The name of property whose value will be compared to the search value.
  29. * @param searchValue he value to search for within the matched property. The type of the property determines
  30. * how the search occurs; direct comparison for non-arrays, while arrays are iterated over. If the property
  31. * value, for non-arrays, or any of the property members' values, for arrays, match, then the Passage object
  32. * is added to the results array.
  33. * @param sortProperty The property whose value will be used to lexicographically sort the returned array.
  34. * If not given, the Passage object's title property is used.
  35. * @since 2.0.0
  36. * @example
  37. * // Returns all 'forest'-tagged Passage objects, sorted by their titles
  38. * Story.lookup("tags", "forest");
  39. */
  40. lookup(propertyName: string, searchValue: string | number, sortProperty?: string): Passage[];
  41. /**
  42. * Returns an array of Passage objects which passed the test implemented by the given filter function or
  43. * an empty array, if no objects pass.
  44. * @param filter The function used to test each Passage object, which is passed in as its sole parameter.
  45. * If the function returns true, then the Passage object is added to the results array.
  46. * @param sortProperty The property whose value will be used to lexicographically sort the returned array.
  47. * If not given, the Passage object's title property is used.
  48. * @since 2.11.0
  49. */
  50. lookupWith(filter: (p: Passage) => boolean, sortProperty?: string): Passage[];
  51. }
  52. export {};