ochre-sdk 1.3.25 → 1.3.27
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/categories.d.mts +56 -56
- package/dist/categories.mjs +39 -39
- package/dist/constants.d.mts +8 -8
- package/dist/constants.mjs +6 -6
- package/dist/errors.d.mts +12 -12
- package/dist/errors.mjs +22 -23
- package/dist/fetchers/container-items.d.mts +28 -28
- package/dist/fetchers/container-items.mjs +27 -27
- package/dist/fetchers/gallery.d.mts +13 -13
- package/dist/fetchers/gallery.mjs +2 -2
- package/dist/fetchers/item-children.d.mts +12 -12
- package/dist/fetchers/item-children.mjs +2 -2
- package/dist/fetchers/item-links.d.mts +10 -10
- package/dist/fetchers/item-links.mjs +6 -6
- package/dist/fetchers/item-locations.d.mts +20 -20
- package/dist/fetchers/item-locations.mjs +3 -3
- package/dist/fetchers/item-ocr-data.d.mts +23 -23
- package/dist/fetchers/item-ocr-data.mjs +44 -44
- package/dist/fetchers/item.d.mts +23 -18
- package/dist/fetchers/item.mjs +15 -15
- package/dist/fetchers/map-layers.d.mts +15 -15
- package/dist/fetchers/map-layers.mjs +12 -11
- package/dist/fetchers/request.d.mts +40 -40
- package/dist/fetchers/request.mjs +37 -37
- package/dist/fetchers/set/items.d.mts +15 -15
- package/dist/fetchers/set/items.mjs +1 -1
- package/dist/fetchers/set/property-values.d.mts +16 -16
- package/dist/fetchers/set/property-values.mjs +43 -43
- package/dist/fetchers/tree/items.d.mts +27 -27
- package/dist/fetchers/tree/items.mjs +1 -1
- package/dist/fetchers/website-metadata.d.mts +4 -4
- package/dist/fetchers/website-metadata.mjs +9 -9
- package/dist/fetchers/website.d.mts +10 -10
- package/dist/fetchers/website.mjs +12 -12
- package/dist/getters.d.mts +83 -83
- package/dist/getters.mjs +74 -74
- package/dist/helpers.d.mts +4 -4
- package/dist/helpers.mjs +7 -7
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +5 -5
- package/dist/languages.d.mts +58 -58
- package/dist/languages.mjs +21 -21
- package/dist/ocr.d.mts +27 -27
- package/dist/ocr.mjs +29 -29
- package/dist/parsers/helpers.d.mts +23 -23
- package/dist/parsers/helpers.mjs +8 -8
- package/dist/parsers/index.d.mts +2 -2
- package/dist/parsers/index.mjs +15 -15
- package/dist/parsers/languages.d.mts +49 -49
- package/dist/parsers/languages.mjs +49 -49
- package/dist/parsers/multilingual.d.mts +174 -174
- package/dist/parsers/multilingual.mjs +146 -146
- package/dist/parsers/partial-date.d.mts +12 -12
- package/dist/parsers/partial-date.mjs +11 -11
- package/dist/parsers/property-token.d.mts +20 -20
- package/dist/parsers/property-token.mjs +16 -16
- package/dist/parsers/string.d.mts +33 -33
- package/dist/parsers/string.mjs +62 -64
- package/dist/parsers/website/bounds.d.mts +6 -6
- package/dist/parsers/website/bounds.mjs +5 -5
- package/dist/parsers/website/components.d.mts +46 -31
- package/dist/parsers/website/components.mjs +84 -51
- package/dist/parsers/website/index.d.mts +2 -2
- package/dist/parsers/website/index.mjs +45 -48
- package/dist/parsers/website/links.d.mts +24 -24
- package/dist/parsers/website/links.mjs +18 -18
- package/dist/parsers/website/messages.d.mts +16 -16
- package/dist/parsers/website/messages.mjs +14 -14
- package/dist/parsers/website/options.d.mts +1 -1
- package/dist/parsers/website/properties.d.mts +17 -8
- package/dist/parsers/website/properties.mjs +31 -10
- package/dist/parsers/website/reader.d.mts +55 -47
- package/dist/parsers/website/reader.mjs +66 -51
- package/dist/parsers/website/slug.d.mts +50 -50
- package/dist/parsers/website/slug.mjs +36 -36
- package/dist/parsers/website/styles.d.mts +18 -18
- package/dist/parsers/website/styles.mjs +19 -19
- package/dist/parsers/website/walk.d.mts +46 -46
- package/dist/parsers/website/walk.mjs +34 -34
- package/dist/query.d.mts +63 -63
- package/dist/query.mjs +137 -140
- package/dist/reflection.d.mts +51 -51
- package/dist/reflection.mjs +45 -45
- package/dist/schemas.d.mts +44 -44
- package/dist/schemas.mjs +50 -50
- package/dist/types/index.d.mts +192 -192
- package/dist/types/utilities.d.mts +5 -5
- package/dist/types/website.d.mts +74 -62
- package/dist/xml/dates.d.mts +9 -9
- package/dist/xml/dates.mjs +9 -9
- package/dist/xml/metadata.d.mts +14 -14
- package/dist/xml/metadata.mjs +18 -18
- package/dist/xml/schemas.mjs +24 -24
- package/dist/xml/types.d.mts +9 -9
- package/dist/xquery.d.mts +49 -49
- package/dist/xquery.mjs +50 -50
- package/package.json +10 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_LANGUAGES } from "../constants.mjs";
|
|
2
|
-
import { readProperty } from "../reflection.mjs";
|
|
3
2
|
import { serializeMDXText } from "./mdx.mjs";
|
|
3
|
+
import { readProperty } from "../reflection.mjs";
|
|
4
4
|
// src/parsers/multilingual.ts
|
|
5
5
|
const MULTILINGUAL_STRING_INTERNAL_INIT = Symbol("MultilingualString.internalInit");
|
|
6
6
|
function normalizeInputText(text) {
|
|
@@ -19,16 +19,16 @@ function normalizeAliases(aliases) {
|
|
|
19
19
|
return normalizedAliases;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
Apply the rule OCHRE publishes `zxx` content by
|
|
23
|
+
|
|
24
|
+
`zxx` content beside a field's languages names the same thing again, so it
|
|
25
|
+
is aliases; `zxx` content with no language beside it is the text itself,
|
|
26
|
+
in no language. Normalizing every string through this keeps the two
|
|
27
|
+
readings from ever coexisting, whichever way a string was built or edited.
|
|
28
|
+
@param hasLanguages - Whether any language carries an entry
|
|
29
|
+
@param aliases - The aliases the string would carry
|
|
30
|
+
@param nonLinguistic - The non-linguistic entries the string would carry
|
|
31
|
+
@returns The aliases and non-linguistic entries to store
|
|
32
32
|
*/
|
|
33
33
|
function normalizeUntaggedText(hasLanguages, aliases, nonLinguistic) {
|
|
34
34
|
if (hasLanguages) return {
|
|
@@ -80,30 +80,30 @@ function getImplicitLanguages(content, options) {
|
|
|
80
80
|
return languages.length > 0 ? languages : [...DEFAULT_LANGUAGES];
|
|
81
81
|
}
|
|
82
82
|
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
Pick the language reads should fall back to first
|
|
84
|
+
@param availableLanguages - The languages carrying content, in order
|
|
85
|
+
@param supportedLanguages - Every language the string was created for
|
|
86
|
+
@returns The default language
|
|
87
87
|
*/
|
|
88
88
|
function resolveDefaultLanguageOption(availableLanguages, supportedLanguages) {
|
|
89
89
|
return availableLanguages[0] ?? supportedLanguages[0] ?? DEFAULT_LANGUAGES[0];
|
|
90
90
|
}
|
|
91
91
|
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
Whether a constructor argument is the module's own normalized init
|
|
93
|
+
|
|
94
|
+
The assertion is earned by the brand rather than by inspecting the fields:
|
|
95
|
+
{@link MULTILINGUAL_STRING_INTERNAL_INIT} is a module-private symbol, so no
|
|
96
|
+
caller outside this file can produce a value carrying it, and the single
|
|
97
|
+
producer is `fromNormalized`. That is what makes the narrowing sound; a
|
|
98
|
+
field-by-field check would only re-state what the brand already guarantees.
|
|
99
|
+
@param value - The constructor argument
|
|
100
|
+
@returns True when the value carries the internal brand
|
|
101
101
|
*/
|
|
102
102
|
function isInternalInit(value) {
|
|
103
103
|
return readProperty(value, MULTILINGUAL_STRING_INTERNAL_INIT) === true;
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
|
-
|
|
106
|
+
Multilingual string
|
|
107
107
|
*/
|
|
108
108
|
var MultilingualString = class MultilingualString {
|
|
109
109
|
static fromNormalized(content, options, availableLanguages, nonLinguistic) {
|
|
@@ -198,13 +198,13 @@ var MultilingualString = class MultilingualString {
|
|
|
198
198
|
this._nonLinguistic = parsed._nonLinguistic;
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
201
|
+
Resolve the entries to read for a language
|
|
202
|
+
|
|
203
|
+
The fallback order is requested language, then the dataset's default
|
|
204
|
+
language, then the first language that has any content. This is the only
|
|
205
|
+
place that order is written down; every reader below is a projection of it.
|
|
206
|
+
Non-linguistic text is the same in every language, so it answers every
|
|
207
|
+
read, exact ones included.
|
|
208
208
|
*/
|
|
209
209
|
resolveEntries(language, isExact) {
|
|
210
210
|
const candidateLanguages = isExact ? [language] : [
|
|
@@ -225,132 +225,132 @@ var MultilingualString = class MultilingualString {
|
|
|
225
225
|
return entries[0] ?? null;
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
|
-
|
|
228
|
+
Get text in a specific language, falling back when it has none
|
|
229
229
|
*/
|
|
230
230
|
getText(language) {
|
|
231
231
|
return this.resolvePrimaryEntry(language, false)?.text ?? "";
|
|
232
232
|
}
|
|
233
233
|
/**
|
|
234
|
-
|
|
234
|
+
Get rich text in a specific language, falling back when it has none
|
|
235
235
|
*/
|
|
236
236
|
getRichText(language) {
|
|
237
237
|
return this.resolvePrimaryEntry(language, false)?.richText ?? "";
|
|
238
238
|
}
|
|
239
239
|
/**
|
|
240
|
-
|
|
240
|
+
Get text in a specific language, with no fallback
|
|
241
241
|
*/
|
|
242
242
|
getExactText(language) {
|
|
243
243
|
return this.resolvePrimaryEntry(language, true)?.text ?? "";
|
|
244
244
|
}
|
|
245
245
|
/**
|
|
246
|
-
|
|
246
|
+
Get rich text in a specific language, with no fallback
|
|
247
247
|
*/
|
|
248
248
|
getExactRichText(language) {
|
|
249
249
|
return this.resolvePrimaryEntry(language, true)?.richText ?? "";
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
|
-
|
|
252
|
+
Get every entry for a specific language, with no fallback
|
|
253
253
|
*/
|
|
254
254
|
getExactEntries(language) {
|
|
255
255
|
return Array.from(this.resolveEntries(language, true), (entry) => ({ ...entry }));
|
|
256
256
|
}
|
|
257
257
|
/**
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
258
|
+
Get every entry for a language, falling back when it has none
|
|
259
|
+
|
|
260
|
+
The multi-entry counterpart of {@link MultilingualString.getText}: OCHRE
|
|
261
|
+
can carry several entries for one language, and this returns all of them
|
|
262
|
+
rather than only the primary. Each entry carries both `text` and
|
|
263
|
+
`richText`, so a caller rendering a rich field reads them from here.
|
|
264
|
+
@param language - The language to read
|
|
265
|
+
@returns The entries, or an empty array when no language has any
|
|
266
266
|
*/
|
|
267
267
|
getEntries(language) {
|
|
268
268
|
return Array.from(this.resolveEntries(language, false), (entry) => ({ ...entry }));
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
271
|
+
Get the text of every entry for a language, falling back when it has none
|
|
272
|
+
@param language - The language to read
|
|
273
|
+
@returns The texts, or an empty array when no language has any
|
|
274
274
|
*/
|
|
275
275
|
getTexts(language) {
|
|
276
276
|
return Array.from(this.resolveEntries(language, false), (entry) => entry.text);
|
|
277
277
|
}
|
|
278
278
|
/**
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
Get the text of every entry for a language, with no fallback
|
|
280
|
+
@param language - The language to read
|
|
281
|
+
@returns The texts, or an empty array when that language has none
|
|
282
282
|
*/
|
|
283
283
|
getExactTexts(language) {
|
|
284
284
|
return Array.from(this.resolveEntries(language, true), (entry) => entry.text);
|
|
285
285
|
}
|
|
286
286
|
/**
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
287
|
+
Get the alternative names OCHRE publishes as `zxx` content beside the
|
|
288
|
+
string's languages
|
|
289
|
+
|
|
290
|
+
A non-linguistic string has none: its `zxx` content is the text itself.
|
|
291
291
|
*/
|
|
292
292
|
getAliases() {
|
|
293
293
|
return [...this._aliases];
|
|
294
294
|
}
|
|
295
295
|
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
296
|
+
Get the languages that carry language-specific content
|
|
297
|
+
|
|
298
|
+
A non-linguistic string has none, although every language reads its text;
|
|
299
|
+
{@link MultilingualString.isNonLinguistic} tells the two apart.
|
|
300
300
|
*/
|
|
301
301
|
getAvailableLanguages() {
|
|
302
302
|
return [...this._availableLanguages];
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
305
|
-
|
|
305
|
+
Get the language reads fall back to before trying the rest
|
|
306
306
|
*/
|
|
307
307
|
getDefaultLanguage() {
|
|
308
308
|
return this._options.defaultLanguage;
|
|
309
309
|
}
|
|
310
310
|
/**
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
311
|
+
Get every language this string was built to hold
|
|
312
|
+
|
|
313
|
+
The configured language list, which is not the same question as
|
|
314
|
+
{@link MultilingualString.getAvailableLanguages}: that one answers which
|
|
315
|
+
languages actually carry content, and is a subset of this.
|
|
316
|
+
@returns The supported languages
|
|
317
317
|
*/
|
|
318
318
|
getSupportedLanguages() {
|
|
319
319
|
return [...this._options.availableLanguages];
|
|
320
320
|
}
|
|
321
321
|
/**
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
322
|
+
Whether any language carries an entry
|
|
323
|
+
|
|
324
|
+
Answers the structural question. A language whose only entry is blank
|
|
325
|
+
still counts here; {@link MultilingualString.hasContent} is the question
|
|
326
|
+
about text. Non-linguistic text counts as an entry; aliases never stand
|
|
327
|
+
without one, since `zxx` content alone is read as non-linguistic text.
|
|
328
|
+
@returns True when no language carries an entry and there is no
|
|
329
|
+
non-linguistic text
|
|
330
330
|
*/
|
|
331
331
|
isEmpty() {
|
|
332
332
|
return this._availableLanguages.length === 0 && this._nonLinguistic.length === 0;
|
|
333
333
|
}
|
|
334
334
|
/**
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
335
|
+
Whether the string is text in no language, such as an identifier or a code
|
|
336
|
+
|
|
337
|
+
OCHRE publishes this as `zxx` content with no other language beside it.
|
|
338
|
+
Its text answers every language, so a caller that needs to know whether
|
|
339
|
+
text was written in a language, to set an HTML `lang` attribute or to
|
|
340
|
+
leave it out of a translation check, asks this.
|
|
341
|
+
@returns True when the string holds non-linguistic text
|
|
342
342
|
*/
|
|
343
343
|
isNonLinguistic() {
|
|
344
344
|
return this._nonLinguistic.length > 0;
|
|
345
345
|
}
|
|
346
346
|
/**
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
347
|
+
Whether any entry in any language carries text that is not whitespace
|
|
348
|
+
|
|
349
|
+
Deliberately not the negation of {@link MultilingualString.isEmpty}, which
|
|
350
|
+
only asks whether entries exist. OCHRE does serve fields holding a single
|
|
351
|
+
whitespace entry, so a caller deciding whether to render something wants
|
|
352
|
+
this one, and it looks at every entry rather than only the primary.
|
|
353
|
+
@returns True when some entry has non-whitespace text
|
|
354
354
|
*/
|
|
355
355
|
hasContent() {
|
|
356
356
|
for (const language of this._availableLanguages) {
|
|
@@ -361,30 +361,30 @@ var MultilingualString = class MultilingualString {
|
|
|
361
361
|
return false;
|
|
362
362
|
}
|
|
363
363
|
/**
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
364
|
+
Whether a specific language reads an entry, with no fallback
|
|
365
|
+
|
|
366
|
+
True for every language when the string is non-linguistic, matching the
|
|
367
|
+
exact readers, which return non-linguistic text for any language.
|
|
368
|
+
@param language - The language to test
|
|
369
|
+
@returns True when that language carries at least one entry
|
|
370
370
|
*/
|
|
371
371
|
hasLanguage(language) {
|
|
372
372
|
return (this._content[language]?.length ?? 0) > 0 || this._nonLinguistic.length > 0;
|
|
373
373
|
}
|
|
374
374
|
/**
|
|
375
|
-
|
|
376
|
-
|
|
375
|
+
Whether OCHRE published any alternative names for this string
|
|
376
|
+
@returns True when there is at least one alias
|
|
377
377
|
*/
|
|
378
378
|
hasAliases() {
|
|
379
379
|
return this._aliases.length > 0;
|
|
380
380
|
}
|
|
381
381
|
/**
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
382
|
+
Set the text for a language, or append another entry to it
|
|
383
|
+
@param language - The language to write
|
|
384
|
+
@param text - The text to write
|
|
385
|
+
@param options - Write options
|
|
386
|
+
@param options.shouldAppend - Append as an additional entry instead of replacing
|
|
387
|
+
@returns A new multilingual string
|
|
388
388
|
*/
|
|
389
389
|
with(language, text, options = {}) {
|
|
390
390
|
const newContent = cloneContent(this._content);
|
|
@@ -395,12 +395,12 @@ var MultilingualString = class MultilingualString {
|
|
|
395
395
|
return MultilingualString.fromNormalized(newContent, this._options, getLanguagesWithEntries(newContent, this._options.availableLanguages), this._nonLinguistic);
|
|
396
396
|
}
|
|
397
397
|
/**
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
398
|
+
Remove the content for a language
|
|
399
|
+
|
|
400
|
+
When the removed language was the default, the default moves to the first
|
|
401
|
+
language that still has content, so reads keep resolving.
|
|
402
|
+
@param language - The language to remove
|
|
403
|
+
@returns A new multilingual string
|
|
404
404
|
*/
|
|
405
405
|
without(language) {
|
|
406
406
|
const currentContent = cloneContent(this._content);
|
|
@@ -413,15 +413,15 @@ var MultilingualString = class MultilingualString {
|
|
|
413
413
|
}, newAvailableLanguages, this._nonLinguistic);
|
|
414
414
|
}
|
|
415
415
|
/**
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
416
|
+
Replace the alias values
|
|
417
|
+
|
|
418
|
+
Aliases are the `zxx` content OCHRE publishes beside a field's languages,
|
|
419
|
+
so they are set as a whole rather than per language. Empty strings are
|
|
420
|
+
dropped, matching how they are read from a payload, and on a string with
|
|
421
|
+
no language they become its non-linguistic text, as the same content
|
|
422
|
+
would be read.
|
|
423
|
+
@param aliases - The aliases to carry
|
|
424
|
+
@returns A new multilingual string
|
|
425
425
|
*/
|
|
426
426
|
withAliases(aliases) {
|
|
427
427
|
return MultilingualString.fromNormalized(cloneContent(this._content), {
|
|
@@ -430,20 +430,20 @@ var MultilingualString = class MultilingualString {
|
|
|
430
430
|
}, this._availableLanguages, this._nonLinguistic);
|
|
431
431
|
}
|
|
432
432
|
/**
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
433
|
+
Transform the text of every entry in every language
|
|
434
|
+
|
|
435
|
+
Replaces the old `map`, which corrupted rich text: it wrote the
|
|
436
|
+
transformed plain text and left the entry's `richText` to be re-derived,
|
|
437
|
+
so a transform such as uppercasing turned `<InternalLink uuid="abc">` into
|
|
438
|
+
markup OCHRE never wrote. The transform here runs against plain text only,
|
|
439
|
+
and the entry's rich text is rebuilt from the result, so the two can never
|
|
440
|
+
disagree.
|
|
441
|
+
|
|
442
|
+
A transform that needs to keep or rewrite markup returns
|
|
443
|
+
`{ text, richText }` instead of a string, and both are used verbatim.
|
|
444
|
+
Non-linguistic text is transformed too, with `null` as its language.
|
|
445
|
+
@param transform - Produces the new text for one entry
|
|
446
|
+
@returns A new multilingual string
|
|
447
447
|
*/
|
|
448
448
|
mapText(transform) {
|
|
449
449
|
const newContent = {};
|
|
@@ -460,16 +460,16 @@ var MultilingualString = class MultilingualString {
|
|
|
460
460
|
})));
|
|
461
461
|
}
|
|
462
462
|
/**
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
463
|
+
Keep only the entries a predicate accepts
|
|
464
|
+
|
|
465
|
+
The callback receives the whole entry rather than just its text, so it
|
|
466
|
+
can also test `richText` and `isPrimary`. Dropping every entry of a
|
|
467
|
+
language removes that language, and when that was the default the default
|
|
468
|
+
moves to the first language that still has content, so reads keep
|
|
469
|
+
resolving. Non-linguistic entries are tested too, with `null` as their
|
|
470
|
+
language.
|
|
471
|
+
@param shouldKeep - Whether to keep one entry
|
|
472
|
+
@returns A new multilingual string
|
|
473
473
|
*/
|
|
474
474
|
filterEntries(shouldKeep) {
|
|
475
475
|
const newContent = {};
|
|
@@ -486,11 +486,11 @@ var MultilingualString = class MultilingualString {
|
|
|
486
486
|
}, newAvailableLanguages, this._nonLinguistic.filter((entry) => shouldKeep({ ...entry }, null)));
|
|
487
487
|
}
|
|
488
488
|
/**
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
489
|
+
Get the JSON representation
|
|
490
|
+
|
|
491
|
+
Carries `defaultLanguage`, because it is not derivable from the content:
|
|
492
|
+
without it {@link MultilingualString.fromJSON} would fall back to the first
|
|
493
|
+
available language and `getText()` would resolve differently.
|
|
494
494
|
*/
|
|
495
495
|
toJSON() {
|
|
496
496
|
const content = {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { PartialDate } from "../types/index.mjs";
|
|
2
2
|
import { XMLPartialDates } from "../xml/types.mjs";
|
|
3
3
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
Parse the partial dates of an event
|
|
5
|
+
|
|
6
|
+
Reads the year, month and day fields rather than the EDTF text OCHRE
|
|
7
|
+
writes alongside them, which leaves out every field that is not a plain
|
|
8
|
+
four-digit year. An end identical to the start is a single date. The EDTF
|
|
9
|
+
string is only set for what EDTF can express: no qualifier on a year with
|
|
10
|
+
unspecified digits or on a season, no season in a range, and no range
|
|
11
|
+
whose end begins before its start.
|
|
12
|
+
@param rawPartialDates - The raw partialDates element
|
|
13
|
+
@returns The parsed partial dates, or null when every field is empty
|
|
14
|
+
@internal
|
|
15
|
+
*/
|
|
16
16
|
export declare function parsePartialDate(rawPartialDates: XMLPartialDates | undefined): PartialDate | null;
|
|
@@ -202,17 +202,17 @@ function formatEdtf(start, end) {
|
|
|
202
202
|
return startEdtf == null || endEdtf == null ? null : `${startEdtf}/${endEdtf}`;
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
Parse the partial dates of an event
|
|
206
|
+
|
|
207
|
+
Reads the year, month and day fields rather than the EDTF text OCHRE
|
|
208
|
+
writes alongside them, which leaves out every field that is not a plain
|
|
209
|
+
four-digit year. An end identical to the start is a single date. The EDTF
|
|
210
|
+
string is only set for what EDTF can express: no qualifier on a year with
|
|
211
|
+
unspecified digits or on a season, no season in a range, and no range
|
|
212
|
+
whose end begins before its start.
|
|
213
|
+
@param rawPartialDates - The raw partialDates element
|
|
214
|
+
@returns The parsed partial dates, or null when every field is empty
|
|
215
|
+
@internal
|
|
216
216
|
*/
|
|
217
217
|
function parsePartialDate(rawPartialDates) {
|
|
218
218
|
if (rawPartialDates == null) return null;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
The attributes a property value can carry its text in
|
|
3
|
+
*/
|
|
4
4
|
type PropertyValueTextSource = {
|
|
5
5
|
rawValue?: string;
|
|
6
6
|
payload?: string;
|
|
7
7
|
slug?: string;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
The text a property value stands for
|
|
11
|
+
|
|
12
|
+
OCHRE spreads that text over four places, so which one wins is real domain
|
|
13
|
+
knowledge and this is the only place it is written down. The content step is
|
|
14
|
+
injected because the two callers reach it differently: the item parser builds
|
|
15
|
+
a full multilingual string, while the rich-text parser needs one language's
|
|
16
|
+
plain text. Reading the sources in a different order is what let the two
|
|
17
|
+
disagree for a value carrying both a `slug` and `content`.
|
|
18
|
+
@param value - The raw property value
|
|
19
|
+
@param readContentText - Reads the value's `content` as plain text, or null when it has none
|
|
20
|
+
@returns The text, or an empty string when the value carries none
|
|
21
|
+
@internal
|
|
22
|
+
*/
|
|
23
23
|
export declare function readPropertyValueText(value: PropertyValueTextSource, readContentText: () => string | null): string;
|
|
24
24
|
/**
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
The UUID a property value points at, treating an empty attribute as absent
|
|
26
|
+
@param value - The raw property value
|
|
27
|
+
@returns The UUID, or null when there is none
|
|
28
|
+
@internal
|
|
29
|
+
*/
|
|
30
30
|
export declare function readPropertyValueUuid(value: {
|
|
31
31
|
uuid?: string;
|
|
32
32
|
} | undefined): string | null;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
// src/parsers/property-token.ts
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
The text a property value stands for
|
|
4
|
+
|
|
5
|
+
OCHRE spreads that text over four places, so which one wins is real domain
|
|
6
|
+
knowledge and this is the only place it is written down. The content step is
|
|
7
|
+
injected because the two callers reach it differently: the item parser builds
|
|
8
|
+
a full multilingual string, while the rich-text parser needs one language's
|
|
9
|
+
plain text. Reading the sources in a different order is what let the two
|
|
10
|
+
disagree for a value carrying both a `slug` and `content`.
|
|
11
|
+
@param value - The raw property value
|
|
12
|
+
@param readContentText - Reads the value's `content` as plain text, or null when it has none
|
|
13
|
+
@returns The text, or an empty string when the value carries none
|
|
14
|
+
@internal
|
|
15
15
|
*/
|
|
16
16
|
function readPropertyValueText(value, readContentText) {
|
|
17
17
|
return value.rawValue ?? value.payload ?? readContentText() ?? value.slug ?? "";
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
The UUID a property value points at, treating an empty attribute as absent
|
|
21
|
+
@param value - The raw property value
|
|
22
|
+
@returns The UUID, or null when there is none
|
|
23
|
+
@internal
|
|
24
24
|
*/
|
|
25
25
|
function readPropertyValueUuid(value) {
|
|
26
26
|
return value?.uuid == null || value.uuid === "" ? null : value.uuid;
|