GithubHelp home page GithubHelp logo

hsk81 / duke.js Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 2.0 1.35 MB

Duke.js: a minimal JavaScript interpreter

License: GNU General Public License v3.0

C 99.54% JavaScript 0.15% CMake 0.02% Makefile 0.06% C++ 0.22%
minimal javascript interpreter runtime engine

duke.js's Introduction

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

duke.js's People

Contributors

hsk81 avatar

Stargazers

 avatar

Watchers

James Cloos avatar Scotty Franzyshen avatar  avatar

Forkers

killvxk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.