openlyrics-parser
Version:
Parses and extracts data from OpenLyrics files, and creates them!
82 lines (63 loc) • 2.59 kB
Markdown
[](https://github.com/ChrisMBarr/OpenLyrics-parser/releases/latest)
[](https://openlyrics.org/) is an open XML file format for storing song and lyric information about songs.
This project will parse and extract data from OpenLyrics XML files written in OpenLyrics version 0.8 and 0.9, and it can create OpenLyrics 0.9 formatted documents.
This project is used by my [LyricConverter](htt://github.com/ChrisMBarr/LyricConverter) project which can convert your song lyric files between many common formats. If you need to convert some songs to another existing format I encourage you to check this project out first.
```txt
npm install openlyrics-parser --save
```
Simply import `OpenLyricsParser`, then pass the contents of an OpenLyrics XML file as a string to it.
```typescript
import { readFile } from 'fs';
import { OpenLyricsParser, IParserRoot } from 'openlyrics-parser';
readFile('example.xml', (contents): void => {
const song: IParserRoot = OpenLyricsParser(contents.toString());
console.log(song);
});
```
```javascript
const { readFile } = require('fs');
const { OpenLyricsParser } = require('openlyrics-parser');
readFile('example.xml', (contents) => {
const song = OpenLyricsParser(contents.toString());
console.log(song);
});
```
Simply import `OpenLyricsBuilder`, then pass the song data to it, and it will return a `string` of XML data which you can then do what you need to with it.
```typescript
import { OpenLyricsBuilder, IBuilderOptions } from 'openlyrics-parser';
const opts: IBuilderOptions = {
properties: { titles: 'Amazing Grace' },
verses: [
{
name: 'v1',
lines: ['Amazing grace how sweet the sound', 'that saved a wretch like me'],
},
],
};
const xmlDoc: string = OpenLyricsBuilder(opts);
console.log(xmlDoc);
```
```javascript
const { OpenLyricsBuilder } = require('openlyrics-parser');
const opts = {
properties: { titles: 'Amazing Grace' },
verses: [
{
name: 'v1',
lines: ['Amazing grace how sweet the sound', 'that saved a wretch like me'],
},
],
};
const xmlDoc = OpenLyricsBuilder(opts);
console.log(xmlDoc);
```