@readium/shared 2.1.0 → 2.1.2
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.js +1992 -2614
- package/dist/index.umd.cjs +3 -3
- package/package.json +16 -17
- package/src/opds/Acquisition.ts +1 -1
- package/src/publication/BelongsTo.ts +1 -1
- package/src/publication/Contributor.ts +6 -6
- package/src/publication/GuidedNavigation.ts +1 -1
- package/src/publication/Link.ts +2 -2
- package/src/publication/LocatorCollection.ts +1 -1
- package/src/publication/PublicationCollection.ts +3 -3
- package/src/publication/Subject.ts +5 -5
- package/src/publication/opds/Properties.ts +1 -1
- package/src/util/JSONParse.ts +1 -1
- package/types/src/publication/Contributor.d.ts +2 -2
- package/types/src/publication/Subject.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@readium/shared",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Shared models to be used across other Readium projects and implementations in Typescript",
|
|
6
6
|
"author": "readium",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"types": "./types/src/index.d.ts",
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
|
+
"types": "./types/src/index.d.ts",
|
|
34
35
|
"import": "./dist/index.js",
|
|
35
|
-
"require": "./dist/index.umd.cjs"
|
|
36
|
-
"types": "./types/src/index.d.ts"
|
|
36
|
+
"require": "./dist/index.umd.cjs"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"dev": "vite",
|
|
49
49
|
"build": "tsc && vite build",
|
|
50
50
|
"update-accessibility-locales": "node update-accessibility-locales.mjs",
|
|
51
|
-
"postinstall": "npm run update-accessibility-locales",
|
|
52
51
|
"test": "jest",
|
|
53
52
|
"size": "size-limit"
|
|
54
53
|
},
|
|
@@ -59,18 +58,18 @@
|
|
|
59
58
|
}
|
|
60
59
|
],
|
|
61
60
|
"devDependencies": {
|
|
62
|
-
"@babel/core": "^7.
|
|
63
|
-
"@babel/preset-env": "^7.
|
|
64
|
-
"@babel/preset-typescript": "^7.
|
|
65
|
-
"@size-limit/file": "^11.
|
|
66
|
-
"@types/jest": "^
|
|
67
|
-
"babel-jest": "^
|
|
68
|
-
"css-selector-generator": "^3.6.
|
|
69
|
-
"jest": "^
|
|
70
|
-
"size-limit": "^11.
|
|
71
|
-
"ts-jest": "^29.
|
|
72
|
-
"tslib": "^2.
|
|
73
|
-
"typescript": "^5.
|
|
74
|
-
"vite": "^
|
|
61
|
+
"@babel/core": "^7.28.3",
|
|
62
|
+
"@babel/preset-env": "^7.28.3",
|
|
63
|
+
"@babel/preset-typescript": "^7.27.1",
|
|
64
|
+
"@size-limit/file": "^11.2.0",
|
|
65
|
+
"@types/jest": "^30.0.0",
|
|
66
|
+
"babel-jest": "^30.1.1",
|
|
67
|
+
"css-selector-generator": "^3.6.9",
|
|
68
|
+
"jest": "^30.1.1",
|
|
69
|
+
"size-limit": "^11.2.0",
|
|
70
|
+
"ts-jest": "^29.4.1",
|
|
71
|
+
"tslib": "^2.8.1",
|
|
72
|
+
"typescript": "^5.9.3",
|
|
73
|
+
"vite": "^7.2.4"
|
|
75
74
|
}
|
|
76
75
|
}
|
package/src/opds/Acquisition.ts
CHANGED
|
@@ -35,7 +35,7 @@ export class Acquisition {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
public static deserializeArray(json: any): Array<Acquisition> | undefined {
|
|
38
|
-
if (!(json
|
|
38
|
+
if (!(Array.isArray(json))) return;
|
|
39
39
|
return json
|
|
40
40
|
.map<Acquisition>(item => Acquisition.deserialize(item) as Acquisition)
|
|
41
41
|
.filter(x => x !== undefined);
|
|
@@ -25,7 +25,7 @@ export class BelongsTo {
|
|
|
25
25
|
* Parses a [BelongsTo] from its RWPM JSON representation.
|
|
26
26
|
*/
|
|
27
27
|
public static deserialize(json: any): BelongsTo | undefined {
|
|
28
|
-
if (!(json && json
|
|
28
|
+
if (!(json && typeof json === 'object')) return;
|
|
29
29
|
|
|
30
30
|
const items = new Map<string, Collection>();
|
|
31
31
|
Object.entries(json).forEach(([key, value]) => {
|
|
@@ -21,7 +21,7 @@ export class Contributor {
|
|
|
21
21
|
public readonly name: LocalizedString;
|
|
22
22
|
|
|
23
23
|
/** The string used to sort the name of the contributor. */
|
|
24
|
-
public readonly sortAs?:
|
|
24
|
+
public readonly sortAs?: LocalizedString;
|
|
25
25
|
|
|
26
26
|
/** An unambiguous reference to this contributor. */
|
|
27
27
|
public readonly identifier?: string;
|
|
@@ -43,7 +43,7 @@ export class Contributor {
|
|
|
43
43
|
*/
|
|
44
44
|
constructor(values: {
|
|
45
45
|
name: LocalizedString;
|
|
46
|
-
sortAs?:
|
|
46
|
+
sortAs?: LocalizedString;
|
|
47
47
|
identifier?: string;
|
|
48
48
|
altIdentifiers?: Set<AltIdentifier>;
|
|
49
49
|
roles?: Set<string>;
|
|
@@ -74,10 +74,10 @@ export class Contributor {
|
|
|
74
74
|
if (!json.name) return;
|
|
75
75
|
return new Contributor({
|
|
76
76
|
name: LocalizedString.deserialize(json.name) as LocalizedString,
|
|
77
|
-
sortAs: json.sortAs,
|
|
77
|
+
sortAs: LocalizedString.deserialize(json.sortAs),
|
|
78
78
|
identifier: json.identifier,
|
|
79
79
|
altIdentifiers: json.altIdentifier
|
|
80
|
-
? (json.altIdentifier
|
|
80
|
+
? (Array.isArray(json.altIdentifier)
|
|
81
81
|
? new Set<AltIdentifier>(json.altIdentifier
|
|
82
82
|
.map((x: string | { value: string; scheme?: string }) => AltIdentifier.deserialize(x))
|
|
83
83
|
.filter((x: AltIdentifier | undefined): x is AltIdentifier => x !== undefined))
|
|
@@ -98,7 +98,7 @@ export class Contributor {
|
|
|
98
98
|
*/
|
|
99
99
|
public serialize(): any {
|
|
100
100
|
const json: any = { name: this.name.serialize() };
|
|
101
|
-
if (this.sortAs !== undefined) json.sortAs = this.sortAs;
|
|
101
|
+
if (this.sortAs !== undefined) json.sortAs = this.sortAs.serialize();
|
|
102
102
|
if (this.identifier !== undefined) json.identifier = this.identifier;
|
|
103
103
|
if (this.altIdentifiers) json.altIdentifier = setToArray(this.altIdentifiers).map(altId => altId.serialize());
|
|
104
104
|
if (this.roles) json.role = setToArray(this.roles);
|
|
@@ -127,7 +127,7 @@ export class Contributors {
|
|
|
127
127
|
*/
|
|
128
128
|
public static deserialize(json: any): Contributors | undefined {
|
|
129
129
|
if (!json) return;
|
|
130
|
-
const items = json
|
|
130
|
+
const items = Array.isArray(json) ? json : [json];
|
|
131
131
|
return new Contributors(
|
|
132
132
|
items
|
|
133
133
|
.map<Contributor>(item => Contributor.deserialize(item) as Contributor)
|
|
@@ -211,7 +211,7 @@ export class GuidedNavigationObject {
|
|
|
211
211
|
* Parses a [GuidedNavigationObject] array from its RWPM JSON representation.
|
|
212
212
|
*/
|
|
213
213
|
public static deserializeArray(json: any): GuidedNavigationObject[] | undefined {
|
|
214
|
-
if (!(json
|
|
214
|
+
if (!(Array.isArray(json))) return undefined;
|
|
215
215
|
return json
|
|
216
216
|
.map<GuidedNavigationObject>((item) => GuidedNavigationObject.deserialize(item) as GuidedNavigationObject)
|
|
217
217
|
.filter((x) => x !== undefined);
|
package/src/publication/Link.ts
CHANGED
|
@@ -107,7 +107,7 @@ export class Link {
|
|
|
107
107
|
type: json.type,
|
|
108
108
|
title: json.title,
|
|
109
109
|
rels: json.rel
|
|
110
|
-
? json.rel
|
|
110
|
+
? Array.isArray(json.rel)
|
|
111
111
|
? new Set<string>(json.rel as Array<string>)
|
|
112
112
|
: new Set<string>([json.rel as string])
|
|
113
113
|
: undefined,
|
|
@@ -226,7 +226,7 @@ export class Links {
|
|
|
226
226
|
* Creates a list of [Link] from its RWPM JSON representation.
|
|
227
227
|
*/
|
|
228
228
|
public static deserialize(json: any): Links | undefined {
|
|
229
|
-
if (!(json && json
|
|
229
|
+
if (!(json && Array.isArray(json))) return;
|
|
230
230
|
return new Links(
|
|
231
231
|
json
|
|
232
232
|
.map<Link>(item => Link.deserialize(item) as Link)
|
|
@@ -102,7 +102,7 @@ export class LocatorCollection {
|
|
|
102
102
|
|
|
103
103
|
let jsonList = json.locators;
|
|
104
104
|
|
|
105
|
-
if (jsonList && jsonList
|
|
105
|
+
if (jsonList && Array.isArray(jsonList)) {
|
|
106
106
|
locators = jsonList
|
|
107
107
|
.map<Locator>(x => Locator.deserialize(x) as Locator)
|
|
108
108
|
.filter(x => x !== undefined);
|
|
@@ -39,10 +39,10 @@ export class PublicationCollection {
|
|
|
39
39
|
let metadata: Map<string, any> | undefined;
|
|
40
40
|
let subcollections: Map<string, Array<PublicationCollection>> | undefined;
|
|
41
41
|
|
|
42
|
-
if (json
|
|
42
|
+
if (Array.isArray(json)) {
|
|
43
43
|
// Parses an array of links.
|
|
44
44
|
links = Links.deserialize(json);
|
|
45
|
-
} else if (json
|
|
45
|
+
} else if (typeof json === 'object') {
|
|
46
46
|
// Parses a sub-collection object.
|
|
47
47
|
links = Links.deserialize(json.links);
|
|
48
48
|
|
|
@@ -86,7 +86,7 @@ export class PublicationCollection {
|
|
|
86
86
|
const list = new Array<PublicationCollection>();
|
|
87
87
|
list.push(collection);
|
|
88
88
|
collections.set(role, list);
|
|
89
|
-
} else if (subJSON
|
|
89
|
+
} else if (Array.isArray(subJSON)) {
|
|
90
90
|
// Parses a list of collection objects.
|
|
91
91
|
const list = subJSON
|
|
92
92
|
.map<PublicationCollection>(
|
|
@@ -14,7 +14,7 @@ export class Subject {
|
|
|
14
14
|
public readonly name: LocalizedString;
|
|
15
15
|
|
|
16
16
|
/** Provides a string that a machine can sort. */
|
|
17
|
-
public readonly sortAs?:
|
|
17
|
+
public readonly sortAs?: LocalizedString;
|
|
18
18
|
|
|
19
19
|
/** EPUB 3.1 opf:term. */
|
|
20
20
|
public readonly code?: string;
|
|
@@ -28,7 +28,7 @@ export class Subject {
|
|
|
28
28
|
/** Creates a [Subject]. */
|
|
29
29
|
constructor(values: {
|
|
30
30
|
name: LocalizedString;
|
|
31
|
-
sortAs?:
|
|
31
|
+
sortAs?: LocalizedString;
|
|
32
32
|
code?: string;
|
|
33
33
|
scheme?: string;
|
|
34
34
|
links?: Links;
|
|
@@ -56,7 +56,7 @@ export class Subject {
|
|
|
56
56
|
if (!json.name) return;
|
|
57
57
|
return new Subject({
|
|
58
58
|
name: LocalizedString.deserialize(json.name) as LocalizedString,
|
|
59
|
-
sortAs: json.sortAs,
|
|
59
|
+
sortAs: json.sortAs ? LocalizedString.deserialize(json.sortAs) : undefined,
|
|
60
60
|
code: json.code,
|
|
61
61
|
scheme: json.scheme,
|
|
62
62
|
links: Links.deserialize(json.links),
|
|
@@ -69,7 +69,7 @@ export class Subject {
|
|
|
69
69
|
*/
|
|
70
70
|
public serialize(): any {
|
|
71
71
|
const json: any = { name: this.name.serialize() };
|
|
72
|
-
if (this.sortAs !== undefined) json.sortAs = this.sortAs;
|
|
72
|
+
if (this.sortAs !== undefined) json.sortAs = this.sortAs.serialize();
|
|
73
73
|
if (this.code !== undefined) json.code = this.code;
|
|
74
74
|
if (this.scheme !== undefined) json.scheme = this.scheme;
|
|
75
75
|
if (this.links) json.links = this.links.serialize();
|
|
@@ -98,7 +98,7 @@ export class Subjects {
|
|
|
98
98
|
*/
|
|
99
99
|
public static deserialize(json: any): Subjects | undefined {
|
|
100
100
|
if (!json) return;
|
|
101
|
-
const items = json
|
|
101
|
+
const items = Array.isArray(json) ? json : [json];
|
|
102
102
|
return new Subjects(
|
|
103
103
|
items
|
|
104
104
|
.map<Subject>(item => Subject.deserialize(item) as Subject)
|
|
@@ -61,7 +61,7 @@ Properties.prototype.getIndirectAcquisitions = function():
|
|
|
61
61
|
| Array<Acquisition>
|
|
62
62
|
| undefined {
|
|
63
63
|
const json = this.otherProperties['indirectAcquisition'];
|
|
64
|
-
if (!(json && json
|
|
64
|
+
if (!(json && Array.isArray(json))) return;
|
|
65
65
|
return json
|
|
66
66
|
.map<Acquisition>(item => Acquisition.deserialize(item) as Acquisition)
|
|
67
67
|
.filter(x => x !== undefined);
|
package/src/util/JSONParse.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Parses the given array (or undefined it it's not an array) */
|
|
2
2
|
export function arrayfromJSON(json: any): Array<any> | undefined {
|
|
3
|
-
return json && json
|
|
3
|
+
return json && Array.isArray(json) ? json : undefined;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
export function arrayfromJSONorString(json: any): Array<any> | undefined {
|
|
@@ -9,7 +9,7 @@ export declare class Contributor {
|
|
|
9
9
|
/** The name of the contributor. */
|
|
10
10
|
readonly name: LocalizedString;
|
|
11
11
|
/** The string used to sort the name of the contributor. */
|
|
12
|
-
readonly sortAs?:
|
|
12
|
+
readonly sortAs?: LocalizedString;
|
|
13
13
|
/** An unambiguous reference to this contributor. */
|
|
14
14
|
readonly identifier?: string;
|
|
15
15
|
/** Alternate identifiers for this contributor. */
|
|
@@ -25,7 +25,7 @@ export declare class Contributor {
|
|
|
25
25
|
*/
|
|
26
26
|
constructor(values: {
|
|
27
27
|
name: LocalizedString;
|
|
28
|
-
sortAs?:
|
|
28
|
+
sortAs?: LocalizedString;
|
|
29
29
|
identifier?: string;
|
|
30
30
|
altIdentifiers?: Set<AltIdentifier>;
|
|
31
31
|
roles?: Set<string>;
|
|
@@ -7,7 +7,7 @@ export declare class Subject {
|
|
|
7
7
|
/** Subject name. */
|
|
8
8
|
readonly name: LocalizedString;
|
|
9
9
|
/** Provides a string that a machine can sort. */
|
|
10
|
-
readonly sortAs?:
|
|
10
|
+
readonly sortAs?: LocalizedString;
|
|
11
11
|
/** EPUB 3.1 opf:term. */
|
|
12
12
|
readonly code?: string;
|
|
13
13
|
/** EPUB 3.1 opf:authority. */
|
|
@@ -17,7 +17,7 @@ export declare class Subject {
|
|
|
17
17
|
/** Creates a [Subject]. */
|
|
18
18
|
constructor(values: {
|
|
19
19
|
name: LocalizedString;
|
|
20
|
-
sortAs?:
|
|
20
|
+
sortAs?: LocalizedString;
|
|
21
21
|
code?: string;
|
|
22
22
|
scheme?: string;
|
|
23
23
|
links?: Links;
|