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

metaknight

v1.0.0

Published

Meta-trickery with parsers!

Downloads

3

Readme

Metaknight

Metaknight is a little library for meta-trickery with javascript functions. It uses esprima and escodegen to take your existing javascript functions, tear them apart and rebuild them, better and stronger than before*

* use only as directed, functions may not be better or stronger, does not work on arrow functions or functions expecting closure context, this is probably not a very useful library

Let's get started

> var meta = require('metaknight')

Have you ever wished a function's arguments were in a different order?

> function minus(a, b) { return b - a; }
> minus(1, 3)
2
> var betterminus = meta(minus).reorder([1,0])()
> betterminus(1, 3)
-2
> betterminus.toString() //toString output cleaned up slightly
'function anonymous(b,a) {return b - a;}'

Or that some arguments were optional?

> function add(a, b) { return a + b; }
> add(5, 7)
12
> var add5 = meta(add).assign({b: 1})()
> add5(10)
15
> add5.toString()
'function anonymous(b) {return 5 + b;}'

Or you could partially apply a function like a functional programmer?

> var add4 = meta(add).curry(4)()
> var add4 = meta(add)(4) // this is a shortcut
> add4(10)
14
> add4.toString()
'function anonymous(b) {return 5 + b;}'

Or that you could rename arguments?

> var funadd = meta(add).rename({a: "hello", b: "world"})()
> funadd(1, 2)
-2
> add5.toString()
'function anonymous(hello,world) {return hello + world;}'

Or even take two totally separate functions and smoosh them together?

> function hello() { console.log("hello"); }
> function world() { console.log("world"); }
> var helloworld = meta(hello).concat(meta(world))()
> helloworld()
hello
world
> helloworld.toString()
'function anonymous(\n) {console.log(\'hello\'); console.log(\'world\')}'

Well, whether you wished for these things or not, now you have them!