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

marc-record-js

v0.3.2

Published

MARC record implementation in javascript

Downloads

105

Readme

marc-record-js

Build Status Code Climate Test Coverage

MARC record implementation in javascript

Installation


npm install marc-record-js

Usage

The tests contains multiple examples on how to use the module.

var Record = require('marc-record-js');

Creating a record

// Create empty record
var myRecord = new Record();

// You can also make a record from string representation
var myRecord = Record.fromString(recordString);

recordString can be obtained with toString() function.

myRecord.toString()

The output of toString() is human-readable. Example:

LDR    leader
001    28474
100    ‡aExample Author
245 0  ‡aExample Title
500 #  ‡aNote‡bSecond subfield

Mutating record

// set record leader
myRecord.setLeader("00000cam^a22001817i^4500");

// insert controlfields to the record. Proper ordering is handled automatically.
myRecord.insertControlField({
	tag: "001"
	value: "007045872"
});

// or using array as a parameter
myRecord.insertControlField(["001", "007045872"]});

// There is also appendControlField, which will append a controlfield to the end of the record.

// insert datafields to the record. Proper ordering is handled automatically.
myRecord.appendField({
	tag: "245",
	ind1: "",
	ind2: "",
	subfields: [
		{
			code: "a"
			value: "The title of the book"
		},
		{
			code: "c",
			value: "Some author"
		}
	]
});

// or using array as a parameter
// Format is [tag,ind1,ind2,sub1code,sub1value,sub2code,sub2value,...subNcode,subNvalue]
myRecord.insertField(["245","","", "a","The title of the book'","b","Some author"]});

Getters

Get array of controlfields:

myRecord.getControlfields();

Get array of datafields:

myRecord.getDatafields();

Record object has an attribute called fields which contains an array of it's fields:

myRecord.fields

Check if record is deleted:

myRecord.isDeleted()

Cloning a record

A deep copy of the record can be made by passing the fields from a record to the constructor of new record:

var deepClonedRecord = Record.clone(myRecord);

Record equality check

Record.isEqual(record1, record2); // true if records are deeply equal.

Alternative form for equality comparison:

record1.equalsTo(record2);

Simple assertions

Check if record contains a data field with specific value

record.containsFieldWithValue('245', 'b', 'Test field', 'c', 'Test content')

Check if record contains a control field with specific value

record.containsFieldWithValue('003', 'some value')

See also

To serialize marc records to other formats, see marc-record-serializers