Skip to content

Instantly share code, notes, and snippets.

@emilkaiser
Created October 17, 2013 07:51
Show Gist options
  • Save emilkaiser/7020813 to your computer and use it in GitHub Desktop.
Save emilkaiser/7020813 to your computer and use it in GitHub Desktop.
Custom javascript function in less
/**
* node less-custom.js
* --> .class{width:2;height:olleh}
*/
var less = require('less.js/lib/less');
less.tree.functions.reverse = function (args) {
return new(less.tree.Anonymous)(new(less.tree.Anonymous)(args.value.split("").reverse().join("")));
}
var parser = new(less.Parser)();
parser.parse('.class { width: (1 + 1); height: reverse("hello") }', function (e, tree) {
var css = tree.toCSS({ compress: true }); // Minify CSS output
console.log(css);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment