These are the data models for Internet Archive Metadata. The Metadata models handle automatic conversions between the raw values to native Typescript data types.
When receiving JSON responses from the Internet Archive's metadata service, the values can be strings, numbers, or arrays. These take all of those values and normalizes them.
All fields, except for identifier, have 3 properties:
.valueto get the first (or only) value in the native type.valuesto get all of the values if it's an array in their native types.rawValueto get the original value from the response
Live demo — load any archive.org item by identifier (or paste raw metadata JSON) and inspect the parsed fields.
const metadata = new Metadata({
identifier: 'foo',
addeddate: '2021-01-01',
collection: ['foo', 'bar'],
description: 'A foo that is also a bar',
duration: '1:23:45',
mediatype: 'audio',
})
console.log('Raw metadata:', JSON.stringify(metadata.rawMetadata));
// outputs the raw JSON response,
// { identifier: 'foo', addeddate: '2021-01-01', collection: ['foo', 'bar'] .... }
console.log('Identifier', metadata.identifier);
// > 'foo'
console.log('Addeddate', metadata.addeddate.value);
// > Date object (Fri Jan 01 2021 00:00:00 GMT-0800 (Pacific Standard Time))
// get first value of an array of values
console.log('Collection', metadata.collection.value);
// > 'foo'
// get all values of an array
console.log('Collection', metadata.collection.values);
// > ['foo', 'bar']
// duration is in seconds and handles conversions from hh:mm:ss if needed
console.log('Duration', metadata.duration.value);
// > 5025npm run startTo run a local development server that serves the basic demo located in demo/index.html
To run the suite of Web Test Runner tests, run
npm run testTo run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
npm run test:watchTo scan the project for linting errors, run
npm run lintYou can lint with ESLint and Prettier individually as well
npm run lint:eslintnpm run lint:prettierTo automatically fix many linting errors, run
npm run formatYou can format using ESLint and Prettier individually as well
npm run format:eslintnpm run format:prettier