New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

metaknight

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metaknight

Meta-trickery with parsers!

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

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!

Keywords

meta

FAQs

Package last updated on 17 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts