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

expanso

v0.1.2

Published

This library allows you to use lambda expressions, precompiler features and lots of other things in JavaScript.

Downloads

1

Readme

Expanso

This library allows you to use lambda expressions, precompiler features and lots of other things in JavaScript.

Examples

Lambda expressions:

// An immediately returning function
var a = x -> x * x;

// Using two parameters
var b = (x, y) -> x * y;

// Using the function body
var c = (x, y) -> {
  if (x === y) {
    return 0;
  }
  
  return x * y;
};

// Default parameters
var d = (x, y = 10) -> {
  // …
};

// Rest parameters
var f = (a, b, c...) -> {
  alert(c.length);
};

// Fat arrow functions
var obj = {
  name: "Cute object",
  getFn: () -> {
    return () => @name;
  }
};

var fn = obj.getFn();
alert(fn()); // "Cute object"

The "this" shorthand:

@someName = "Hello world!"; // means this.someName
console.log(@); // means this

// "this" parameters
var e = (@x, @y) -> {
  @x === x;
  @y === y;
  // Both evalute to true
};

Multi-line strings and a string interpolation:

// (The indentation - in this case 10 spaces - is cleared on every line)
var str = `
          <div class="article">
            <div class="author">#{author}</div>
            #{@content}
            #{@[index]}
            #{comments.join("<br>")}
          </div>
          `;

Better regular expressions (in development):

var rgx = #/some data/g;

Precompiler features

Modules (CommonJS, AMD):

#module (
  SomeModule = "some-module",
  AnotherModule = "another-module"
)

var ThisModule = {
  sayHello: () -> {
    alert("Hello world!");
  }
};

#export ThisModule;

// Support for browser modules
#module GlobalNameOfModule (
  SomeModule = "some-module" = GlobalNameOfSomeModule,
  AnotherModule = "another-module" = GlobalNameOfAnotherModule
)

The foreach cycle:

#foreach (key in object) {
  // …
}
#foreach (key : val in object) {
  // …
}

#foreach (key of array) {
  // …
}
#foreach (key : val of array) {
  // …
}

Scoping:

var a = "world", b = "Hello";
#scope (a = b, b = a) {
  alert(a + ", " + b + "!"); // Hello, world!
};

var c = #scope (a = b, b = a) {
  var exports = {};
  
  exports.greeting = a + ", " + b + "!";
  
  #export exports;
};
alert(c.greeting);

var d = #(a = b, b = a) { // shorthand
  // …
};

Support of the "super" keyword using the Legio.construct:

var A = construct({
  init: (a, b) -> {
    @a = a.toString();
    @b = b.toString();
  },
  
  members: {
    showValues: () -> {
      alert(@a);
      alert(@b);
    }
  }
});

var B = construct({
  inherits: A,
  
  init: (a, b, c) -> {
    #super(a, b); // this.superInit(a, b)
    
    @c = c.toString();
  },
  
  members: {
    showValues: () -> {
      #super.showValues(); // this.superCall("showValues")
      alert(@c);
    },
    
    getNewParentInstance: (a, b) -> {
      var Parent = #super; // this.superConstructor
      
      return new Parent(a, b);
    }
  }
});

Compiling

You need Legio installed to use this.

<script src="http://requirejs.org/docs/release/2.1.6/minified/require.js"></script>
<script>
require.config({
  baseUrl: "/",
  paths: {
    "legio": "some/path/to/legio/",
    "expanso": "some/path/to/expanso/"
  }
});
</script>

<script>
require(["expanso/lib/extra-compiler", "legio/util/request"], function (ExtraCompiler, Request) {
  
  Request.file("test-file.js").then(function (code) {
    var compiler = new ExtraCompiler(code);
    
    alert(compiler.compile());
  });
  
});
</script>

Or you can use the NPM package:

npm install -g expanso

expanso test-file.jsx
expanso test-file.jsx someDir/test-file.js