Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 1.57 KB

README.md

File metadata and controls

56 lines (39 loc) · 1.57 KB

dirty-pluck

NPM Version NPM Bundle Size

dirty-pluck is a tiny and straight-forward library for plucking JSON values. It's great for adapters of all sorts.

Installation

To add dirty-pluck to your project, you can use your favorite package manager.

npm install dirty-pluck
yarn add dirty-pluck

Usage

dirty-pluck is opinionated and not meant to be a query language. However, it's as simple as it gets if you want to pluck whatever values that get in the way.

import pluck from "dirty-pluck";

const data = {
  restaurant: {
    title: "The Best Restaurant",
    reviews: [{ rating: 8.5 }, { rating: 2.7 }, { rating: 9.1 }],
  },
};

pluck(data, "restaurant.title");
// => ["The Best Restaurant"]

pluck(data, "restaurant.reviews");
// => [{ rating: 8.5 }, { rating: 2.7 }, { rating: 9.1 }]

pluck(data, "restaurant.reviews.rating");
// => [8.5, 2.7, 9.1]

Licence

dirty-pluck is released under the MIT License.

Acknowledgements

This package is inspired by JSONata and JMESpath and fostered by the people at Primevise and Mintis