inline-critical
Advanced tools
Comparing version 5.1.2 to 5.1.3
{ | ||
"name": "inline-critical", | ||
"version": "5.1.2", | ||
"version": "5.1.3", | ||
"description": "Inline critical-path css and load the existing stylesheets asynchronously", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -30,12 +30,13 @@ const fs = require('fs'); | ||
const getPartials = (html = '', tag = 'svg') => { | ||
const indices = []; | ||
let start = html.indexOf(`<${tag}`, 0); | ||
let end = html.indexOf(`</${tag}>`, start) + `</${tag}>`.length; | ||
while (start >= 0) { | ||
indices.push({start, end}); | ||
start = html.indexOf(`<${tag}`, end); | ||
end = html.indexOf(`</${tag}>`, end) + `</${tag}>`.length; | ||
} | ||
const result = []; | ||
html.replace(new RegExp(`<${tag}(?:\\s[^>]+)?>`, 'ig'), (match, offset, str) => { | ||
if (match.includes('/>')) { | ||
result.push(str.substring(offset, offset + match.length)); | ||
} else { | ||
result.push(str.substring(offset, str.indexOf(`</${tag}>`, offset) + `</${tag}>`.length)); | ||
} | ||
return match; | ||
}); | ||
return indices.map(({start, end}) => html.substring(start, end)); | ||
return result; | ||
}; | ||
@@ -68,2 +69,3 @@ | ||
const jsdom = new JSDOM(html); | ||
const {window} = jsdom; | ||
@@ -97,3 +99,3 @@ const {document} = window; | ||
return result.replace(/^(\s*)(<\/\s*body>)/gim, `$1$1${this.noscript.join('\n$1$1')}\n$1$2`); | ||
return result.replace(/^([\s\t]*)(<\/\s*body>)/gim, `$1$1${this.noscript.join('\n$1$1')}\n$1$2`); | ||
} | ||
@@ -100,0 +102,0 @@ |
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
25528
516