genius-lyrics-ts
Advanced tools
Comparing version 0.0.29 to 0.0.30
@@ -45,2 +45,12 @@ "use strict"; | ||
}; | ||
function decodeHTMLEntities(element, str) { | ||
if (str && typeof str === "string") { | ||
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gim, ""); | ||
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gim, ""); | ||
element.innerHTML = str; | ||
str = element.textContent; | ||
element.textContent = ""; | ||
} | ||
return str; | ||
} | ||
@@ -59,3 +69,4 @@ // src/utils/extractsLyrics.ts | ||
if (elem && elem.textContent?.length !== 0) { | ||
let snippet = elem.innerHTML?.replace(/<br>/g, "\n").replace(/<(?!\s*br\s*\/?)[^>]+>/gi, "").replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gim, ""); | ||
let snippet = elem.innerHTML?.replace(/<br>/g, "\n").replace(/<(?!\s*br\s*\/?)[^>]+>/gi, ""); | ||
snippet = decodeHTMLEntities(elem, snippet); | ||
lyrics += snippet; | ||
@@ -62,0 +73,0 @@ htmlDocument.querySelector("textarea")?.textContent + "\n\n"; |
{ | ||
"name": "genius-lyrics-ts", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"description": "Get lyrics from genius with Typescript, Javascript, or Node", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
import { parse } from "node-html-parser"; | ||
import { decodeHTMLEntities } from "."; | ||
@@ -24,4 +25,4 @@ /** | ||
?.replace(/<br>/g, "\n") | ||
.replace(/<(?!\s*br\s*\/?)[^>]+>/gi, "") | ||
.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gim, ""); | ||
.replace(/<(?!\s*br\s*\/?)[^>]+>/gi, ""); | ||
snippet = decodeHTMLEntities(elem, snippet); | ||
lyrics += snippet; | ||
@@ -28,0 +29,0 @@ htmlDocument.querySelector("textarea")?.textContent + "\n\n"; |
@@ -0,1 +1,3 @@ | ||
import { HTMLElement } from "node-html-parser"; | ||
export type Options = { | ||
@@ -34,1 +36,14 @@ apiKey: string; | ||
}; | ||
export function decodeHTMLEntities(element: HTMLElement, str: string) { | ||
if (str && typeof str === "string") { | ||
// strip script/html tags | ||
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gim, ""); | ||
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gim, ""); | ||
element.innerHTML = str; | ||
str = element.textContent as string; | ||
element.textContent = ""; | ||
} | ||
return str; | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15561
367