Parsers to convert strings from Internet Archive API responses to their native javascript equivalents.
Each parser implements the FieldParserInterface:
export type FieldParserRawValue = string | number | boolean;
export interface FieldParserInterface<T> {
/**
* Parse the raw value and return a value of type T or undefined if unparseable
*
* @param rawValue T | undefined
*/
parseValue(rawValue: FieldParserRawValue): T | undefined;
}
They are responsible for parsing the input and returning the appropriate value or undefined.
Instantiate a parser or use the shared instance:
const parser = new BooleanParser()
parser.parse('true') => true
BooleanParser.shared.parse('false') => false
See tests for more usage examples.
BooleanByte- a number in bytesDate- parses the various Internet Archive date formatsDuration- Parseshh:mm:ss.msandss.msformats to secondsMediaType- Internet Archive media typesNumberPageProgression- Internet Archive page progression (right to left, left to right)String
To run the suite of Web Test Runner tests, run
yarn run testTo run the tests in watch mode (for <abbr title="test driven development">TDD</abbr>, for example), run
yarn run test:watchTo scan the project for linting errors, run
yarn run lintYou can lint with ESLint and Prettier individually as well
yarn run lint:eslintyarn run lint:prettierTo automatically fix many linting errors, run
yarn run formatYou can format using ESLint and Prettier individually as well
yarn run format:eslintyarn run format:prettierFor most of the tools, the configuration is in the package.json to reduce the amount of files in your project.
If you customize the configuration a lot, you can consider moving them to individual files.