Module

BasicHelpers

This file contains helpers for working with LinkedArt JSON-LD data

Author:
  • Adam Brin, Pamela Lam, Alyx Rossetti, Charles Webb, Selina Zawacki

View Source BasicHelpers.js, line 1

Methods

# static normalizeAatId(id) → {String}

Normalizes the AAT ID to one of two versions (an aat: prefixed id or a full url)

Parameters:
Name Type Description
id String

an ID to test

View Source BasicHelpers.js, line 63

  • the alternate ID format
String
Examples
- short to full aat value
normalizeAatId("aat:300388306") would return http://vocab.getty.edu/aat/300388306
- full to short
normalizeAatId("http://vocab.getty.edu/aat/300388306") would return aat:300388306

# static normalizeFieldToArray(obj, key) → {Array}

Checks whether the object has the key as a property, and returns the result as either
an empty array (if it doesn't exist), an array with the single object if it's an object
or primitive, or the array

Parameters:
Name Type Description
obj Object

The object that might have an array attribute

key String

The key for the attribute field we want to retrieve

View Source BasicHelpers.js, line 28

  • The field's value normalized to an array
Array
Examples
field doesn't exist
normalizeFieldToArray({"id": "1234"}, "type") would return an empty array ([])
field value is not an array
normalizeFieldToArray({"id": "1234"}, "id") would return ["1234"]

# static normalizeFieldWithParts(object, field) → {Array}

Some of the fields in LinkedArt may be (but sometimes dont) include parts.
For example, produced_by which may have a production, or that production may contain multiple
parts. This function returns an array with the single or all parts

Parameters:
Name Type Description
object Object

the JSON-LD object (or sub-bart)

field String

the field to look for/in

View Source BasicHelpers.js, line 101

an array that contains the single or multiple parts

Array
Examples
with a production without parts:
 normalizeFieldWithParts({produced_by: { carried_out_by: {id:123}}}, 'produced_by'), it would return an array with 1 item [{ carried_out_by: {id:123}}}]
with a production with parts:
 normalizeFieldWithParts({produced_by: { part: [{carried_out_by: {id:123}}}]}, 'produced_by'), it would return an array with one item [{ carried_out_by: {id:123}}}]