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

recursify

v0.0.14

Published

An attempt to recursively define most built-in js functions

Downloads

5

Readme

recursify

Functional programming has gotten bigger. The below functions(mostly built-in to JS) are defined using recursion. Enjoy.

Install

$ npm install recursify

Usage

var R = require('recursify');

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

// return [3,6,9];

R

Recursify


R~isString(input) ⇒ boolean

isString Function

Kind: inner method of R

Example

isString('test');
// return true;

R~isArray(input) ⇒ boolean

isArray function

Kind: inner method of R

Example

isArray([1,2,3]);
// return true;

R~isObject(input) ⇒ boolean

isObject function

Kind: inner method of R

Example

isObject({});
// return true;

R~isNumber(input) ⇒ boolean

isNumber function

Kind: inner method of R

Example

isNumber(1);
// return true;

R~isFunction(input) ⇒ boolean

isFunction function

Kind: inner method of R

Example

isFunction(function(){});
// return true;

R~isSimilar(input1, input2) ⇒ boolean

isSimilar function

Kind: inner method of R

Example

isSimilar({}, []);
// return false;

R~isEmpty(input) ⇒ boolean

isEmpty Function

Kind: inner method of R

Example

isEmpty([]);
// return true;

R~exists(value, list) ⇒ boolean

Exists Function

Kind: inner method of R

Example

exists(1, [1,2,3]);
// return true;

Example

exists(1, [2,3]);
// return false;

R~map(func, list) ⇒ array

Recursive Map Function

Kind: inner method of R
Returns: array - New array

Example

map(function(x) { return x * 2; }, [1,2,3]);
// return [2,4,6];

R~each(func, list) ⇒ array

Recursive Each Function

Kind: inner method of R
Returns: array - Input array

Example

var count = 0;
each(function(x) { return count += x; }, [1,2,3]);
// return [1,2,3]
// count => 6;

R~filter(func, list) ⇒ array

Recursive Filter Function

Kind: inner method of R
Returns: array - New filtered array

Example

filter(function(x) { return x < 3; }, [1,2,3]);
// return [1,2];

R~reverse(list) ⇒ array

Recursive Reverse Function

Kind: inner method of R
Returns: array - New reversed array

Example

reverse([1,2,3]);
// return [3,2,1];

R~insert(value, list) ⇒ array

Recursive Insert Function

Kind: inner method of R
Returns: array - New array with inserted value

Example

insert(2, [1,4,5]);
// return [1,2,4,5];

R~insertDesc(value, list) ⇒ array

Recursive Insert Function

Kind: inner method of R
Returns: array - New array with inserted value

Example

insertDesc(3, [4,2,1]);
// return [4,3,2,1];

R~sort(list) ⇒ array

Recursive Sort Function (ascending)

Kind: inner method of R
Returns: array - New sorted array-ascending

Example

sort([1,5,3,3,1,3,5,6]);
// return [1,1,3,3,3,5,5,6];

R~sortDesc(list) ⇒ array

Recursive Sort Function (descending)

Kind: inner method of R
Returns: array - New sorted array-descending

Example

sortDesc([1,4,2,4,1,3]);
// return [4,4,3,2,1,1];

R~qsort(list) ⇒ array

Quick Sort Function (ascending)

Kind: inner method of R
Returns: array - New sorted-unique-ascending

Example

qsort([5,4,1,2,4,1,3,4,6]);
// return [1,2,3,4,5,6];

R~qsortDesc(list) ⇒ array

Quick Sort Function (descending)

Kind: inner method of R
Returns: array - New sorted-unique-descending

Example

qsortDesc([1,5,2,1,3,5,6,7,3]);
// return [7,6,5,3,2,1];

R~foldr(func, value, list) ⇒ *

Recursive Foldr Function

Kind: inner method of R
Returns: * - Result after collecting

Example

foldr(function(x, y) { return x + y; }, 10, [1,2,3]);
// return 16;

R~foldl(func, value, list) ⇒ *

