@lrc-maker/lrc-parser
Advanced tools
Comparing version 0.0.1 to 0.1.0
@@ -16,3 +16,10 @@ declare global { | ||
}>; | ||
export declare const parser: (lrcString: string) => Readonly<{ | ||
export declare type TrimOptios = Partial<{ | ||
trimStart: boolean; | ||
trimEnd: boolean; | ||
}>; | ||
export declare const parser: (lrcString: string, option?: Partial<{ | ||
trimStart: boolean; | ||
trimEnd: boolean; | ||
}>) => Readonly<{ | ||
info: Map<string, string>; | ||
@@ -19,0 +26,0 @@ lyric: Readonly<ILyric>[]; |
@@ -1,2 +0,3 @@ | ||
export const parser = (lrcString) => { | ||
export const parser = (lrcString, option = {}) => { | ||
const { trimStart = false, trimEnd = false } = option; | ||
const lines = lrcString.split(/\r\n|\n|\r/); | ||
@@ -39,2 +40,12 @@ const timeTag = /\[\s*(\d{1,3}):(\d{1,2}(?:[:.]\d{1,3})?)\s*]/y; | ||
} | ||
if (trimStart || trimEnd) { | ||
lyric.forEach((line) => { | ||
if (trimStart) { | ||
line.text = line.text.trimStart(); | ||
} | ||
if (trimEnd) { | ||
line.text = line.text.trimEnd(); | ||
} | ||
}); | ||
} | ||
return { info, lyric }; | ||
@@ -41,0 +52,0 @@ }; |
{ | ||
"name": "@lrc-maker/lrc-parser", | ||
"description": "lrc-parser for lrc-maker", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"repository": "https://github.com/magic-akari/lrc-maker.git", | ||
@@ -6,0 +6,0 @@ "author": "阿卡琳 <hufan.akarin@Gmail.com>", |
@@ -21,3 +21,10 @@ declare global { | ||
export const parser = (lrcString: string): State => { | ||
export type TrimOptios = Partial<{ | ||
trimStart: boolean; | ||
trimEnd: boolean; | ||
}>; | ||
export const parser = (lrcString: string, option: TrimOptios = {}): State => { | ||
const { trimStart = false, trimEnd = false } = option; | ||
const lines = lrcString.split(/\r\n|\n|\r/); | ||
@@ -76,2 +83,13 @@ | ||
if (trimStart || trimEnd) { | ||
lyric.forEach((line) => { | ||
if (trimStart) { | ||
line.text = line.text.trimStart(); | ||
} | ||
if (trimEnd) { | ||
line.text = line.text.trimEnd(); | ||
} | ||
}); | ||
} | ||
return { info, lyric }; | ||
@@ -78,0 +96,0 @@ }; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
15206
268