duke.js

0.7.9 • Public • Published

NPM version Build Status

Duke.js: a minimal JavaScript interpreter

Duke.js is a minimal JavaScript interpreter, which has been build with Duktape – an embeddable and portable Javascript engine with a compact footprint. The duke interpreter consumes JavaScript code from a file or the standard input and then evaluates it.

Prerequisites

Name            : cmake
Version         : 3.14.5-1
Description     : A cross-platform open-source make system
URL             : https://www.cmake.org/

Installation

$ npm install duke.js --global

Usage

Running Scripts

$ duke ./a-script.js
$ duke < ./a-script.js

Doing Arithmetic

$ echo "console.log(1/0)" | duke
Infinity

Using Functions

$ echo "function id(a) { return a; }; console.log(id(1))" | duke
1

Console Logging

$ echo "console.log('message')" | duke
message
$ echo "console.error('message')" | duke
Error: message

Throwing Errors

$ echo "throw new Error('message')" | duke
Error: message

Requiring JSON

$ cat ./data.json
[{"0": null, "1": "1", "2": 2}]
$ echo "console.log(require('./data.json'))" | duke
[{"0":null,"1":"1","2":2}]

Requiring Modules

$ cat ./stdout.js
module.exports = console.log
$ echo "require('./stdout.js')('message')" | duke
message

Reading Input

$ cat ./stdin.js
require('/dev/stdin')
$ echo "console.log('message')" | duke ./stdin.js
message

Development

Cleaning

$ npm run clean

Building

$ npm run build

Running

$ RUN_ARGS=$PWD/test/boolean/true.js npm start
$ npm start < ./test/boolean/true.js

Testing

$ npm test

Copyright

© 2019 Hasan Karahan

Package Sidebar

Install

npm i duke.js

Weekly Downloads

7

Version

0.7.9

License

ISC

Unpacked Size

4.01 MB

Total Files

27

Last publish

Collaborators

  • hsk81