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

datafield

v0.3.0

Published

Sort, select, filter, evaluate and perform maths on your arrays of data

Downloads

9

Readme

codecov Build Status JavaScript Style Guide npm version License: MIT

:page_facing_up: Read the documentation here
:cat: Contribute for the greater good

What is DataField

DataField is a library that helps you wrangle your awesome collections of data you obtain from different sources.

Imagine you are building a web application that deals with users. You make an API request and receive an array of 100 entries which look like this one below:

{
  "_id": "5b420ae94fe6464ff91f5de8",
  "index": 0,
  "guid": "871eebf0-9983-4eb5-a0b5-59372a2fbecd",
  "isActive": true,
  "balance": "$1,268.06",
  "age": 41,
  "name": {
    "first": "Pearlie",
    "last": "Osborne"
  },
  "company": "PIVITOL",
  "email": "[email protected]",
  "phone": "+1 (992) 418-2307",
  "address": "190 River Street, Spelter, Tennessee, 1088",
  "registered": "Monday, April 18, 2016 7:35 AM",
  "tags": ["ad", "magna", "aliqua"],
  "friends": [{"id": 0, "name": "Whitney Snow"}, {"id": 1, "name": "Garza Hernandez"}, {"id": 2,"name": "Lourdes Conley"}]
} 
  

With this library it is rather easy to perform various actions on your data.

How It Works

const users = new DataField(arrayOfUsers)

Now your data is stored in an instance of DataField class.

Each method that performs any kind of selection or filtering returns a new instance of DataField and can be chained.

Math methods return primitives and can not be chained

To extract your data use .values() or toArray()

Lets filter our data. We need users who are 30 years old or older, but not 41 years old and have at least 2 friends, but less than 10. Also we want our list sorted by last name in descending order. Then we are done so we want an array out of that:

users.where('age').gte(30).not(41).where('friends').range(2, 10).sort({by: 'name.last', order: 'desc'}).toArray()

Or you can go more object-oriented way (this one below is kinda weird request although):

users.where('age').any({
  range: [8, 88],
  lte: 18,
  gt: 60,
  not: 42,
  is: false
})

That's it. API is short and simple. Also, read the Documentation

npm i datafield