pica-data v0.7.0
pica-data
PICA+ record processing
Table of Contents
Install
npm install pica-data (requires Node >= v16)
Usage
This EcmaScript Module contains utility functions to process PICA+ data.
The following serialization formats are supported:
- PICA Plain parsing and serialization (
plain) - Annotated PICA parsing and serialization (
annotated) - PICA Patch Plain (annotated PICA with annotation
+,-,parsing (patch-plain) - Normalized PICA parsing (
normalized) - PICA Patch Normalized parsing (
patch-normalized) - PICA JSON
Parsing
Parsing from string is supported by exported function parsePica. The serialization format is passed as second argument or as option. The function always returns an array of records. Parsing errors result in skipped records unless option error is enabled.
import { parsePica } from "pica-data"
const records = parsePica(input, { format: "plain" })Parsing from readable streams is supported by parser functions parseStream (returns a stream of records) and parseAll (returns a promise resolving in an array of records).
import { parseStream, parseAll } from "pica-data"
// transform stream
parseStream(process.stdin, { format: "plain" })
.on("data", record => console.log(record))
.on("error", ({message, line}) => console.error(`${message} on line ${line}`))
// promise stream to array
parseAll(process.stdin, { format: "plain"})
.then(records => console.log(records))
.catch(e => console.error(`${e.message} on line ${e.line}`))In addition the function parsePicaLine can be used to parse a single line of PICA Plain (optionally annotated) into a PICA field.
To process PICA/XML as returned via SRU use xml2js and transform records with exported function fromXML:
import { fromXML, serializePica } from 'pica-data'
import createClient from '@natlibfi/sru-client'
createClient({
url:'https://sru.k10plus.de/opac-de-627', version: '1.1',
recordSchema: 'picaxml', recordFormat: 'object'
}).searchRetrieve('pica.tit=Beowulf')
.on('record', record => {
const pica = fromXML(record)
console.log(serializePica(pica))
})Serializing
- function
serializePicato serialize a PICA record in PICA Plain syntax (optionally annotated) - function
serializePicaFieldto serialize a PICA field in PICA Plain syntax (optionally annotated) - function
picaFieldIdentifierto generate a field identifier from a field or from an Avram field schedule
Access
- function
getPPNto extract the PPN of a record - class
PicaPathto work with PICA Path expressions- method
fieldIdentifierto get the path's field identifier (tag and optional occurrence) - method
tagStringto get the path's PICA tag, without occurrence - method
occurrenceStringto get the path's occurrence (or an empty string) - method
startOccurrenceto get the path's start occurrence (or an empty string) - method
endOccurrenceto get the path's end occurrence (or an empty string) - method
subfieldStringto get the path's subfield identifier (or an empty string) - method
toStringto get field identifier and subfield identifier combined - method
matchField(field)to check whether a PICA field matches the path - method
getFields(record)to filter all matching PICA fields - method
extractSubfields(field)to filter out all matching subfield values - method
getValues(record)to get a (possibly empty) array of matching subfield values - method
getUniqueValues(record)same asgetValuesbut unique values only
- method
Validation
- function
picaFieldScheduleto look up a field schedule for a given field in an Avram schema - function
picaFieldScheduleIdentifierto look up the field identifier of a field in an Avram schema - function
isPPNto check whether a string looks like a valid PPN (including checksum) - function
ppnChecksumto calculate the checksum of a PPN
Contributing
PRs accepted against the dev branch. Never directly work on the main branch.
For releases (maintainers only) make changes on dev and then run the release script:
npm run release:patch # or minor or majorLicense
MIT License Verbundzentrale des GBV (VZG)