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

@biblioteksentralen/marc

v0.0.2

Published

MARC record parser and serializer

Downloads

6

Readme

@biblioteksentralen/marc

Package for representating MARC records in TypeScript and serialize to/from MARC XML and JSON.

The JSON serialization is compatible with schema defined by https://www.npmjs.com/package/@natlibfi/marc-record

Usage

Parsing XML

import { parseMarcXml } from "@biblioteksentralen/marc";

const xmlRecord = `
<record xmlns="http://www.loc.gov/MARC21/slim">
  <leader>00000cam^a22001937i^4500</leader>
  <controlfield tag="001">000030000</controlfield>
  <controlfield tag="003">FI-MELINDA</controlfield>
  <controlfield tag="005">20141221175522.0</controlfield>
  <controlfield tag="008">890208s1988^^^^sw^|||||||||||||||||swe||</controlfield>
  <datafield tag="020" ind1=" " ind2=" ">
    <subfield code="a">91-38-61844-3</subfield>
    <subfield code="q">inb.</subfield>
  </datafield>
  <datafield tag="100" ind1="0" ind2=" ">
    <subfield code="a">Durö, Robert.</subfield>
  </datafield>
  <datafield tag="245" ind1="1" ind2="0">
    <subfield code="a">Konkurrensöverlägsenhet :</subfield>
    <subfield code="b">i tio konkreta steg /</subfield>
    <subfield code="c">Robert Durö.</subfield>
  </datafield>
</record>
`;

const record = parseMarcXml(xmlRecord);
const title = record
  .getSubfieldValues("245", /a|b|n|p/)
  .join(" ")
  ?.trim();

Serializing / deserializing

The MarcRecord class can be JSON serialized:

const serializedRecord = JSON.stringify(record);

and deserialized:

const record = MarcRecord.fromJSON(JSON.parse(serializedRecord));

Standalone fields can also be deserialized using the createDataField function – useful for tests:

const field = createDataField({
  tag: "020",
  subfields: [{ code: "a", value: "9788283982701" }],
});

JSON Schema validation

The package exports a JSON schema that can be used to validate JSON serialized MARC record structure using AJV or other JSON Schema validators.

import Ajv from "ajv";
import { createMarcSchema } from "@biblioteksentralen/marc";

const schema = createMarcSchema();
const ajv = new Ajv();
const validate = ajv.compile(schema);
const result = validate(record.toJSON());