Git Product home page Git Product logo

bean's Introduction

Logo Bean-js

An esoteric byte-encoded code-golfing language derived from JavaScript

Install via npm:

npm install --save bean-js

Also works in-browser thanks to browserify and is ES5-compatible. Online interpreter available here.

Example usage:

<script src="js/bean.min.js"></script>
<script>
  var binary = bean.compile('[a+b,A+B,_,$]');
  var byteCount = binary.length;
  var source = bean.assemble(binary);
  var program = bean.program(binary);
  var input = '3\n4';
  var output = program(input);

  console.log(byteCount === 19);
  console.log(source === '[(a+b),(A+B),_,$,];');
  console.log(JSON.stringify(output) === '["34",7,["3","4"],[3,4]]');
</script>

Documentation

bean.compile(source)

Arguments

  • source An ASCII string containing valid JavaScript source: e.g. a function or variable declaration, expression, statement, or any combination thereof. An empty input string returns an empty output string.

Returns

  • binary An ISO8859-1 encoded binary string of equivalent Bean source.

Throws

  • Potentially any error throwable by babylon.parse(source)
  • RangeError if more than 32512 unique identifiers not listed in globals.json or identifiers.json are parsed from source.

bean.assemble(binary)

Arguments

  • binary An ISO8859-1 encoded binary string containing valid Bean source. An empty input string returns an empty output string.

Returns

  • source An ASCII string of equivalent JavaScript source.

Throws

  • RangeError if more than 32512 unique identifiers not listed in globals.json or identifiers.json are parsed from binary.

bean.program(binary)

Arguments

  • binary An ISO8859-1 encoded binary string containing valid Bean source. If an empty string is passed, the return value of the output function will be undefined, no matter what the input.

Returns

  • function program(stdin = "") {...} A function that optionally accepts standard line-separated input and implicitly initializes input before executing the Bean source. Returns the implicit output of the Bean source, which is the result of the last executed statement.

License

Copyright (c) 2017 Patrick Roberts

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.