@helloao/tools 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/cjs/generation/api.cjs +856 -36
  2. package/dist/cjs/generation/api.cjs.map +3 -3
  3. package/dist/cjs/generation/audio.cjs +5 -5
  4. package/dist/cjs/generation/audio.cjs.map +1 -1
  5. package/dist/cjs/generation/book-order.cjs.map +1 -1
  6. package/dist/cjs/generation/common-types.cjs +359 -14
  7. package/dist/cjs/generation/common-types.cjs.map +2 -2
  8. package/dist/cjs/generation/dataset.cjs +13 -9
  9. package/dist/cjs/generation/dataset.cjs.map +2 -2
  10. package/dist/cjs/generation/index.cjs +8 -5
  11. package/dist/cjs/generation/index.cjs.map +2 -2
  12. package/dist/cjs/generation/simple.cjs +294 -0
  13. package/dist/cjs/generation/simple.cjs.map +7 -0
  14. package/dist/cjs/index.cjs +4 -4
  15. package/dist/cjs/index.cjs.map +1 -1
  16. package/dist/cjs/log.cjs.map +1 -1
  17. package/dist/cjs/parser/codex-parser.cjs +3 -3
  18. package/dist/cjs/parser/codex-parser.cjs.map +3 -3
  19. package/dist/cjs/parser/commentary-csv-parser.cjs +14 -3
  20. package/dist/cjs/parser/commentary-csv-parser.cjs.map +3 -3
  21. package/dist/cjs/parser/index.cjs +1 -1
  22. package/dist/cjs/parser/iterators.cjs.map +1 -1
  23. package/dist/cjs/parser/lockman-parser.cjs +1 -1
  24. package/dist/cjs/parser/lockman-parser.cjs.map +1 -1
  25. package/dist/cjs/parser/tyndale-xml-parser.cjs +1 -1
  26. package/dist/cjs/parser/tyndale-xml-parser.cjs.map +1 -1
  27. package/dist/cjs/parser/types.cjs.map +1 -1
  28. package/dist/cjs/parser/usfm-parser.cjs +2 -2
  29. package/dist/cjs/parser/usfm-parser.cjs.map +1 -1
  30. package/dist/cjs/parser/usx-parser.cjs +122 -26
  31. package/dist/cjs/parser/usx-parser.cjs.map +2 -2
  32. package/dist/cjs/parser/words.cjs +187 -0
  33. package/dist/cjs/parser/words.cjs.map +7 -0
  34. package/dist/cjs/utils.cjs +1 -1
  35. package/dist/esm/generation/api.js +835 -37
  36. package/dist/esm/generation/api.js.map +3 -3
  37. package/dist/esm/generation/audio.js +1 -1
  38. package/dist/esm/generation/audio.js.map +1 -1
  39. package/dist/esm/generation/book-order.js.map +1 -1
  40. package/dist/esm/generation/common-types.js +327 -14
  41. package/dist/esm/generation/common-types.js.map +2 -2
  42. package/dist/esm/generation/dataset.js +6 -2
  43. package/dist/esm/generation/dataset.js.map +2 -2
  44. package/dist/esm/generation/index.js +2 -1
  45. package/dist/esm/generation/index.js.map +2 -2
  46. package/dist/esm/generation/simple.js +260 -0
  47. package/dist/esm/generation/simple.js.map +7 -0
  48. package/dist/esm/index.js.map +1 -1
  49. package/dist/esm/log.js.map +1 -1
  50. package/dist/esm/parser/codex-parser.js +3 -3
  51. package/dist/esm/parser/codex-parser.js.map +3 -3
  52. package/dist/esm/parser/commentary-csv-parser.js +3 -2
  53. package/dist/esm/parser/commentary-csv-parser.js.map +2 -2
  54. package/dist/esm/parser/iterators.js.map +1 -1
  55. package/dist/esm/parser/lockman-parser.js +1 -1
  56. package/dist/esm/parser/lockman-parser.js.map +1 -1
  57. package/dist/esm/parser/tyndale-xml-parser.js +1 -1
  58. package/dist/esm/parser/tyndale-xml-parser.js.map +1 -1
  59. package/dist/esm/parser/usfm-parser.js +1 -1
  60. package/dist/esm/parser/usfm-parser.js.map +1 -1
  61. package/dist/esm/parser/usx-parser.js +130 -26
  62. package/dist/esm/parser/usx-parser.js.map +2 -2
  63. package/dist/esm/parser/words.js +149 -0
  64. package/dist/esm/parser/words.js.map +7 -0
  65. package/dist/types/generation/api.d.ts +6879 -918
  66. package/dist/types/generation/common-types.d.ts +432 -2
  67. package/dist/types/generation/index.d.ts +2 -1
  68. package/dist/types/generation/simple.d.ts +110 -0
  69. package/dist/types/parser/commentary-csv-parser.d.ts +1 -1
  70. package/dist/types/parser/lockman-parser.d.ts +1 -1
  71. package/dist/types/parser/tyndale-xml-parser.d.ts +1 -1
  72. package/dist/types/parser/types.d.ts +63 -0
  73. package/dist/types/parser/usx-parser.d.ts +6 -5
  74. package/dist/types/parser/words.d.ts +104 -0
  75. package/package.json +3 -2
@@ -1,10 +1,11 @@
1
1
  import { Chapter, ChapterContent, FootnoteReference, ParseTree, Verse, Text, HebrewSubtitle, InlineLineBreak } from './types.js';
2
2
  import { RewindableIterator } from './iterators.js';
3
+ import { AnnotatedContent } from './words.js';
3
4
  /**
4
5
  * The version of the parser.
5
6
  * Used to determine whether input files need to be re-parsed.
6
7
  */
7
- export declare const PARSER_VERSION = 3;
8
+ export declare const PARSER_VERSION = 4;
8
9
  /**
9
10
  * Defines a class that is able to parse USX content.
10
11
  */
@@ -25,13 +26,13 @@ export declare class USXParser {
25
26
  parse(usx: string): ParseTree;
26
27
  iterateRootContent(usxElement: Element): Generator<ParseTree['content'][0]>;
27
28
  iterateChapterContent(chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<ChapterContent>;
28
- iterateVerseContent(chapter: Chapter, verse: Verse, nodes: RewindableIterator<Node>, previousVerse?: Verse | null): IterableIterator<string | FootnoteReference | Text | InlineLineBreak>;
29
+ iterateVerseContent(chapter: Chapter, verse: Verse, nodes: RewindableIterator<Node>, previousVerse?: Verse | null): IterableIterator<string | FootnoteReference | Text | InlineLineBreak | AnnotatedContent<string | Text>>;
29
30
  parseVerse(element: Element, chapter: Chapter, nodes: RewindableIterator<Node>): Verse;
30
31
  parseHebrewSubtitle(para: Element, chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<HebrewSubtitle | Verse>;
31
- iterateHebrewSubtitleContent(element: Element, chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<Verse | string | Text | FootnoteReference | InlineLineBreak>;
32
- iterateNodeTextContent(nodes: RewindableIterator<Node>, node: Node, chapter: Chapter, verse?: Verse): IterableIterator<string | Text | FootnoteReference | InlineLineBreak>;
32
+ iterateHebrewSubtitleContent(element: Element, chapter: Chapter, nodes: RewindableIterator<Node>): IterableIterator<Verse | string | Text | FootnoteReference | InlineLineBreak | AnnotatedContent<string | Text>>;
33
+ iterateNodeTextContent(nodes: RewindableIterator<Node>, node: Node, chapter: Chapter, verse?: Verse): IterableIterator<string | Text | FootnoteReference | InlineLineBreak | AnnotatedContent<string | Text>>;
33
34
  iterateCharContent(char: Element): IterableIterator<string | Text>;
34
35
  iterateNote(nodes: RewindableIterator<Node>, node: Element, chapter: Chapter, verse?: Verse): IterableIterator<FootnoteReference>;
35
- iterateChar(nodes: RewindableIterator<Node>, node: Element): IterableIterator<string | Text>;
36
+ iterateChar(nodes: RewindableIterator<Node>, node: Element): IterableIterator<string | Text | AnnotatedContent<string | Text>>;
36
37
  }
37
38
  //# sourceMappingURL=usx-parser.d.ts.map
@@ -0,0 +1,104 @@
1
+ import { Chapter, ChapterWord } from './types.js';
2
+ /**
3
+ * The annotations that a source associated with a word, without any information
4
+ * about where the word is located.
5
+ */
6
+ export type WordAnnotations = Omit<ChapterWord, 'contentIndex' | 'start' | 'end'>;
7
+ /**
8
+ * Defines an interface that represents a range of characters within a single
9
+ * piece of text, along with the annotations that apply to it.
10
+ */
11
+ export interface WordRange {
12
+ /**
13
+ * The index of the first character of the word.
14
+ */
15
+ start: number;
16
+ /**
17
+ * The index after the last character of the word.
18
+ */
19
+ end: number;
20
+ /**
21
+ * The annotations that apply to the word.
22
+ */
23
+ annotations: WordAnnotations;
24
+ }
25
+ /**
26
+ * Defines an interface that pairs a piece of verse content with the word
27
+ * annotations that apply to it, so that the annotations can be passed along
28
+ * with the content while it is being parsed.
29
+ *
30
+ * The ranges are relative to the text of the content, and are never included in
31
+ * the final parse tree.
32
+ */
33
+ export interface AnnotatedContent<T> {
34
+ /**
35
+ * The content that the annotations apply to.
36
+ */
37
+ annotatedContent: T;
38
+ /**
39
+ * The ranges of the content that are annotated.
40
+ */
41
+ words: WordRange[];
42
+ }
43
+ /**
44
+ * Determines whether the given value is content that has word annotations
45
+ * attached to it.
46
+ * @param value The value to test.
47
+ */
48
+ export declare function isAnnotatedContent(value: unknown): value is AnnotatedContent<unknown>;
49
+ /**
50
+ * Reads the word annotations that are attached to the given element.
51
+ * Returns null if the element doesn't have any recognized annotations.
52
+ * @param element The element to read the annotations from.
53
+ */
54
+ export declare function readWordAnnotations(element: Element): WordAnnotations | null;
55
+ /**
56
+ * Shrinks the given range so that it doesn't include any leading or trailing
57
+ * whitespace. Returns null if the range only contains whitespace.
58
+ * @param text The text that the range is in.
59
+ * @param start The index of the first character of the range.
60
+ * @param end The index after the last character of the range.
61
+ */
62
+ export declare function trimWordRange(text: string, start: number, end: number): {
63
+ start: number;
64
+ end: number;
65
+ } | null;
66
+ /**
67
+ * Collapses the whitespace in the given text in the same manner that the
68
+ * parsers normalize text (each run of whitespace becomes a single space, and the
69
+ * result is trimmed), and returns a map from the indexes in the given text to
70
+ * the indexes in the returned text.
71
+ *
72
+ * The map contains an entry for every index in the given text, plus one for the
73
+ * index just past the end of it, so that both ends of a range can be mapped.
74
+ * @param text The text to collapse.
75
+ */
76
+ export declare function collapseWhitespaceMap(text: string): {
77
+ text: string;
78
+ map: number[];
79
+ };
80
+ /**
81
+ * Moves the words that apply to the given content item to the indexes that they
82
+ * have after the item's text was collapsed with collapseWhitespaceMap().
83
+ * Words that no longer cover any characters are removed.
84
+ * @param words The words to remap.
85
+ * @param contentIndex The index of the content item that was collapsed.
86
+ * @param map The index map that collapseWhitespaceMap() returned.
87
+ */
88
+ export declare function remapChapterWords(words: ChapterWord[], contentIndex: number, map: number[]): void;
89
+ /**
90
+ * Removes the words that apply to the given content item, and moves the words
91
+ * that apply to later items back by one to account for the item being removed.
92
+ * @param words The words to update.
93
+ * @param contentIndex The index of the content item that was removed.
94
+ */
95
+ export declare function removeChapterWordsForContent(words: ChapterWord[], contentIndex: number): void;
96
+ /**
97
+ * Adds the given words to the chapter for the given verse number.
98
+ * Does nothing if there are no words.
99
+ * @param chapter The chapter to add the words to.
100
+ * @param verseNumber The number of the verse that the words are in.
101
+ * @param words The words to add.
102
+ */
103
+ export declare function addChapterWords(chapter: Chapter, verseNumber: number, words: ChapterWord[]): void;
104
+ //# sourceMappingURL=words.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@helloao/tools",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A set of tools for managing HelloAO's Free Bible API",
5
+ "type": "module",
5
6
  "main": "./dist/cjs/index.cjs",
6
7
  "module": "./dist/esm/index.js",
7
8
  "exports": {
@@ -49,7 +50,7 @@
49
50
  "author": "Kallyn Gowdy <kal@helloao.org>",
50
51
  "license": "MIT",
51
52
  "dependencies": {
52
- "lodash": "4.17.21",
53
+ "es-toolkit": "1.46.1",
53
54
  "zod": "^4.4.3",
54
55
  "papaparse": "5.4.1"
55
56
  },