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

recursionjs

v0.3.1

Published

A library to allow recursion of nestable javascript objects using available prototypial methods

Downloads

8

Readme

recursionjs

A library to allow flexible recursion of javascript objects, written in Typescript.

Motivation

Doing nested recursion on Javascript objects is a pain.

It's hard to compare them all, they're all slightly different when accessing properties and reading them.

Goal

To provide familiar Javascript prototype methods to use in a recursive fashion, with inter-object compatibility.

Note

This in development, very early stages. I want to do as many methods as possible, but if you want something prioritised just post an issue.

Anything I've written below is available and works.

How to use?

Easy, just parse your object, array, map or set through the recursion() function:

import { recursion } from 'recursionjs'
// OR
import recursion from 'recursionjs'

const myOldObject = { name: 'shrek', wife: 'fiona' }
const myNewObject = recursion(myOldObject)

// Now you can access `recursionjs` methods

// callbacks hold two objects:
// + 1st object is the original arguments, available to deconstruct ,
// + 2nd object holds handy methods for getting values handy in recursion (parents, depth, path)

const hasShrek = myNewObject.some(({ key, value }, { depth, parent, path }) => {
  return key === 'name' && value === 'shrek'
})

API

array.some()

Outputs a boolean based off the callback:

const myNewObject = recursion({ name: 'shrek', wife: 'fiona' })

// returns true
const hasShrek = myNewObject.some(({ key, value }) => {
  return key === 'name' && value === 'shrek'
})

array.map()

An alias for recursion.mapValues()

This maps the value of the Object.

const myNewObject = recursion({ name: 'shrek', wife: 'fiona' })

// returns { shrek: 'name', fiona: 'wife' }
const hasShrek = myNewObject.some(({ value }) => value)

array.filter()

Filters the array.

const myNewObject = recursion({ name: 'shrek', wife: 'fiona' })

// returns { shrek: 'name'}
const hasShrek = myNewObject.filter(({ value }) => value === 'shrek')

Contribution and Discussion

I'd love to hear from anyone looking to benefit from something like this.

It's early days and if you want a feature or have any ideas you'd like to jot down, just ask as an issue :)

I plan to add as much as I can in as it's not hard once the architecture of the library is understood.

Architecture

In a nutshell, each object gets converted to the object that the prototype method requires and then runs the method, which runs on it's value property again if value instanceof Object.

For example we'll use recursion.some(). This comes from and uses Array.prototype.some() under the hood. We must convert from our input to an array of tuples/entries). now we have a standardized array, we run the function against it.

We have the public facing function (some) and the private facing function (_some()). The public function calls _some() using the input parsed to recursion() class.