0.0.8 • Published 6 years ago

returnjs v0.0.8

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

Return.JS

What is it?

A library for Node.JS that wraps functions and compares their return types to pre-defined expected returned types

Why did you make it?

I do drunk programming a lot. It helps me a lot. /shrug

How can I use it?

It's simple:

First require the module:

const {Return} = require("returnjs")

Second, define a function with some sort of return:

const func = function(hi) {
  console.log(hi)
  return hi ? {} : []
}

Third. instantiate an object:

const returnFunc = new Return(func)

Now comes the fun part. You can easily declare which sort of return types you want. In our case, we want array and object.

There are three ways you can do this:

The first way:

returnFunc.array
returnFunc.object
const caller = returnFunc.done

Which basically says that returnFunc can return either an array or object. .done gets an anonymous function which calls the main function

The second way:

const caller = returnFunc.array.or.object.done

Basically, it's chained commands, saying that it can be either array or object, and to return a wrapper once it's done.

The third way is the way I prefer most, using it directly:

const returnFunc = new Return(function func(hi) {
  console.log(hi)
  return hi ? {} : []
}).array.or.object.done

This is everything above combined.

Disclaimer:

This entire module is drunk-code, made to make drunk programmer's lives easier

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago