Nothing Special   »   [go: up one dir, main page]

Skip to content

A lightly module for LRC format string parsing and serialization

License

Notifications You must be signed in to change notification settings

pandaGao/lrc.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lrc.js

npm version Build Status Coverage Status JavaScript Style Guide

A lightly module for LRC format string parsing and serialization

Install

From npm

npm i lrc.js --save

In browser

<script src="https://unpkg.com/lrc.js/dist/lrc.js"></script>

<script src="https://unpkg.com/lrc.js/dist/lrc.min.js"></script>

Usage

LRC.Parse(lrc = '')

const LRC = require('lrc.js')
// ...
let lyrics = LRC.parse(LRCString)
// or let lyrics = new LRC(LRCString)

lyrics.clone(obj)

deep clone a lyrics object or plain object

let lyrics = LRC.parse(LRCString)
let lyrics2 = new LRC().clone(lyrics)

lyrics.toJSON()

let lyrics = LRC.parse(LRCString)
lyrics.toJSON()

// Sample output
{
  al: '',
  ar: '',
  au: '',
  ti: '',
  by: '',
  offset: 0,
  length: '',
  re: '',
  ve: '',
  lines: [
    {
      time: 0,
      text: 'xxx'
    }
  ]
}

lyrics.stringify(timeFixed = 2)

let lyrics = LRC.parse(`[00:00:01]Test Line`)
lyrics.stringify()
// Output
"[00:00:01]Test Line"
lyrics.stringify(3)
// Output
"[00:00:010]Test Line"

lyrics.findIndex(currentTime)

let lrc =`
[00:01.00] Line 1
[00:03.00] Line 3
[00:05.70] Line 5
[00:02.00][00:04.00] Line 2 & Line 4
`
let lyrics = LRC.parse(lrc)
lyrics.findIndex(0) // -1
lyrics.findIndex(1.5) // 0
lyrics.findIndex(5) // 3
lyrics.findIndex(6) // 4

lyrics.previousLine(currentTime)

// ...
lyrics.previousLine(0) // null
lyrics.previousLine(1.5) // null
lyrics.previousLine(2.5)
// Output
{
  idx: 0,
  time: 1,
  text: 'Line 1'
}

lyrics.currentLine(currentTime)

// ...
lyrics.currentLine(0) // null
lyrics.currentLine(1.5) 
// Output
{
  idx: 0,
  time: 1,
  text: 'Line 1'
}

lyrics.currentLine(10)
// Output
{
  idx: 4,
  time: 5.7,
  text: 'Line 5'
}

lyrics.nextLine(currentTime)

// ...
lyrics.nextLine(0)
// Output
{
  idx: 0,
  time: 1,
  text: 'Line 1'
}

lyrics.nextLine(1.5)
// Output
{
  idx: 1,
  time: 2,
  text: 'Line 2 & Line 4'
}

lyrics.nextLine(6) // null

About

A lightly module for LRC format string parsing and serialization

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published