Recursive Foldl Function

Kind: inner method of R
Returns: * - Result after collecting

Example

foldl(function(x, y) { return x + y; }, 10, [1,2,3]);
// return 16;

R~addr(list1, list2) ⇒ array

Recursive Right Concatenation Function

Kind: inner method of R
Returns: array - New array of list1 + list2

Example

addr([1,2,3], [4,5,6]);
// return [1,2,3,4,5,6];

R~addl(list1, list2) ⇒ array

Recursive Left Concatenation Function

Kind: inner method of R
Returns: array - New array of list2 + list1;

Example

addl([1,2,3], [4,5,6]);
// return [4,5,6,1,2,3];

R~rgive(value, list, mutate) ⇒ array

Append value to list

Kind: inner method of R
Returns: array - New array of appended value

Example

rgive(1, [4,3,2]);
// return [4,3,2,1];

R~lgive(value, list, mutate) ⇒ array

Prepend value to list

Kind: inner method of R
Returns: array - New array of prepended value

Example

lgive(1, [2,3,4]);
// return [1,2,3,4];

R~cplist(list) ⇒ array

Copy array (Array.prototype.slice wrapper)

Kind: inner method of R

Example

var a = [1,2,3];
var b = cplist(a);
a == b
// return false;

R~indexOf(match, list, index) ⇒ number

IndexOf Function

Kind: inner method of R
Returns: number - index value if match found. Returns -1 if no match.

Example

indexOf('l', 'hello');
// return 2;

Example

indexOf('a', 'hello');
// return -1;

R~genList(size, function) ⇒ array

genList Function

Kind: inner method of R
Returns: array - New array of generated values

Example

genList(5, function(x) { return x * 3; });
// return [0,3,6,9,12];

R~keys(obj) ⇒ array

keys functions

Kind: inner method of R

Example

keys({a: 1, b: 2});
// return ['a', 'b'];

R~lenObj(obj) ⇒ number

lenObj function

Kind: inner method of R

Example

lenObj({a: 1, b: 2});
// return 2;

R~cpobj(obj) ⇒ object

Copy Object Function

Kind: inner method of R
Returns: object - Copy of object

Example

var a = {hello: 'world'};
var b = cpboj(a);
b === a;
// return false

R~lmerge(obj1, obj2) ⇒ object

Merge Left Function

Kind: inner method of R
Returns: object - obj1

Example

var a = {a: 1};
var b = {b: 2};
lmerge(a, b);
// return {a: 1, b:2};
// a => {a: 1,b: 2};
// b => {b: 2};

R~rmerge(obj1, obj2) ⇒ object

Merge Right Function

Kind: inner method of R
Returns: object - obj2

Example

var a = {a: 1};
var b = {b: 2};
rmerge(a,b);
// return {a: 1,b: 2};
// a => {a: 1};
// b => {a: 1,b: 2};

R~eachObj(func, obj) ⇒ object

EachObj Function

Kind: inner method of R
Returns: object - - input object

Example

var a = {a: 1, b: 2};
var count = 0;
eachObj(function(value, key) { count += value; }, a);
// return {a: 1, b: 2}
// count => 3;

R~mapObj(func, obj) ⇒ object

MapObj Function

Kind: inner method of R
Returns: object - - new object

Example

var a = {a: 1, b: 2}
mapObj(function(value, key, obj) { 
 obj[key + value] = value * 3;
}, a);
// return { a1: 3, b2: 6};

R~foldObj(func, start, obj) ⇒ *

FoldObj Function

Kind: inner method of R

Example

var a = {a: 1, b: 2}
foldObj(function(result, val, key) { return result + val }, 0, a);
// return 3;

R~times(number, function) ⇒ undefined

times Function

Kind: inner method of R

Example

times(3, function(x) { console.log('Number: ', x); });
// return Number: 3
// return Number: 2
// return Number: 1
// return undefined

Contributing

New functions, issues, and pull requests welcome

  1. Fork it
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request