JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q39835F

CoffeeScript with asynchronous syntax and additional features

Package Exports

  • toffee-script

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (toffee-script) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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

Code Examples

Left: ToffeeScript

Right: Generated JavaScript

Basic

x, y = a! b
console.log x, y
var x, y,
  _this = this;

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

### Condition

if i
  x = a!
else
  y = b!
console.log x, y
var x, y, _$$_0,
  _this = this;

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

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

### Loop Support For In, For Of, While with guard `when`

xs = for i in [1..3] when i > 2
  a!
var i, xs,
  _this = this;

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

### Mathematics

x = a! + b! * c!
var x,
  _this = this;

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

### Object

A =
  a: a
  b: b!
  c: c
var A,
  _this = this;

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

### Logical Support `||`, `&&`, `?`, `&&=`, `||=`, `?=`

x = a! || b!
console.log x
var x,
  _this = this;

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

### Auto Callback

a = (autocb) -> return 3
var a;

a = function(autocb) { return autocb(3); };

Return Multiple Values

a = (autocb) -> return null, 3
var a;

a = function(autocb) { return autocb(null, 3); };

### Regexp

if a =~ b || b =~ c
  \~
  \&
  \0
  \9
var __matches;

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