Skip to content

Instantly share code, notes, and snippets.

@askucher
Last active December 27, 2015 18:09
Show Gist options
  • Save askucher/7367389 to your computer and use it in GitHub Desktop.
Save askucher/7367389 to your computer and use it in GitHub Desktop.
Trick which allow to convert SASS to SCSS
function indentToBraces(input){
var p = require("prelude-ls"); //http://preludels.com/
var lines, i, idx, j, braces, bracesString;
if (input != null) {
lines = p.map(function(it){
var m;
m = it.match(/^\s+/);
return {
i: m != null ? m[0].length : 0,
c: it
};
})(
input.split('\n'));
for (i in lines) {
idx = parseInt(
i);
if (lines[idx].c.match(/[a-z]+/)) {
j = p.last(
p.map(fn$)(
p.takeWhile(fn1$)(
p.drop(idx + 1)(
lines))));
if (j != null) {
lines[idx].c += '{';
lines[j].c += '}';
} else {
braces = lines[idx].c.match(/\}+/);
bracesString = braces ? braces[0] : "";
lines[idx].c = lines[idx].c.replace(/\}+/, '') + ';' + bracesString;
}
}
}
return p.join('\n')(
p.map(function(it){
return it.c;
})(
lines));
}
function fn$(it){
return lines.indexOf(it);
}
function fn1$(it){
return it.i > lines[i].i;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment