@digitalculture/ochre-sdk 0.4.13 → 0.4.15

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.
package/dist/index.cjs CHANGED
@@ -42,7 +42,7 @@ __export(index_exports, {
42
42
  parseContext: () => parseContext,
43
43
  parseCoordinates: () => parseCoordinates,
44
44
  parseDocument: () => parseDocument,
45
- parseEmailAndUrl: () => parseEmailAndUrl,
45
+ parseEmail: () => parseEmail,
46
46
  parseEvents: () => parseEvents,
47
47
  parseFakeString: () => parseFakeString,
48
48
  parseIdentification: () => parseIdentification,
@@ -125,21 +125,11 @@ var whitespaceSchema = import_zod2.z.string().transform((str) => str.split(" "))
125
125
  )
126
126
  );
127
127
  var emailSchema = import_zod2.z.string().email({ message: "Invalid email" });
128
- var urlSchema = import_zod2.z.string().refine((v) => v ? isUrlValid(v) : false, {
129
- message: "Invalid URL"
130
- });
131
- function isUrlValid(url) {
132
- const pattern = (
133
- // eslint-disable-next-line regexp/no-useless-quantifier, regexp/no-unused-capturing-group
134
- /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\w$&+,:;=-]+@)?[\d.A-Za-z-]+(:\d+)?|(?:www.|[\w$&+,:;=-]+@)[\d.A-Za-z-]+)((?:\/[\w%+./~-]*)?\??[\w%&+.;=@-]*#?\w*)?)/
135
- );
136
- return !!pattern.test(url);
137
- }
138
128
  function getStringItemByLanguage(content, language) {
139
129
  const stringItemToFind = content.find((item) => item.lang === language);
140
130
  return stringItemToFind ?? null;
141
131
  }
