Skip to content

Instantly share code, notes, and snippets.

@msyfls123
Created April 9, 2024 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msyfls123/12f3cdd1827ea4649cbb565f866d329c to your computer and use it in GitHub Desktop.
Save msyfls123/12f3cdd1827ea4649cbb565f866d329c to your computer and use it in GitHub Desktop.
// https://regex101.com/r/30Xvde/1
const fs = require('fs')
const VAR_REG = /(?:@extend\s.\\@|&:extend\(\.\\@|@extend\s.\\\$)([^\;\r\n\t\s\)]+)/gm;
const sassInput = fs.readFileSync('style/style.scss', 'utf-8');
const lessInput = fs.readFileSync('style/style.less', 'utf-8');
const stylusInput = fs.readFileSync('style/style.styl', 'utf-8');
function getVariables(input) {
return Array.from(input.matchAll(VAR_REG)).map(([, key]) => key);
}
[sassInput, lessInput, stylusInput].map(getVariables).forEach((v) => console.log(v));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment