JavaScript with no limits ๐Ÿคซ

Overview

Goldstein License NPM version Build Status Coverage Status

image

"You haven't a real appreciation of Newspeak, Winston," he said almost sadly. "Even when you write it you're still thinking in Oldspeak. I've read some of those pieces that you write in The Times occasionally. They're good enough, but they're translations. In your heart you'd prefer to stick to Oldspeak, with all its vagueness and its useless shades of meaning. You don't grasp the beauty of the destruction of words. Do you know that Newspeak is the only language in the world whose vocabulary gets smaller every year?"

(c) โ€œ1984โ€, George Orwell

JavaScript with no limits ๐Ÿคซ .

Language ruled by the users, create an issue with ideas of a new language construction and what is look like in JavaScript, and most likely we implement it :).

Install

npm i goldstein -g

CLI

$ cat > 1.gs
export fn hello() {
    return 'world';
}

$ gs 1.gs
$ cat 1.js
// ~1.js
function hello() {
  return "world";
}
export {
  hello
};

API

import {compile} from 'goldstein';

compile(`
    fn hello() {
        guard text !== "world" else {
            return ""
        }
        
        return "Hello " + text
    }
`);
// returns
`
function hello() {
    if (!(text !== 'world')) {
        return '';
    }
    
    return 'Hello ' + text;
}
`;

Keywords

Goldstein is absolutely compatible with JavaScript, and it has extensions. Here is the list.

fn

You can use fn to declare a function:

fn hello() {
    return 'world';
}

This is the same as:

function hello() {
    return 'world';
}

guard

Applies not to IfCondition:

fn hello() {
    guard text !== "world" else {
        return ""
    }

    return "Hello " + text
}

Is the same as:

function hello() {
    if (!(text !== 'world')) {
        return '';
    }
    
    return 'Hello ' + text;
}

try

try can be used as an expression.

Applies tryCatch:

const [error, result] = try hello(1, 2, 3);

Is the same as:

import tryCatch from 'try-catch';
const [error, result] = tryCatch(1, 2, 3);

and

const [error, result] = try await hello(1, 2, 3);

Is the same as:

import tryToCatch from 'try-catch';
const [error, result] = await tryToCatch(1, 2, 3);

should

should can be used as an expression (just like try). This keyword is useful if you want to prevent a function call (also async) to throw an error because you don't need to have any result and the real execution is just optional (so runs if supported).

should hello()

Is the same as:

try hello();

โ˜๏ธ Warning: this feature can be helpful but also dangerous especially if you're debugging your application. In fact, this is made to be used as an optional function call (ex. should load content, but not necessary and knowing this feature is optional), if you call a function in this way while debugging, no error will be printed and the application will continue run as nothing happened.

freeze

You can use freeze instead of Object.freeze() like that:

freeze {
    'example': true
}

Is the same as:

Object.freeze({
    example: true,
});

if

You can omit parens. But you must use braces in this case.

if a > 3 {
    hello();
}

throw expression

You can use throw as expression, just like that:

const a = () => throw 'hello';

Curry

Similar to partial application:

const sum = (a, b) => a + b;
const inc = sum~(1);

inc(5);
// returns
6

How to contribute?

Clone the registry, create a new keyword with a prefix keyword-, then create directory fixture and put there two files with extensions .js and .gs. Half way done ๐Ÿฅณ !

Then goes test and implementation in index.js and index.spec.js accordingly. Use scripts:

  • npm test
  • UPDATE=1 npm test - update fixtures;
  • AST=1 npm test - log AST;
  • npm run coverage;
  • npm run fix:lint;

Update docs and make PR, that's it!

License

MIT

