css-absolute-values-to-px
Advanced tools
Comparing version 1.0.8 to 1.0.10
{ | ||
"name": "css-absolute-values-to-px", | ||
"version": "1.0.8", | ||
"version": "1.0.10", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "https://github.com/omateusanjos", |
@@ -7,16 +7,10 @@ const fs = require("fs").promises; | ||
const fileContent = await fs.readFile(filePath, "utf8"); | ||
const convertedContent = fileContent.replace( | ||
/(-?\b\d+(?:\.\d+)?\b)(?![\s\S]*["'])(?=[,;])/g, | ||
(_, value) => { | ||
// Check if the value is already wrapped in double quotes | ||
if (value.startsWith('"') && value.endsWith('"')) { | ||
return value; | ||
} else { | ||
return `"${value}px"`; | ||
} | ||
} | ||
); | ||
const modifiedContent = transformJavaScriptObjects(fileContent); | ||
await fs.writeFile(filePath, convertedContent); | ||
console.log(`File update: ${filePath}`); | ||
if (fileContent === modifiedContent) { | ||
return console.log(`File skipped: ${filePath}. Please, open a issue.`); | ||
} | ||
await fs.writeFile(filePath, modifiedContent); | ||
console.log(`File updated: ${filePath}`); | ||
} catch (error) { | ||
@@ -27,2 +21,13 @@ console.error(`Error converting ${filePath}: ${error}`); | ||
function transformJavaScriptObjects(fileContent) { | ||
const objectPattern = /({[^{}]*})/g; | ||
return fileContent.replace(objectPattern, (match) => { | ||
return match.replace( | ||
/(-?\b\d+\b)(?![\s\S]*["'])(?=:|\s*[;,}])/g, | ||
(_, value) => `"${value}px"` | ||
); | ||
}); | ||
} | ||
async function processDirectory( | ||
@@ -29,0 +34,0 @@ directoryPath, |
4555
85