1.0.2 • Published 5 years ago
parse-refresh-redirect v1.0.2
parse-refresh-redirect
Parse HTML with parse5 and return a redirect URL if one is defined in the content attribute of a <meta http-equiv="refresh"/> element.
Features
Installation
npm install parse-refresh-redirector
yarn add parse-refresh-redirectUsage
API
const parseURL = require('parse-refresh-redirect');parseURL(html)
Parse HTML string and return redirect URL string or undefined.
Examples
const html = `
<html>
<head>
<meta http-equiv="refresh" content="0; url=https://example.com/foo.html" />
</head>
</html>
`;
const url = parseURL(html);
// url === 'https://example.com/foo.html'const html = `
<html>
<head>
<meta http-equiv="refresh" content="5" />
</head>
</html>
`;
const url = parseURL(html);
// url === undefinedconst html = `
<html>
<head>
<title>Test</test>
</head>
</html>
`;
const url = parseURL(html);
// url === undefinedCLI
The CLI will parse HTML input from stdin and output the redirect URL if found (it will output nothing if no URL was found).
# HTML from local file
cat index.html | parse-refresh-redirect
# HTML from URL
curl -s "https://adamjarret.github.io" | parse-refresh-redirectIf parse-refresh-redirect is not installed globally, run it with npx (ex. cat index.html | npx parse-refresh-redirect).
The exit code will be 0 if the URL was found, otherwise 1.
The CLI takes no options.