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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yucho123987/lrc-parser

v1.0.0

Published

An LRC-format lyrics parser written in JavaScript that supports both Node.js and browser environments.

Downloads

161

Readme

lrc-parser

English | 简体中文
一个用 JavaScript 编写的 LRC 格式歌词解析器,同时支持 Node.js 和浏览器环境。

安装

npm install @yucho123987/lrc-parser

用法

引入

import { LrcParser } from "@yucho123987/lrc-parser";

初始化

var parser = new LrcParser();

你也可以传入一段 LRC 歌词字符串,LrcParser 会解析这段字符串:

var parser = new LrcParser(`
[00:16.000][00:31.154]Never gonna give you up
[00:16.000][00:31.154]永远不会放弃你
[00:21.154]Never gonna let you down
[00:21.154]永远不会让你失望
`);

API

parser.listLyrics()

作用:列出所有的歌词。
参数:无。
返回值:数组。该数组的元素均为对象,每个对象包含如下表所示的属性:
|属性|类型|说明| |-|-|-| |time|非负整数|时刻,单位为毫秒| |lyrics|字符串|歌词文本| |translation|字符串/null|歌词翻译文本|

示例:
打印所有的歌词:

let lyricsList = parser.listLyrics();
lyricsList.forEach(lyricsItem => {
  console.log(lyricsItem.lyrics + (lyricsItem.translation == null ? "" : "\n" + lyricsItem.translation));
});

parser.getLyrics(time)

作用:获取某个时刻对应的歌词。
参数: |参数|类型|说明| |-|-|-| |time|非负整数|时刻,单位为毫秒|

返回值:传入时刻存在对应的歌词时,返回一个对象,反之,则返回null。返回的对象包含如下表所示的属性: |属性|类型|说明| |-|-|-| |lyrics|字符串|歌词文本| |translation|字符串/null|歌词翻译文本|

示例:
打印1分54秒514毫秒(114514毫秒)时对应的歌词:

let lyricsInfo = parser.getLyrics(114514);
console.log(lyricsInfo.lyrics + (lyricsInfo.translation == null ? "" : "\n" + lyricsInfo.translation));

parser.updateLyrics(time, lyrics, translation = null)

作用:更新某个时刻所对应的的歌词和翻译。
参数: |参数|类型|说明 |-|-|-| |time|非负整数|时刻,单位为毫秒| |lyrics|字符串|歌词文本| |translation|字符串/null|歌词翻译文本|

返回值:undefined。
示例:
将1分54秒514毫秒(114514毫秒)时对应的歌词设置为“Never gonna give you up”:

parser.updateLyrics(114514, "Never gonna give you up");

将1分54秒514毫秒(114514毫秒)时对应的歌词设置为“Never gonna give you up”,并附上中文翻译“永远不会放弃你”:

parser.updateLyrics(114514, "Never gonna give you up", "永远不会放弃你");

parser.deleteLyrics(time)

作用:删除某个时刻所对应的歌词。
参数: |参数|类型|说明| |-|-|-| |time|非负整数|时刻,单位为毫秒|

返回值:若传入的时刻存在对应的歌词,则返回true,否则返回false。
示例:
删除1分54秒514毫秒(114514毫秒)时对应的歌词:

parser.deleteLyrics(114514);

parser.toString()

作用:将LrcParser对象转换成LRC歌词字符串。
参数:无。
返回值:字符串。
示例:
打印所有LRC格式歌词:

console.log(parser.toString());

parser.useTraditionalFormat = [value]

作用:设置是否以传统格式(一行只有一个时刻)输出LRC歌词。
参数: |参数|类型|说明| |-|-|-| |[value]|布尔值|是否以传统格式输出LRC歌词|

LrcParser.lrcTimeText2Millseconds(providedLrcTimeText)

作用:将LRC格式歌词中的时刻文本转换成毫秒。
参数: |参数|类型|说明| |-|-|-| |providedLrcTimeText|字符串|时刻文本| 返回值:非负整数。

LrcParser.millseconds2LrcTimeText(providedMillseconds)

作用:将非负整数类型的时刻转换成LRC时刻文本。
参数: |参数|类型|说明| |-|-|-| |providedMillseconds|非负整数|时刻| 返回值:字符串。