@digitalculture/ochre-sdk 0.4.14 → 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 +10 -38
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +9 -37
- package/package.json +1 -1
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
|
-
|
|
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
|
|
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
|
|
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") {
|
|
@@ -371,25 +354,16 @@ function parseStringDocumentItem(item, footnotes) {
|
|
|
371
354
|
returnString += parseStringDocumentItem(stringItem, footnotes);
|
|
372
355
|
}
|
|
373
356
|
if ("whitespace" in item && item.whitespace != null) {
|
|
374
|
-
returnString = parseWhitespace(
|
|
375
|
-
parseEmailAndUrl(returnString),
|
|
376
|
-
item.whitespace
|
|
377
|
-
);
|
|
357
|
+
returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
|
|
378
358
|
}
|
|
379
359
|
return returnString.replaceAll("'", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
380
360
|
} else {
|
|
381
361
|
returnString = parseFakeString(item.content);
|
|
382
362
|
if (item.rend != null) {
|
|
383
|
-
returnString = parseRenderOptions(
|
|
384
|
-
parseEmailAndUrl(returnString),
|
|
385
|
-
item.rend
|
|
386
|
-
);
|
|
363
|
+
returnString = parseRenderOptions(parseEmail(returnString), item.rend);
|
|
387
364
|
}
|
|
388
365
|
if (item.whitespace != null) {
|
|
389
|
-
returnString = parseWhitespace(
|
|
390
|
-
parseEmailAndUrl(returnString),
|
|
391
|
-
item.whitespace
|
|
392
|
-
);
|
|
366
|
+
returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
|
|
393
367
|
}
|
|
394
368
|
}
|
|
395
369
|
return returnString.replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
@@ -786,9 +760,7 @@ function parseDocument(document, language = "eng") {
|
|
|
786
760
|
const footnotes = [];
|
|
787
761
|
const documentWithLanguage = Array.isArray(document) ? document.find((doc) => doc.lang === language) : document;
|
|
788
762
|
if (typeof documentWithLanguage.string === "string" || typeof documentWithLanguage.string === "number" || typeof documentWithLanguage.string === "boolean") {
|
|
789
|
-
returnString +=
|
|
790
|
-
parseFakeString(documentWithLanguage.string)
|
|
791
|
-
);
|
|
763
|
+
returnString += parseEmail(parseFakeString(documentWithLanguage.string));
|
|
792
764
|
} else {
|
|
793
765
|
const documentItems = Array.isArray(documentWithLanguage.string) ? documentWithLanguage.string : [documentWithLanguage.string];
|
|
794
766
|
for (const item of documentItems) {
|
|
@@ -840,9 +812,9 @@ function parseNotes(notes, language = "eng") {
|
|
|
840
812
|
}
|
|
841
813
|
}
|
|
842
814
|
if (typeof noteWithLanguage.string === "string" || typeof noteWithLanguage.string === "number" || typeof noteWithLanguage.string === "boolean") {
|
|
843
|
-
content =
|
|
815
|
+
content = parseEmail(parseFakeString(noteWithLanguage.string));
|
|
844
816
|
} else {
|
|
845
|
-
content =
|
|
817
|
+
content = parseEmail(parseDocument(noteWithLanguage).content);
|
|
846
818
|
}
|
|
847
819
|
returnNotes.push({
|
|
848
820
|
number: note.noteNo,
|
|
@@ -2743,7 +2715,7 @@ async function fetchWebsite(abbreviation) {
|
|
|
2743
2715
|
parseContext,
|
|
2744
2716
|
parseCoordinates,
|
|
2745
2717
|
parseDocument,
|
|
2746
|
-
|
|
2718
|
+
parseEmail,
|
|
2747
2719
|
parseEvents,
|
|
2748
2720
|
parseFakeString,
|
|
2749
2721
|
parseIdentification,
|
package/dist/index.d.cts
CHANGED
|
@@ -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
|
|
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
|
|
1802
|
+
* @returns String with emails converted to HTML links
|
|
1803
1803
|
*
|
|
1804
1804
|
* @example
|
|
1805
1805
|
* ```ts
|
|
1806
|
-
* const parsed =
|
|
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
|
|
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,
|
|
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
|
@@ -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
|
|
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
|
|
1802
|
+
* @returns String with emails converted to HTML links
|
|
1803
1803
|
*
|
|
1804
1804
|
* @example
|
|
1805
1805
|
* ```ts
|
|
1806
|
-
* const parsed =
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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") {
|
|
@@ -294,25 +277,16 @@ function parseStringDocumentItem(item, footnotes) {
|
|
|
294
277
|
returnString += parseStringDocumentItem(stringItem, footnotes);
|
|
295
278
|
}
|
|
296
279
|
if ("whitespace" in item && item.whitespace != null) {
|
|
297
|
-
returnString = parseWhitespace(
|
|
298
|
-
parseEmailAndUrl(returnString),
|
|
299
|
-
item.whitespace
|
|
300
|
-
);
|
|
280
|
+
returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
|
|
301
281
|
}
|
|
302
282
|
return returnString.replaceAll("'", "'").replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
303
283
|
} else {
|
|
304
284
|
returnString = parseFakeString(item.content);
|
|
305
285
|
if (item.rend != null) {
|
|
306
|
-
returnString = parseRenderOptions(
|
|
307
|
-
parseEmailAndUrl(returnString),
|
|
308
|
-
item.rend
|
|
309
|
-
);
|
|
286
|
+
returnString = parseRenderOptions(parseEmail(returnString), item.rend);
|
|
310
287
|
}
|
|
311
288
|
if (item.whitespace != null) {
|
|
312
|
-
returnString = parseWhitespace(
|
|
313
|
-
parseEmailAndUrl(returnString),
|
|
314
|
-
item.whitespace
|
|
315
|
-
);
|
|
289
|
+
returnString = parseWhitespace(parseEmail(returnString), item.whitespace);
|
|
316
290
|
}
|
|
317
291
|
}
|
|
318
292
|
return returnString.replaceAll(/^(\d+)\./gm, String.raw`$1\.`);
|
|
@@ -709,9 +683,7 @@ function parseDocument(document, language = "eng") {
|
|
|
709
683
|
const footnotes = [];
|
|
710
684
|
const documentWithLanguage = Array.isArray(document) ? document.find((doc) => doc.lang === language) : document;
|
|
711
685
|
if (typeof documentWithLanguage.string === "string" || typeof documentWithLanguage.string === "number" || typeof documentWithLanguage.string === "boolean") {
|
|
712
|
-
returnString +=
|
|
713
|
-
parseFakeString(documentWithLanguage.string)
|
|
714
|
-
);
|
|
686
|
+
returnString += parseEmail(parseFakeString(documentWithLanguage.string));
|
|
715
687
|
} else {
|
|
716
688
|
const documentItems = Array.isArray(documentWithLanguage.string) ? documentWithLanguage.string : [documentWithLanguage.string];
|
|
717
689
|
for (const item of documentItems) {
|
|
@@ -763,9 +735,9 @@ function parseNotes(notes, language = "eng") {
|
|
|
763
735
|
}
|
|
764
736
|
}
|
|
765
737
|
if (typeof noteWithLanguage.string === "string" || typeof noteWithLanguage.string === "number" || typeof noteWithLanguage.string === "boolean") {
|
|
766
|
-
content =
|
|
738
|
+
content = parseEmail(parseFakeString(noteWithLanguage.string));
|
|
767
739
|
} else {
|
|
768
|
-
content =
|
|
740
|
+
content = parseEmail(parseDocument(noteWithLanguage).content);
|
|
769
741
|
}
|
|
770
742
|
returnNotes.push({
|
|
771
743
|
number: note.noteNo,
|
|
@@ -2665,7 +2637,7 @@ export {
|
|
|
2665
2637
|
parseContext,
|
|
2666
2638
|
parseCoordinates,
|
|
2667
2639
|
parseDocument,
|
|
2668
|
-
|
|
2640
|
+
parseEmail,
|
|
2669
2641
|
parseEvents,
|
|
2670
2642
|
parseFakeString,
|
|
2671
2643
|
parseIdentification,
|
package/package.json
CHANGED