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

jmespath-plus

v0.1.7

Published

jmespath.js extended with functions from lodash

Downloads

2,645

Readme

JMESPath+

Build Status

This is an extension of a fork of the original JMESPath.

It fully complies with the spec, and includes all tests from the original jmespath.js project.

Motivation

There is an article on the XML website claiming that You Should Be Using XSLT 3.0 to process JSON. If you take a look at the XSLT given for performing the transformation of the JSON in their example, it's (like XML in general) overly verbose.

I couldn't quite reproduce the same thing using the original JMESPath, but with my fork of JMESPath that allows for the addition of custom functions, I could. By adding the toPairs function, there is now an elegant solution to the example from that XML article:

toPairs(employees)[*]
  .merge(
    [1],
    {
      id: [0],
      fullName: join(' ', [[1].firstname, [1].surname]),
      reverseName: join(', ', [[1].surname, [1].firstname])
    }
  )

The original jmespath.js repository has not been updated for many years. There are many unanswered issues, including this one inquiring about the project status. Also on the website repo there is an issue about the project status. I submitted a pull request.

In the meantime, I published my fork as a "scoped package" on NPM here.

This package is an extension of that fork, with some extra utility functions that I find useful. I added a few bits of lodash and some string functions. Open an issue if you need any extra functions added, or use the code in src/main.js as an example and extend @daz.is/jmespath.js with your own functions.

Install

Install from npm:

npm install --save jmespath-plus

Online demo:

https://codesandbox.io/embed/focused-lichterman-y867l?fontsize=14&hidenavigation=1&theme=dark

Usage

const jmespath = require('jmespath-plus');
const v = jmespath.search({ a: 42 }, 'a');
console.log(v); // output = 42

Additions

  • additional functions have been added (see below)
  • more custom functions can be added by you
  • the $ character can be used within expressions to reference the root
  • parsed expressions can be cached and run against multiple data

Extra functions

The following extra functions have been added:

toLowerCase(STRING)

Converts string to lowercase.

trim(STRING)

Removes any spaces from beginning and end of string.

split(STRING, separator:STRING)

Split string by separator.

zip(...ARRAYS)

toPairs(OBJECT)

Convert an object into an array of key value pairs.

fromPairs(ARRAY)

Convert an array of key value pairs back into an object.

omit(OBJECT, ...KEYS)

Return the object but omitting the items with the specified keys.

pick(OBJECT, ...KEYS)

Return a new object with only the items with the specified keys.