Comments
  • fix:lint fails on Windows

    fix:lint fails on Windows

    While running npm run fix:lint on Windows it fails and logs: Only URLs with a scheme in: file, data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'

    Same problem testing with GitHub actions on windows-latest.

    bug windows ci 
    opened by Bellisario 9
  • [Feature request] String interpolation (like Swift)

    [Feature request] String interpolation (like Swift)


    About

    Javascript string interpolation is not always clear:

    • it appears difficult to read it because could be "confused" with code brackets;
    • "$" and "{" char are difficult to read when a text is sticky to them (making strings hard also to "format");
    • you could find yourself in a string you used the (double)quote and just to add a string interpolation you need to replace (double)quotes to ticks first, then also add the string interpolation itself, loosing time.

    More about Swift string interpolation here: https://www.hackingwithswift.com/sixty/1/5/string-interpolation


    Here is how it will look like:

    let me = "Tom"
    let years = 25
    let question = "Hello \(me), how old are you?"
    let answer = "I'm \(years) year\(years > 1 ? "s" : "") old!"
    
    console.log(question + "\n" + answer)
    /* Will log:
     *    Hello Tom, how old are you?
     *    I'm 25 years old!
     * ----------------------------------------
     * Note if years was 1 it returned "year", not "years", as you could do within Javascript interpolation
    */
    

    And here is how it looks in JavaScript:

    let me = "Tom"
    let years = 25
    let question = `Hello ${me}, how old are you?`
    let answer = `I'm ${years} year${years > 1 ? "s" : ""} old!`
    
    console.log(question + "\n" + answer)
    /* Will log:
     *    Hello Tom, how old are you?
     *    I'm 25 years old!
     * ----------------------------------------
     * Note if years was 1 it returned "year", not "years"
    */
    
    feature 
    opened by Bellisario 5
  • Solve

    Solve "try" and "guard" tests

    This solves "try" and "guard" compile test by "forcing" both codes to be a string.

    All this is very strage because running the same tests doing a sort of debug printing (on the console), code and value types will result the same to eye and also by comparing them with VS Code built-in feature... The strangest thing is also this code test (in "production" mode) here: the result is both strings are equal, but that's not so by running tests. All this should be investigated more, currently project tests could not be so reliable.

    opened by Bellisario 4
  • Fix Gitpod spelling

    Fix Gitpod spelling

    @coderaiser, using Gitpod I noticed there is a "d" instead of "t" in the name. (I didn't open a pull request because it's just a little misspelling... :wink:)

    opened by Bellisario 1
  • Add freeze keyword

    Add freeze keyword

    This pull adds the freeze keyword.


    About (same as README.md)

    freeze

    You can use freeze instead of Object.freeze() like that:

    freeze {
        'example': true
    }
    

    Is the same as:

    Object.freeze({
        'example': true
    })
    

    @coderaiser, seems there is a little thing goes bad while compiling: the compiled code adds two semicolons instead of one. I don't know if there is something to change in my code... Anyways the produced code doesn't produce any error at execution time and could also be left so (it's always a compiled code...).

    opened by Bellisario 1
  • Add should keyword

    Add should keyword

    Adds should keyword.

    About (same added to README.md)

    should

    should can be used as an expression. This keyword is useful if you want to prevent a function call (also async) to throw an error because you don't need to have any result and the real execution is just optional (so runs if supported).

    should hello()
    

    Is the same as:

    try {
        hello();
    } catch (e) {};
    

    Warning: this feature can be helpful but also dangerous especially if you're debugging your application. In fact, this is made to be used as an optional function call (ex. should load content, but not necessary and knowing this feature is optional), if you call a function in this way while debugging, no error will be printed and the application will contine run as nothing happened.

    opened by Bellisario 1
Releases(v2.5.0)
Owner
coderaiser
coderaiser
This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules to write modular JavaScript.

To-Do-List App This is my to-do list website built with html, css and JavaScript. In this project I used Webpack to bundle JavaScript and ES6 modules

Samuel Mwape 18 Sep 20, 2022
Reference for How to Write an Open Source JavaScript Library - https://egghead.io/series/how-to-write-an-open-source-javascript-library

Reference for How to Write an Open Source JavaScript Library The purpose of this document is to serve as a reference for: How to Write an Open Source

Sarbbottam Bandyopadhyay 175 Dec 24, 2022
Open Source projects are a project to improve your JavaScript knowledge with JavaScript documentation, design patterns, books, playlists.

It is a project I am trying to list the repos that have received thousands of stars on Github and deemed useful by the JavaScript community. It's a gi

Cihat Salik 22 Aug 14, 2022
Javascript-testing-practical-approach-2021-course-v3 - Javascript Testing, a Practical Approach (v3)

Javascript Testing, a Practical Approach Description This is the reference repository with all the contents and the examples of the "Javascript Testin

Stefano Magni 2 Nov 14, 2022
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021
Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript

Ping.js Ping.js is a small and simple Javascript library for the browser to "ping" response times to web servers in Javascript! This is useful for whe

Alfred Gutierrez 353 Dec 27, 2022
MenuSlider-Javascript - How to create a menu slider with vanilla javascript

MenuSlider-Javascript How to create a menu slider with vanilla javascript Instal

Tarokh Mohammadi 1 Feb 8, 2022
Simple Library implemented using HTML, CSS and JavaScript. This is a simple implementation of JavaScript Modules of ES6.

Awesome-books A single page project with the porpuse of storing books' titles and authors. Built With CSS, HTML & Javascript. How to run in your local

Saadat Ali 7 Feb 21, 2022
This is a project that allows users to add/remove books from a list. we accomplish this by using a JavaScript object. Built with JavaScript, Html and CSS.

Awesome-book This is a project that allows users to add/remove book from a list. we accomplish this by usig javascript oject. Built With HTML5 CSS3 Ja

Juan Fco. Rosario Suli 6 May 27, 2022
JavaScript project for the Leaderboard list app, using Webpack and ES6 features, notably modules. this app consume the Leaderboard API using JavaScript async and await and add some styling.

Leaderboard Project JavaScript project for the Leaderboard list app, using Webpack and ES6 features, notably modules. this app consume the Leaderboard

bizimungu pascal 4 May 20, 2022
Custom alert box using javaScript and css. This plugin will provide the functionality to customize the default JavaScript alert box.

customAlertBoxPlugin Custom Alert Box Plugin Using JavaScript and CSS Author: Suraj Aswal Must Include CSS Code/Default Custom Alert Box Class: /* mus

Suraj Aswal 17 Sep 10, 2022
A Powerful and Elegant "alert" library for JavaScript that replaces that boring alert style of Javascript.

A Powerful , Elegant and fully customizable "alert" library using JavaScript that replaces that boring style of alert. Installation Place the below sc

Cosmogic 11 Aug 10, 2021
Device.js is a JavaScript library to detect device, viewport, and browser information using plain JavaScript.

Device.js Device.js is a JavaScript library to detect device, viewport, and browser information using plain JavaScript. Compatibility Works with all m

Emanuel R. Vรกsquez 5 Dec 16, 2022
It's an alert library build with JavaScript. You can replace your traditional JavaScript alert, confirm and toast with the library.

asteroid-alert It's an alert library build with JavaScript. You can replace your traditional JavaScript alert, confirm with the library. It has also e

Khan Md Sagar 4 Mar 12, 2021
A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript Object or DOM element only from the frontend!

?? JavaScript Object to csv, xls, pdf, doc and DOM to html generator ?? A little JavaScript plugin to generate PDF, XLS, CSV and DOC from JavaScript O

null 61 Jan 7, 2023
Leader Board is a simple project based on JavaScript programing language. The purpose of this project is to work with APIs and ASYNC & AWAIT methods. I have used vanilla JavaScript with web pack to implement this project

Leader Board - JavaScript Project Table of contents Overview The challenge Screenshot Links Project Setup commands My process Built with What I learne

Mahdi Rezaei 7 Oct 21, 2022
This repo has demos, content and documentation of javascript concepts and syntax, in their simplest form. Contribute by sharing your understanding of javascript! Hacktoberfest Accepted!

javascript-documentation open-source hacktoberfest2022 Submit your PR to this javascript-documentation repo ?? ?? โ— This repo has some of my javascrip

Austin Lynch 7 Nov 2, 2022
๐Ÿ“ Algorithms and data structures implemented in JavaScript with explanations and links to further readings

?? Algorithms and data structures implemented in JavaScript with explanations and links to further readings

Oleksii Trekhleb 157.8k Dec 29, 2022
A book series on JavaScript. @YDKJS on twitter.

You Don't Know JS Yet (book series) - 2nd Edition This is a series of books diving deep into the core mechanisms of the JavaScript language. This is t

Kyle Simpson 162.7k Dec 29, 2022