npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pica-data

v0.7.0

Published

EcmaScript utilities to process PICA+ data

Downloads

31

Readme

pica-data

Test and build npm release

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 serializePica to serialize a PICA record in PICA Plain syntax (optionally annotated)
  • function serializePicaField to serialize a PICA field in PICA Plain syntax (optionally annotated)
  • function picaFieldIdentifier to generate a field identifier from a field or from an Avram field schedule

Access

  • function getPPN to extract the PPN of a record
  • class PicaPath to work with PICA Path expressions
    • method fieldIdentifier to get the path's field identifier (tag and optional occurrence)
    • method tagString to get the path's PICA tag, without occurrence
    • method occurrenceString to get the path's occurrence (or an empty string)
    • method startOccurrence to get the path's start occurrence (or an empty string)
    • method endOccurrence to get the path's end occurrence (or an empty string)
    • method subfieldString to get the path's subfield identifier (or an empty string)
    • method toString to 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 as getValues but unique values only

Validation

  • function picaFieldSchedule to look up a field schedule for a given field in an Avram schema
  • function picaFieldScheduleIdentifier to look up the field identifier of a field in an Avram schema
  • function isPPN to check whether a string looks like a valid PPN (including checksum)
  • function ppnChecksum to 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 major

License

MIT License Verbundzentrale des GBV (VZG)