npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

toffee-script

v1.6.3-5

Published

CoffeeScript with asynchronous syntax and additional features

Downloads

37

Readme

ToffeeScript

ToffeeScript is a CoffeeScript dialect with Asynchronous Grammar

Features

  1. Asynchronous everywhere
    • Condition: If, Switch
    • Loop: For In, For Of, While with guard when
    • Mathematics
    • Logical Operation
  2. Auto Callback
  3. Regexp Operator =~ and matches \~, \&, \0~\9
  4. High efficent code generated.
  5. Sourcemap Supported.
    • Follow up to CoffeeScript 1.6.2 so far
  6. Safety named-function supported.
    • Added in ToffeeScript 1.6.2-3

Installation

npm install toffee-script

Named Function

ToffeeScript support named function which is different from CoffeeScript. if the function defined in the first level of code block and the function name haven't been used, then compile it as named function. see Code Examples section It won't have compatible issue with CoffeeScript except one case

# m never declared above, m must be local variable and assign to undefined
m()
m = ->
m

in CoffeeScript will throw exception undefined is not function. Use m as constant undefined variable is rare case.

in ToffeeScript function m is hoisted, and will run function m() as Javascript does.

Code Examples

Left: ToffeeScript

Right: Generated JavaScript

Basic

a(b, function() { x = arguments[0], y = arguments[1]; return console.log(x, y); });

with powerful CoffeeScript assignment [...]

a(b, function() { _this.x = arguments[0], y = 2 <= arguments.length ? __slice.call(arguments, 1) : []; return console.log(_this.x, y); });

Condition

if (i) { a(function() { x = arguments[0]; _$$_0(); }); } else { b(function() { y = arguments[0]; _$$_0(); }); }

function _$$_0() { return console.log(x, y); };

Async in condition

a(function() { _$cb$_2(e = arguments[0]); }); function _$cb$2($$0) { if ($$_0) { return cb(e); } else { _$$_1(); } function _$$_1() { return foo(); }; };

Async in condition with multi return

Async call always return first argument

fs.readFile('foo', function() { _$cb$_2((e = arguments[0], data = arguments[1], e)); }); function _$cb$2($$0) { if ($$_0) { return cb(e); } else { _$$_1(); } function _$$_1() { return console.log(data); }; };

Loop

Support For In, For Of, While with guard when

_$res$_1 = []; i = _i = 1; function _step() { i = ++_i; _body(); }; function _body() { if (i <= 3) { if (i > 2) { a(function($$_2) { step($res$1.push($$_2)); }); } else { _step(); } } else { _done(); } }; function _done() { _$cb$0($res$_1); }; _body(); function _$cb$_0() { return xs = arguments[0]; };

Mathematics

a(function(_$$1) { b(function($$3) { c(function($$_4) { _$cb$2($$_3 * _$$_4); }); }); function _$cb$2($$_5) { _$cb$0($$_1 + _$$_5); }; }); function _$cb$_0() { return x = arguments[0]; };

Object

_$$1 = a; b(function($$_2) { _$cb$_0({ a: _$$_1, b: _$$_2, c: c }); }); function _$cb$_0() { return A = arguments[0]; };

Logical

Support ||, &&, ?, &&=, ||=, ?=

a(function(_$$1) { if ($$_1) { _$cb$3($$1); } else { b(function($$_2) { _$cb$3($$_2); }); } }); function _$cb$3($$_4) { _$cb$0($$_4); }; function _$cb$_0() { x = arguments[0]; return console.log(x); };

Auto Callback

Return Multiple Values

Autocb with default args

Regexp

if ((__matches = a.match(b)) || (__matches = b.match(c))) { __matches; __matches[0]; __matches[0]; __matches[9]; }

Named Function Supported

function b() {};

null;

Those cases will be kept in non-named function

f = null;

if (a) { b = c(function() {}); }

d(e = function() {});

f = function() {};

null;