Skip to content

Instantly share code, notes, and snippets.

View LabiKyo's full-sized avatar
🎯
Focusing

Labi Kyo LabiKyo

🎯
Focusing
View GitHub Profile
@LabiKyo
LabiKyo / less2stylus.coffee
Created October 7, 2012 14:38 — forked from lancejpollard/less2stylus.coffee
Convert Less to Stylus for general purpose
less2stylus = (string) ->
string = string
.replace(/^(\ *)(.+)\ +\{\ *\n?\ */mg, "$1$2\n$1 ") # remove opening brackets
.replace(/^(\ *)([^\ \n]+)\ +\{\ *\n?\ */mg, "$1$2\n$1 ") # remove opening brackets
.replace(/\ *\{\ *\n*/g, "\n") # remove opening brackets again (some random cases I'm too lazy to think through)
.replace(/\ *\}\ *\n*/g, "\n") # remove closing brackets
.replace(/\;\ *?$/gm, "") # remove semicolons
.replace(/@(\w+):(\ *)\ /g, (_, $1, $2) -> # replace @variable: with $variable =
"$#{$1}#{$2} = "
)