parse-static-imports
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -10,9 +10,10 @@ "use strict"; | ||
const importIdx = str.indexOf("import"); | ||
const quoteIdx = str.replace(/(\'|\`)+/gm, '"').indexOf('"'); // eslint-disable-line no-useless-escape | ||
const normalized = str.replace(/(\'|\`)+/gm, '"'); // eslint-disable-line no-useless-escape | ||
const semiColonIdx = str.indexOf(";"); | ||
const startQuoteIdx = normalized.indexOf('"'); | ||
const endQuoteIdx = normalized.indexOf('"', startQuoteIdx + 1); | ||
const startIdx = importIdx >= 0 ? importIdx + 6 : 0; | ||
const betweenImportAndQuote = str.substring(startIdx, quoteIdx).trim(); | ||
const sideEffectOnly = semiColonIdx >= 0 && betweenImportAndQuote.length === 0; | ||
const betweenImportAndQuote = str.substring(startIdx, startQuoteIdx).trim(); | ||
const sideEffectOnly = startQuoteIdx >= 0 && endQuoteIdx >= 0 && betweenImportAndQuote.length === 0; | ||
return str.includes("from") || sideEffectOnly; | ||
} |
@@ -12,10 +12,10 @@ "use strict"; | ||
const importIdx = normalized.indexOf("import"); | ||
const quoteIdx = normalized.indexOf('"'); | ||
const semiColonIdx = normalized.indexOf(";"); | ||
const startQuoteIdx = normalized.indexOf('"'); | ||
const endQuoteIdx = normalized.indexOf('"', startQuoteIdx + 1); | ||
if (importIdx < 0 || semiColonIdx < 0 || quoteIdx < 0) { | ||
if (importIdx < 0 || startQuoteIdx < 0 || endQuoteIdx < 0) { | ||
return ""; | ||
} | ||
return normalized.substring(quoteIdx, semiColonIdx).replace(/(\;|\"|\s)+/gm, ""); // eslint-disable-line no-useless-escape | ||
return normalized.substring(startQuoteIdx, endQuoteIdx).replace(/(\"|\s)+/gm, ""); // eslint-disable-line no-useless-escape | ||
} |
{ | ||
"name": "parse-static-imports", | ||
"description": "Gracefully parse ECMAScript static imports 💃", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": "Cody A Price <dev.cprice@gmail.com>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
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
14003
151