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

fancierscript

v0.5.1

Published

Fancier JavaScript

Downloads

4

Readme

FancierScript

Fancier FancyScript

FancierScript aims to make developing in FancyScript easier and more powerful while remaining "just FancyScript". For a completely different approach with diverse syntax rules, and in the latter case, a powerful standard library, look toward CoffeeScript or ClojureScript. FancierScript compiles to plain ES5 JavaScript. Thanks @btmills for the name.

Usage

npm install -g fancierscript installs the FancierScript binary fancier so it can be used globally.

fancier input.fs compiles the FancierScript source file input.fs to plain JavaScript in input.js.

Options

  • -b, --bare Compile without a top-level function wrapper.
  • -o, --out [DIR] Write all compiled JavaScript files into the specified directory.
  • -r, --repl Start an interactive FancierScript REPL. Interrupts all other options.
  • -w, --watch Watch specified files for changes.

Features

Strict by default

FancierScript follows strict-mode JavaScript conventions. Unless the --bare option is passed, the compiled code is wrapped in an IIFE (Immediately-Invoked Function Expression) with "use strict"; inside. For the sake of clarity, other examples will not include the function wrapper and strict mode declaration.

var a = 42;
(function () {
    "use strict";
    var a = 42;
}).call(this);

Arrow functions

Arrow functions in Harmony are a more concise syntax for function expressions, consisting of a parameter list and an automatically-returned expression or a statement block.

[1, 2, 3, 4].map(x => x * x);
[1, 2, 3, 4].map(function (x) {
    return x * x;
});

Default arguments

Use default arguments to provide a default value within the function's parameter list for any optional arguments.

function foo(a, b = 42, c, d = bar(), e) { }
function foo(a, b, c, d, e) {
    if (typeof b === 'undefined') { b = 42; }
    if (typeof d === 'undefined') { d = bar(); }
}

Rest parameters

From the MDN page, rest parameters represent "an indefinite number of arguments as an array." A function declaration or function expression may have a rest parameter as its last argument which will absorb all the rest of the arguments when the function is called.

fn isEven (...x) {
    x.every(fn (x) { x % 2 === 0 });
}
function isEven() {
    var x = Array.prototype.slice.call(arguments, 0);
    return x.every(function (x) {
        return x % 2 === 0;
    });
}

isEven(2, 4, 6); // true

Spread operator

From the MDN page, the spread operator expands an expression into multiple arguments to a function or multiple elements in array literals. Currently only the former case is supported, but the latter is in progress.

var arr = ['b', 'c', 'd'];
console.log('a', ...arr, 'e');
var arr = ['b', 'c', 'd'];
console.log.apply(console.log, [].concat(['a'], arr, ['e'])); // a b c d e

Note that support for the spread operator in a call to Function.prototype.apply is neither available nor planned. A compelling use case would be needed.

Array destructuring

Array destructuring can occur in variable declarations, assignment expressions, or function parameters.

var [a, b] = [11, 42];
console.log([a, b] = [b, a]); // [42, 11]
function show([, second]) {
    console.log(second);
}
show([a, b]); // 11
var $tmp = [11, 42], a = $tmp[0], b = $tmp[1];
console.log(function ($tmp) {
    a = $tmp[0];
    b = $tmp[1];
    return $tmp;
}([b, a]));
function show($tmp) {
    var second = $tmp[1];
    return console.log(second);
}
show([a, b]);

Object destructuring

Like array destructuring, object destructuring is syntactic sugar for more easily creating objects or retrieving values from them. This can occur in variable declarations, function parameter lists, or as a shortcut in object expressions.

var { name, age: a } = getPerson(); // Declare variables "name" and "a"
var obj = { name, age: a }; // Shortcut to initialize obj.name to variable "name"
function ({ name, age: b}, cb) { }
({ name, age: a }) = getAnotherPerson();
var $tmp = getPerson(), name = $tmp['name'], a = $tmp['age'];
var obj = { name: name, age: a };
function ($tmp2, cb) {
    var name = $tmp2['name'], b = $tmp2['age'];
}
(function ($tmp3) {
    name = $tmp3['name'];
    a = $tmp3['age'];
    return $tmp3;
})(getAnotherPerson());

Automatic return values

If the last statement of a function is an expression contained in an ExpressionStatement, it is automatically returned.

fn isEven (x) { x % 2 === 0 }
function isEven(x) {
    return x % 2 === 0;
}

fn keyword

fn is an alias to the function keyword and is interchangeable.

fn hello () {
    conole.log('Hello, world!');
}
function hello () {
    console.log('Hello, world!');
}

Example

var isEven = (x, ...r) => x % 2 === 0 && (r.length ? isEven(...r) : true)
var isEven = function (x) {
    var r = Array.prototype.slice.call(arguments, 1);
    return x % 2 === 0 && (r.length ? isEven.apply(isEven, [].concat(r)) : true);
}

isEven(2, 4, 6, 7); // false
isEven(2, 4, 6, 8); // true

License

Licensed under the BSD 3-Clause License, the full text of which can be read in LICENSE.