Showing posts with label coffeescript. Show all posts
Showing posts with label coffeescript. Show all posts

Thursday, November 3, 2011

String trimming in Javascript

Here is a simple trim function to remove leading and trailing whitespaces.

function trim(s) {
return s.replace(/^\s*|\s*$/g, '');
}

and in CoffeeScript
trim = (s) ->
s.replace /^\s*|\s*$/g, ''


You can check Steven Levithan's collection of trim functions.

Sunday, February 13, 2011

CoffeeScript Syntax Checker Textmate Bundle

Here is a rudimentary version of my CoffeeScript bundle that performs a quick syntax check.
You can bind this command to CMD + S, so it runs after save.

CoffeeScript-Syntax-Checker-Textmate-Bundle on Github

Building CoffeeScript from source

CoffeeScript includes a simple build system similar to Make and Rake. Naturally, it's called Cake, and is used for the build and test tasks for the CoffeeScript language itself.

git clone https://github.com/jashkenas/coffee-script.git
cd coffee-script

To build the whole system
bin/cake build:full

To build the script for inclusion in the browser
bin/cake build:browser
or
MINIFY=false bin/cake build:browser


you may need to install uglify-js as well
npm install uglify-js