node package manager
Don’t reinvent the wheel. Reuse code within your team. Create a free org »

caffeine-script

logo

Do More with Less Build Status NPM version

CaffeineScript is an open-source programming language that compiles to JavaScript. The goal is to minimize total effort, over a product's lifetime, for the entire team. Design thinking is essential for achieving that goal. That means user-experience and graphic design are as important as computer-science and software engineering. A well-designed language makes code more beautiful, programming more fun, and, ultimately, lets us get more done with less effort.

CaffeineScript starts where CoffeeScripts left off, fixing its shortcomings and taking a big step forward for high-productivity javascript. Two concrete examples: improved React-style programming and 90% reduced module-specific code. The result is a lean, high-level language that empowers you to get the most out of JavaScript.

Example

logo

Related: ArtSuite

Live Demo

A brief, interactive slideshow written in CaffeineScript

Status: BETA

CaffeineScript is working and usable. The semantics are still shifting as I implement the remaining, planned v1 features.

Install

npm install caffeine-script

Learn More

Contribute

More Examples

React and Declarative Programming
# CaffeineScript - 27 tokens and 0 must-match-tokens 
import &ArtSuite
 
class Login extends Component
 
  render: ->
    Element
      TextElement
        text: :username
        size: ww: 1hch: 1
 
      TextInput
        placeholder: "" enter username here
        size: ww: 1hch: 1
// JavaScript - 73 tokens including 28 must-match-tokens
let {
  Component,
  Element,
  TextElement,
  TextInput
} = require('art-suite');
 
module.exports = class Login extends Component {
  render() {
    return Element(
      TextElement({
        text: 'username',
        size: {ww: 1, hch: 1}
      }),
 
      TextInput({
        placeholder: 'enter username here',
        size: {ww: 1, hch: 1}
      })
    );
  };
};
Implicit Array and Object literals
# CaffeineScript - 20 tokens 
1d: 1 2 3 4 5 6 7 8 9
 
2d:
  1 2 3
  4 5 6
  7 8 9
// JavaScript - 54 tokens
{
  "1d": [1, 2, 3, 4, 5, 6, 7, 8, 9],
  "2d": [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
};
# CaffeineScript - 18 tokens 
users =
  id: 123 username: :shanebdavis born: 1976 fullName: "" Shane Brinkman-Davis Delamore
  id: 456 username: :alanturing  born: 1912 fullName: "" Alan Turing
// JavaScript - 35 tokens
let users = [
  {id: 123, username: "shanebdavis", born: 1976, "Shane Brinkman-Davis Delamore"},
  {id: 456, username: "alanturing",  born: 1912, "Alan Turing"}
];
#hashStrings, :wordStrings, and 10unitStrings
# CaffeineScript - 15 tokens 
nameToColor:
  red:   #f00 
  green: #0f0 
 
colorToName:
  #f00:  :red 
  #0f0:  :green 
 
style:
  fontSize: 12pt
  padding:  25px
// JavaScript - 40 tokens
{
  nameToColor: { red:      "#f00", green:   "#0f0"  },
  colorToName: { "#f00":   "red",  "#0f0":  "green" },
  style:       { fontSize: "12pt", padding: "25px"  }
};
Comprehensions and Iteration
# CaffeineScript 
fontProps = object valuekey from allProps when /^font/.test key
// JavaScript
var fontProps = {}, key, value;
 
for (key in allProps) {
  value = allProps[key];
  if (/^font/.test(key)) {
    fontProps[key] = value;
  }
}

CaffeineScript and CoffeeScript

I owe a debt of gratitude to Jeremy Ashkenas and the CoffeeScript community. It is my primary inspiration, and what the CaffeineScript compiler was originally written in. More on inspirations from CoffeeScript: Coming from CoffeeScript.