@readium/shared 2.0.0 → 2.1.1

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.
@@ -77,7 +77,7 @@ export class Contributor {
77
77
  sortAs: json.sortAs,
78
78
  identifier: json.identifier,
79
79
  altIdentifiers: json.altIdentifier
80
- ? (json.altIdentifier instanceof Array
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))
@@ -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 instanceof Array ? json : [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 instanceof Array)) return undefined;
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);
@@ -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 instanceof Array
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 instanceof Array)) return;
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 instanceof Array) {
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);
@@ -1,4 +1,4 @@
1
- /* Copyright 2021 Readium Foundation. All rights reserved.
1
+ /* Copyright 2025 Readium Foundation. All rights reserved.
2
2
  * Use of this source code is governed by a BSD-style license,
3
3
  * available in the LICENSE file present in the Github repository of the project.
4
4
  */
@@ -16,6 +16,7 @@ import { LocalizedString } from './LocalizedString';
16
16
  import { Profile } from './Profiles';
17
17
  import { ReadingProgression } from './ReadingProgression';
18
18
  import { Subjects } from './Subject';
19
+ import { Accessibility } from './accessibility/Accessibility';
19
20
  import { TDM } from './TDM';
20
21
 
21
22
  /**
@@ -59,6 +60,7 @@ export class Metadata {
59
60
  public readingProgression?: ReadingProgression;
60
61
  public duration?: number;
61
62
  public numberOfPages?: number;
63
+ public accessibility?: Accessibility;
62
64
  public tdm?: TDM;
63
65
  public otherMetadata?: { [key: string]: any };
64
66
 
@@ -94,6 +96,7 @@ export class Metadata {
94
96
  'readingProgression',
95
97
  'duration',
96
98
  'numberOfPages',
99
+ 'accessibility',
97
100
  'tdm'
98
101
  ];
99
102
 
@@ -131,6 +134,7 @@ export class Metadata {
131
134
  readingProgression?: ReadingProgression;
132
135
  duration?: number;
133
136
  numberOfPages?: number;
137
+ accessibility?: Accessibility;
134
138
  tdm?: TDM;
135
139
  otherMetadata?: { [key: string]: any };
136
140
  }) {
@@ -184,6 +188,7 @@ export class Metadata {
184
188
  this.readingProgression = values.readingProgression;
185
189
  this.duration = values.duration;
186
190
  this.numberOfPages = values.numberOfPages;
191
+ this.accessibility = values.accessibility;
187
192
  this.tdm = values.tdm;
188
193
  this.otherMetadata = values.otherMetadata;
189
194
  }
@@ -222,6 +227,7 @@ export class Metadata {
222
227
  const modified = datefromJSON(json.modified);
223
228
  const subjects = Subjects.deserialize(json.subject);
224
229
  const belongsTo = BelongsTo.deserialize(json.belongsTo);
230
+ const accessibility = Accessibility.deserialize(json.accessibility);
225
231
  const layout = json.layout;
226
232
  const readingProgression = json.readingProgression;
227
233
  const duration = positiveNumberfromJSON(json.duration);
@@ -265,6 +271,7 @@ export class Metadata {
265
271
  readingProgression,
266
272
  duration,
267
273
  numberOfPages,
274
+ accessibility,
268
275
  tdm,
269
276
  otherMetadata
270
277
  });
@@ -308,6 +315,7 @@ export class Metadata {
308
315
  if (this.duration !== undefined) json.duration = this.duration;
309
316
  if (this.numberOfPages !== undefined)
310
317
  json.numberOfPages = this.numberOfPages;
318
+ if (this.accessibility) json.accessibility = this.accessibility.serialize();
311
319
  if (this.tdm) json.tdm = this.tdm.serialize();
312
320
 
313
321
  if (this.otherMetadata) {
@@ -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 instanceof Array) {
42
+ if (Array.isArray(json)) {
43
43
  // Parses an array of links.
44
44
  links = Links.deserialize(json);
45
- } else if (json instanceof Object) {
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 instanceof Array) {
89
+ } else if (Array.isArray(subJSON)) {
90
90
  // Parses a list of collection objects.
91
91
  const list = subJSON
92
92
  .map<PublicationCollection>(
@@ -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 instanceof Array ? json : [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)