npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bastascript

v0.2.0

Published

A JavaScript dialect that adds some useful crap.

Downloads

6

Readme

bastascript (v0.2)

Bastascript is a language designed to improve JavaScript's ability to serve as a functional programming language with terse, obvious syntax. Bastascript is a subset of JavaScript extended with additional syntax that compiles to JavaScript.

Running Bastascript code

You can compile a BS file with the following command:

bs file_to_compile.bs

The generated code will be piped to stdout.

Adding the --run flag will execute the code after compiling.

Features

Partial Functions/Currying (skinny arrow)

Bastascript makes heavy use of partial functions, which are applied in a manner more similar to currying. This is accomplished via the skinny arrow operator (->).

Some examples:

promise.then(function() {
    foo.bar(x);
}, function(err) {
    console.error(err);
});

could be written as

promise.then(foo.bar->(x), console.error->());

A skinny arrow augmented assignment operator is provided:

x = x->(1, 2, 3);
// equivalent to
x =->(1, 2, 3);

Currying can be simulated like this:

function myfunc(x, y, z) {...;}

var curr = myfunc->();
curr =->(1);
curr = curr->(2);
console.log(curr(3));

Creating a partial function preserves the context of members. For instance:

var x = foo.bar.bind(foo);
// equivalent to
var x = foo.bar->();

Member Augmented Assignment

x = x.y can be written as x .= y.

Yada Yada Operator

...; will throw a new error named "Not Implemented".

if (someCondition) {
   ...;
}

For-In-If Loops

for (var i in foo) {
    if (foo.hasOwnProperty(i)) {
        console.log(i);
    }
}

can be written as

for (var i in foo if foo.hasOwnProperty(i)) {
    console.log(i);
}

Method Declarations

foo.method = function method() {};

can be written as

function foo.method() {
    ...;
}

Note that the method name is preserved.

Decorators

var myFunc = decorator(function() {
    // ...
});

obj.method = decorator(function method() {});

can be written as

@decorator:
function myFunc() {
    ...;
}

@decorator:
function obj.method() {
    ...;
}

Decorators can be members or call expressions:

@ident:
@dec.method:
@call(foo, bar):
@dec.call(foo, bar):

Decorators can be chained, and will be applied such that the outermost decorator will be applied last.

later Statement

The later statement allows you to defer a statement's execution until after the completion of the remainder of the function.

function test(shouldMock) {
    if (shouldMock) {
        mock();
        later cleanup();
    }
    ...;
}

later statements retain lexical scope and their access to the this identifier. later statements will not presently work with generators.

If an exception is thrown in a function with later statements, none of the deferred statements will be executed. You should catch exceptions with try blocks instead.

return-unless and return-if statements

Return statements support a ruby-like unless clause that expands out to an if (!expr) construct. They may also use if, which expands out to if (expr).

return foo unless bar;
return foo if bar;

vs.

if (!bar) {
    return foo;
}
if (bar) {
    return foo;
}

Function shorthand

The function keyword can be replaced with the unicode character ƒ. This also works with generators: ƒ*.

ƒ foo() {
    ...;
}
function foo() {
    // ...;
}

ES6-style Fat Arrow Functions

Fat arrow functions should work as they're documented in the Harmony wiki.

x = () => foo;
y = elements.map(e => e.getAttribute('name'));

vs.

x = function() {return foo;};
y = elements.map(function(e) {return e.getAttribute('name')});

Arrow functions will bind this lexically (as in ES6) when this is used.

Note that later statements are not bound to arrow functions and instead are bound to the lexical parent. If the arrow function executes after the lexical parent has completed, the later statement will not be run.

Differences from JavaScript

  • There is no with statement.
  • All statements must be followed by a semicolon. There is no automatic semicolon insertion.
  • Only generated identifiers may start with three underscores.
  • Numeric literals may only be written as integers or floats. Octal values are not allowed.