# marc-record-js

> MARC record implementation in javascript

Latest version **0.3.2** (published 2017-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install marc-record-js
pnpm add marc-record-js
yarn add marc-record-js
bun add marc-record-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2017-06-07 |
| First published | 2015-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Pasi Tuominen |
| Maintainers | petuomin |

## Links

- npm: https://www.npmjs.com/package/marc-record-js
- Repository: https://github.com/petuomin/marc-record-js
- Homepage: https://github.com/petuomin/marc-record-js#readme
- Issues: https://github.com/petuomin/marc-record-js/issues
- npm.io page: https://npm.io/package/marc-record-js

## Recent versions

- 0.3.2 (latest) — 2017-06-07
- 0.3.1 — 2016-10-25
- 0.3.0 — 2016-10-25
- 0.2.0 — 2016-10-25
- 0.1.1 — 2015-08-13
- 0.1.0 — 2015-05-29

## README

# marc-record-js

[![Build Status](https://travis-ci.org/petuomin/marc-record-js.svg?branch=master)](https://travis-ci.org/petuomin/marc-record-js)
[![Code Climate](https://codeclimate.com/github/petuomin/marc-record-js/badges/gpa.svg)](https://codeclimate.com/github/petuomin/marc-record-js)
[![Test Coverage](https://codeclimate.com/github/petuomin/marc-record-js/badges/coverage.svg)](https://codeclimate.com/github/petuomin/marc-record-js/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](https://github.com/petuomin/marc-record-serializers)

---
_Source: https://npm.io/package/marc-record-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
