Registry / serialization / decafjs

decafjs

JSON →
library0.6.2jsnpmunverified

A CoffeeScript to ES6 transpiler that leverages the CoffeeScript compiler to produce modern JavaScript syntax. Stable version 0.6.2 is available on npm. Unlike other transpilers, Decaf uses the official CoffeeScript parser to build an AST and then maps it to ES6 constructs, falling back to original CoffeeScript output for unsupported syntax. It can be used as a CLI tool or as a Node module with jscodeshift for code transforms. Development appears to be in maintenance mode with limited recent updates.

npm install decafjs
INSTALL
IMPORT
SIG · DECAFJS
D
decafjs
serializationjavascriptv0.6.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ const decaf = require('decafjs');
✗ import decaf from 'decafjs';
Package does not provide ES module exports; use CommonJS require.
compile
✓ const decaf = require('decafjs'); decaf.compile('()-> alert "hello"');
✗ import { compile } from 'decafjs';
The module exports a single function object; compile is a property, not a named export.
compileFile
✓ const decaf = require('decafjs'); decaf.compileFile('file.coffee');
✗ const { compileFile } = require('decafjs');
Not available as named export; the main default export contains all methods.

Demonstrates basic usage: compile CoffeeScript string and file to ES6 JavaScript using Decaf.

const decaf = require('decafjs'); const path = require('path'); const fs = require('fs'); // Compile a CoffeeScript string to ES6 JS const coffeeCode = 'square = (x) -> x * x'; const es6Code = decaf.compile(coffeeCode); console.log(es6Code); // outputs: var square = (x) => x * x; // Compile a file (assuming example.coffee exists) const filePath = path.join(__dirname, 'example.coffee'); const coffeeFromFile = fs.readFileSync(filePath, 'utf8'); const jsFromFile = decaf.compile(coffeeFromFile, { tabWidth: 2 }); fs.writeFileSync('example.js', jsFromFile); console.log('Compiled successfully!');
decafjs --version
Debug
Known issues
gotchaThe package name on npm is 'decafjs', not 'decaf'. Using 'npm install decaf' installs a different unrelated package.
fix
Install with 'npm install decafjs'.
affects: all
gotchaThe exported object is the compile function itself; you cannot destructure named exports like { compile }.
fix
Use: const decaf = require('decafjs'); then decaf.compile(...).
affects: all
deprecatedPackage has not been updated since 2018; may not support latest CoffeeScript or ES6 features.
fix
Consider alternatives like decaffeinate (more actively maintained).
affects: 0.6.2
gotchaWhen used as CLI globally, command is 'decaf' not 'decafjs'. Ensure global install.
fix
Run: npm install -g decafjs; then decaf <file or directory>.
affects: all
Errors
Common errors & fixes
Error: Cannot find module 'coffee-script'
Missing peer dependency coffee-script / coffeescript.
fix
Install: npm install coffeescript (or coffee-script for older versions).
TypeError: decaf.compile is not a function
Incorrect import/require: probably using import or destructuring.
fix
Use: const decaf = require('decafjs'); decaf.compile(...);
SyntaxError: Unexpected token while parsing CoffeeScript
Input contains unsupported CoffeeScript syntax or invalid input.
fix
Check source for syntax errors; Decaf falls back to original CoffeeScript output, but invalid syntax will still break.
Upgrade
Version history
0.6.2latest on npm
Audit
Dependencies
coffeescriptrequiredCore dependency for parsing CoffeeScript syntax
ast-typesrequiredBuilds esprima-compatible syntax tree from CoffeeScript AST
recastrequiredUsed for printing JavaScript AST to code
Agent activity
9 hits · last 30 days
node
8
Resources
decafjs — npm install decafjs · libregistry