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

opather

v0.1.0

Published

A micro library to defer the resolution of object paths.

Downloads

7

Readme

opather (oh-path-er)

A tool to defer the resolution of an object path until you have the data.

This lets you remove functions where you don't reall need any except to map out a property path, and write code that reads more like configuration. It also allows you to refactor object structure easily.

Inspired by trivial uses of XPath, where you can "compile" a path to access a node on an XML document many times over. Think of this as similar to that, but with less features.

Use case:

Instead of writing:

var getBaxInJson = function(data){
    return data.foo.bar.baz.fax;
};
var getBaxInJson = function(data){
    return data.foo.bar.baz.bax;
};
var getBaxInJson = function(data){
    return data.foo.bar.baz.jax;
};

function(data){
    return [
        getFaxInJson(data)
        getBaxInJson(data)
        getJaxInJson(data)
    ];
}

You can write:

var getFaxInJson = opather('foo')('bar')('baz')('fax').locate;
var getBaxInJson = opather('foo')('bar')('baz')('bax').locate;
var getJaxInJson = opather('foo')('bar')('baz')('jax').locate;

function(data){
    return [
        getFaxInJson(data)
        getBaxInJson(data)
        getJaxInJson(data)
    ];
}

You can also write:

bazPather = opather('foo')('bar')('baz');
var getFaxInJson = bazPather('fax').locate;
var getBaxInJson = bazPather('bax').locate;
var getJaxInJson = bazPather('jax').locate;

function(data){
    return [
        bazPather('fax').locate(data);
        bazPather('bax').locate(data);
        bazPather('jax').locate(data);
    ];
}

You may also have a method that expects a opather you can curry with:

var hugeBlobOfData = {
    address: '123 bob way',
    company: 'bob tech',
    user: {username: 'bob'},
    email: ['[email protected]']
};

function curryByOpather(opather){
    return function(object){
      opather.locate(object)
    };
}

getUsername = curryByOpather(opather('user')('username'));
getFirstEmail = curryByOpather(opather('email')(0));
getCompany = curryByOpather(opather('company'));
getAddress = curryByOpather(opather('address'));

getUsername(hugeBlobOfData); // 'bob'

And if you don't have data until later, you can return the opather and reduce data against it later.

Feedback providers, thinkers, hate mobs

  • What do you like?
  • What do you have questions about?
  • What do you think needs to change?
  • What new ideas can you present?

Create an issue on github and let me know!

Future changes?

I'd like to introduce some default-to-undefined/specified or methods similar to that.

I really want to keep the API stable. If I need to break it, my goal will be to deprecate in a feature release and break in a major release.