142
- function parseEmailAndUrl(string) {
132
+ function parseEmail(string) {
143
133
  const splitString = string.split(" ");
144
134
  const returnSplitString = [];
145
135
  for (const string2 of splitString) {
@@ -155,13 +145,6 @@ function parseEmailAndUrl(string) {
155
145
  );
156
146
  continue;
157
147
  }
158
- const isUrl = urlSchema.safeParse(cleanString).success;
159
- if (isUrl) {
160
- returnSplitString.push(
161
- `${before}<ExternalLink href="${cleanString}">${cleanString}</ExternalLink>${after}`
162
- );
163
- continue;
164
- }
165
148
  returnSplitString.push(string2);
166
149
  }
167
150
  return returnSplitString.join(" ");
@@ -265,7 +248,7 @@ function parseStringItem(item) {
265
248
  }
266
249
  function parseStringDocumentItem(item, footnotes) {
267
250
  if (typeof item === "string" || typeof item === "number" || typeof item === "boolean") {
268
- return parseEmailAndUrl(parseFakeString(item));
251
+ return parseEmail(parseFakeString(item));
269
252
  }
270
253
  if ("whitespace" in item && !("content" in item) && !("string" in item)) {
271
254
  if (item.whitespace === "newline") {
@@ -275,7 +258,12 @@ function parseStringDocumentItem(item, footnotes) {
275
258
  }
276
259
  }
277
260
  if ("links" in item) {
278
- const itemString = parseFakeString(item.string).replaceAll("<", String.raw`\<`).replaceAll("{", String.raw`\{`);
261
+ let itemString = "";
262
+ if (typeof item.string === "object") {
263
+ itemString = parseStringContent(item.string);
264
+ } else {
265
+ itemString = parseFakeString(item.string).replaceAll("<", String.raw`\<`).replaceAll("{", String.raw`\{`);
266
+ }
279
267
  const itemLinks = Array.isArray(item.links) ? item.links : [item.links];
280
268
  for (const link of itemLinks) {
281
269
  if ("resource" in link) {
@@ -366,25 +354,16 @@ function parseStringDocumentItem(item, footnotes) {
366
354
  returnString += parseStringDocumentItem(stringItem, footnotes);
367
355
  }
368
356
  if ("whitespace" in item && item.whitespace != null) {
369
- returnString = parseWhitespace(
370
- parseEmailAndUrl(returnString),
371
- item.whitespace
372
- );
357
+ returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
373
358
  }
374
359
  return returnString.replaceAll("&#39;", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
375
360
  } else {
376
361
  returnString = parseFakeString(item.content);
377
362
  if (item.rend != null) {
378
- returnString = parseRenderOptions(
379
- parseEmailAndUrl(returnString),
380
- item.rend
381
- );
363
+ returnString = parseRenderOptions(parseEmail(returnString), item.rend);
382
364
  }
383
365
  if (item.whitespace != null) {
384
- returnString = parseWhitespace(
385
- parseEmailAndUrl(returnString),
386
- item.whitespace
387
- );
366
+ returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
388
367
  }
389
368
  }
390
369
  return returnString.replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
@@ -781,9 +760,7 @@ function parseDocument(document, language = "eng") {
781
760
  const footnotes = [];
782
761
  const documentWithLanguage = Array.isArray(document) ? document.find((doc) => doc.lang === language) : document;
783
762
  if (typeof documentWithLanguage.string === "string" || typeof documentWithLanguage.string === "number" || typeof documentWithLanguage.string === "boolean") {
784
- returnString += parseEmailAndUrl(
785
- parseFakeString(documentWithLanguage.string)
786
- );
763
+ returnString += parseEmail(parseFakeString(documentWithLanguage.string));
787
764
  } else {
788
765
  const documentItems = Array.isArray(documentWithLanguage.string) ? documentWithLanguage.string : [documentWithLanguage.string];
789
766
  for (const item of documentItems) {
@@ -835,9 +812,9 @@ function parseNotes(notes, language = "eng") {
835
812
  }
836
813
  }
837
814
  if (typeof noteWithLanguage.string === "string" || typeof noteWithLanguage.string === "number" || typeof noteWithLanguage.string === "boolean") {
838
- content = parseEmailAndUrl(parseFakeString(noteWithLanguage.string));
815
+ content = parseEmail(parseFakeString(noteWithLanguage.string));
839
816
  } else {
840
- content = parseEmailAndUrl(parseDocument(noteWithLanguage).content);
817
+ content = parseEmail(parseDocument(noteWithLanguage).content);
841
818
  }
842
819
  returnNotes.push({
843
820
  number: note.noteNo,
@@ -2738,7 +2715,7 @@ async function fetchWebsite(abbreviation) {
2738
2715
  parseContext,
2739
2716
  parseCoordinates,
2740
2717
  parseDocument,
2741
- parseEmailAndUrl,
2718
+ parseEmail,
2742
2719
  parseEvents,
2743
2720
  parseFakeString,
2744
2721
  parseIdentification,
package/dist/index.d.cts CHANGED
@@ -751,7 +751,7 @@ type OchreStringRichTextItemContent = {
751
751
  */
752
752
  type OchreStringRichTextItemAnnotation = {
753
753
  annotation: string; // UUID
754
- string: FakeString;
754
+ string: FakeString | OchreStringRichTextItemContent;
755
755
  links: OchreLink | Array<OchreLink>;
756
756
  };
757
757
 
@@ -1796,19 +1796,18 @@ declare function parseConcepts(concepts: Array<OchreConcept> | Array<OchreNested
1796
1796
  declare function parseWebsite(websiteTree: OchreTree, projectName: FakeString, website: FakeString | null): Promise<Website>;
1797
1797
 
1798
1798
  /**
1799
- * Parses email addresses and URLs in a string into HTML links
1799
+ * Parses email addresses in a string into HTML links
1800
1800
  *
1801
1801
  * @param string - Input string to parse
1802
- * @returns String with emails and URLs converted to HTML links
1802
+ * @returns String with emails converted to HTML links
1803
1803
  *
1804
1804
  * @example
1805
1805
  * ```ts
1806
- * const parsed = parseEmailAndUrl("Contact us at info@example.com or visit www.example.com");
1807
- * // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>
1808
- * // or visit <ExternalLink href="www.example.com">www.example.com</ExternalLink>"
1806
+ * const parsed = parseEmail("Contact us at info@example.com");
1807
+ * // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>"
1809
1808
  * ```
1810
1809
  */
1811
- declare function parseEmailAndUrl(string: string): string;
1810
+ declare function parseEmail(string: string): string;
1812
1811
  /**
1813
1812
  * Converts a FakeString (string|number|boolean) to a proper string
1814
1813
  *
@@ -1847,4 +1846,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
1847
1846
  */
1848
1847
  declare function parseStringContent(content: OchreStringContent, language?: string): string;
1849
1848
 
1850
- export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmailAndUrl, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
1849
+ export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
package/dist/index.d.ts CHANGED
@@ -751,7 +751,7 @@ type OchreStringRichTextItemContent = {
751
751
  */
752
752
  type OchreStringRichTextItemAnnotation = {
753
753
  annotation: string; // UUID
754
- string: FakeString;
754
+ string: FakeString | OchreStringRichTextItemContent;
755
755
  links: OchreLink | Array<OchreLink>;
756
756
  };
757
757
 
@@ -1796,19 +1796,18 @@ declare function parseConcepts(concepts: Array<OchreConcept> | Array<OchreNested
1796
1796
  declare function parseWebsite(websiteTree: OchreTree, projectName: FakeString, website: FakeString | null): Promise<Website>;
1797
1797
 
1798
1798
  /**
1799
- * Parses email addresses and URLs in a string into HTML links
1799
+ * Parses email addresses in a string into HTML links
1800
1800
  *
1801
1801
  * @param string - Input string to parse
1802
- * @returns String with emails and URLs converted to HTML links
1802
+ * @returns String with emails converted to HTML links
1803
1803
  *
1804
1804
  * @example
1805
1805
  * ```ts
1806
- * const parsed = parseEmailAndUrl("Contact us at info@example.com or visit www.example.com");
1807
- * // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>
1808
- * // or visit <ExternalLink href="www.example.com">www.example.com</ExternalLink>"
1806
+ * const parsed = parseEmail("Contact us at info@example.com");
1807
+ * // Returns: "Contact us at <ExternalLink href="mailto:info@example.com">info@example.com</ExternalLink>"
1809
1808
  * ```
1810
1809
  */
1811
- declare function parseEmailAndUrl(string: string): string;
1810
+ declare function parseEmail(string: string): string;
1812
1811
  /**
1813
1812
  * Converts a FakeString (string|number|boolean) to a proper string
1814
1813
  *
@@ -1847,4 +1846,4 @@ declare function parseStringDocumentItem(item: OchreStringRichTextItem, footnote
1847
1846
  */
1848
1847
  declare function parseStringContent(content: OchreStringContent, language?: string): string;
1849
1848
 
1850
- export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmailAndUrl, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
1849
+ export { type Bibliography, type Concept, type Context, type ContextItem, type ContextNode, type Coordinates, type Data, type Document, type Event, type Footnote, type Gallery, type Identification, type Image, type ImageMap, type ImageMapArea, type Interpretation, type License, type Link, type Metadata, type NestedConcept, type NestedResource, type NestedSpatialUnit, type Note, type Observation, type Period, type Person, type Property, type PropertyValue, type PropertyValueType, type Resource, type Set, type SpatialUnit, type Style, type Tree, type WebBlock, type WebElement, type WebElementComponent, type WebImage, type Webpage, type WebpageProperties, type Website, type WebsiteProperties, fetchBibliography, fetchByUuid, fetchConcept, fetchGallery, fetchPeriod, fetchResource, fetchSet, fetchSpatialUnit, fetchTree, fetchWebsite, filterProperties, getAllPropertyLabels, getPropertyByLabel, getPropertyValueByLabel, getPropertyValuesByLabel, parseBibliographies, parseBibliography, parseConcept, parseConcepts, parseContext, parseCoordinates, parseDocument, parseEmail, parseEvents, parseFakeString, parseIdentification, parseImage, parseImageMap, parseInterpretations, parseLanguages, parseLicense, parseLink, parseLinks, parseMetadata, parseNotes, parseObservation, parseObservations, parsePeriod, parsePeriods, parsePerson, parsePersons, parseProperties, parseResource, parseResources, parseSet, parseSpatialUnit, parseSpatialUnits, parseStringContent, parseStringDocumentItem, parseStringItem, parseTree, parseWebsite };
package/dist/index.js CHANGED
@@ -48,21 +48,11 @@ var whitespaceSchema = z2.string().transform((str) => str.split(" ")).pipe(
48
48
  )
49
49
  );
50
50
  var emailSchema = z2.string().email({ message: "Invalid email" });
51
- var urlSchema = z2.string().refine((v) => v ? isUrlValid(v) : false, {
52
- message: "Invalid URL"
53
- });
54
- function isUrlValid(url) {
55
- const pattern = (
56
- // eslint-disable-next-line regexp/no-useless-quantifier, regexp/no-unused-capturing-group
57
- /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\w$&+,:;=-]+@)?[\d.A-Za-z-]+(:\d+)?|(?:www.|[\w$&+,:;=-]+@)[\d.A-Za-z-]+)((?:\/[\w%+./~-]*)?\??[\w%&+.;=@-]*#?\w*)?)/
58
- );
59
- return !!pattern.test(url);
60
- }
61
51
  function getStringItemByLanguage(content, language) {
62
52
  const stringItemToFind = content.find((item) => item.lang === language);
63
53
  return stringItemToFind ?? null;
64
54
  }
65
- function parseEmailAndUrl(string) {
55
+ function parseEmail(string) {
66
56
  const splitString = string.split(" ");
67
57
  const returnSplitString = [];
68
58
  for (const string2 of splitString) {
@@ -78,13 +68,6 @@ function parseEmailAndUrl(string) {
78
68
  );
79
69
  continue;
80
70
  }
81
- const isUrl = urlSchema.safeParse(cleanString).success;
82
- if (isUrl) {
83
- returnSplitString.push(
84
- `${before}<ExternalLink href="${cleanString}">${cleanString}</ExternalLink>${after}`
85
- );
86
- continue;
87
- }
88
71
  returnSplitString.push(string2);
89
72
  }
90
73
  return returnSplitString.join(" ");
@@ -188,7 +171,7 @@ function parseStringItem(item) {
188
171
  }
189
172
  function parseStringDocumentItem(item, footnotes) {
190
173
  if (typeof item === "string" || typeof item === "number" || typeof item === "boolean") {
191
- return parseEmailAndUrl(parseFakeString(item));
174
+ return parseEmail(parseFakeString(item));
192
175
  }
193
176
  if ("whitespace" in item && !("content" in item) && !("string" in item)) {
194
177
  if (item.whitespace === "newline") {
@@ -198,7 +181,12 @@ function parseStringDocumentItem(item, footnotes) {
198
181
  }
199
182
  }
200
183
  if ("links" in item) {
201
- const itemString = parseFakeString(item.string).replaceAll("<", String.raw`\<`).replaceAll("{", String.raw`\{`);
184
+ let itemString = "";
185
+ if (typeof item.string === "object") {
186
+ itemString = parseStringContent(item.string);
187
+ } else {
188
+ itemString = parseFakeString(item.string).replaceAll("<", String.raw`\<`).replaceAll("{", String.raw`\{`);
189
+ }
202
190
  const itemLinks = Array.isArray(item.links) ? item.links : [item.links];
203
191
  for (const link of itemLinks) {
204
192
  if ("resource" in link) {
@@ -289,25 +277,16 @@ function parseStringDocumentItem(item, footnotes) {
289
277
  returnString += parseStringDocumentItem(stringItem, footnotes);
290
278
  }
291
279
  if ("whitespace" in item && item.whitespace != null) {
292
- returnString = parseWhitespace(
293
- parseEmailAndUrl(returnString),
294
- item.whitespace
295
- );
280
+ returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
296
281
  }
297
282
  return returnString.replaceAll("&#39;", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
298
283
  } else {
299
284
  returnString = parseFakeString(item.content);
300
285
  if (item.rend != null) {
301
- returnString = parseRenderOptions(
302
- parseEmailAndUrl(returnString),
303
- item.rend
304
- );
286
+ returnString = parseRenderOptions(parseEmail(returnString), item.rend);
305
287
  }
306
288
  if (item.whitespace != null) {
307
- returnString = parseWhitespace(
308
- parseEmailAndUrl(returnString),
309
- item.whitespace
310
- );
289
+ returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
311
290
  }
312
291
  }
313
292
  return returnString.replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
@@ -704,9 +683,7 @@ function parseDocument(document, language = "eng") {
704
683
  const footnotes = [];
705
684
  const documentWithLanguage = Array.isArray(document) ? document.find((doc) => doc.lang === language) : document;
706
685
  if (typeof documentWithLanguage.string === "string" || typeof documentWithLanguage.string === "number" || typeof documentWithLanguage.string === "boolean") {
707
- returnString += parseEmailAndUrl(
708
- parseFakeString(documentWithLanguage.string)
709
- );
686
+ returnString += parseEmail(parseFakeString(documentWithLanguage.string));
710
687
  } else {
711
688
  const documentItems = Array.isArray(documentWithLanguage.string) ? documentWithLanguage.string : [documentWithLanguage.string];
712
689
  for (const item of documentItems) {
@@ -758,9 +735,9 @@ function parseNotes(notes, language = "eng") {
758
735
  }
759
736
  }
760
737
  if (typeof noteWithLanguage.string === "string" || typeof noteWithLanguage.string === "number" || typeof noteWithLanguage.string === "boolean") {
761
- content = parseEmailAndUrl(parseFakeString(noteWithLanguage.string));
738
+ content = parseEmail(parseFakeString(noteWithLanguage.string));
762
739
  } else {
763
- content = parseEmailAndUrl(parseDocument(noteWithLanguage).content);
740
+ content = parseEmail(parseDocument(noteWithLanguage).content);
764
741
  }
765
742
  returnNotes.push({
766
743
  number: note.noteNo,
@@ -2660,7 +2637,7 @@ export {
2660
2637
  parseContext,
2661
2638
  parseCoordinates,
2662
2639
  parseDocument,
2663
- parseEmailAndUrl,
2640
+ parseEmail,
2664
2641
  parseEvents,
2665
2642
  parseFakeString,
2666
2643
  parseIdentification,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalculture/ochre-sdk",
3
- "version": "0.4.13",
3
+ "version": "0.4.15",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",