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

faltu

v0.1.0

Published

Search sort, filter, limit and iterate over an array of objects in Mongo-style.

Downloads

45

Readme

travis-ci Coverage Status npm version License

Faltu

Search sort, filter, limit and iterate over an array of objects in Mongo-style.

Installation

In NodeJS:

npm install faltu --save

For other projects simply download and include the file in your pages:

<script src="faltu.min.js"></script>

Usage

All the data passed is expected to be an array or objects.

e.g:

[record, record, ..., record]

All the data returned is also of the same type.

For example:

var data = [{
  name: "John",
  age: 16
},{
  name: "Doe",
  age: 18
},{
  name: "Smith",
  age: 22
}];

Pass the array to constructor:

In NodeJS:

var Faltu = require('faltu');
var faltuData = new Faltu(data);

Searching

You can use find method for searching. Search for all the guys who are 18 years of age:

var newData = new Faltu(data).find({
  age: 18
}).get();

newData would look something like:

[{
  name: "Doe",
  age: 18
}]

Search for all the guys who are 18 years of age or older:

var newData = new Faltu(data).find({
  age: {
    $gte: 18 // $gte is similar to >= (greater than or equal to)
  }
}).get();

newData:

[{
  name: "Doe",
  age: 18
},{
  name: "Smith",
  age: 22
}]

Other supported comparison operators in find are:

  • $lt: <
  • $lte: <=
  • $gt: >
  • $ne: !=

Search for all the guys who are 18 or 16 years of age:

var newData = new Faltu(data).find({
  age: [16, 18]
}).get();

newData:

[{
  name: "John",
  age: 16
},{
  name: "Doe",
  age: 18
}]

Passing null, empty object {} or nothing to find means not performing any search.

Sorting

Use sort to sort the result in descending order by age:

var newData = new Faltu(data).find({
  age: [16, 18]
}).sort({
  age: -1 // 1 = ASC, -1 = DESC
}).get();

newData:

[{
  name: "Doe",
  age: 18
},{
  name: "John",
  age: 16
}]

Limit

Let's get only 1 object back:

var newData = new Faltu(data).find().limit(1).get();

newData:

[{
  name: "John",
  age: 16
}]

Skip

Let's skip 1st object:

var newData = new Faltu(data).find().skip(1).get();

newData:

[{
  name: "Doe",
  age: 18
},{
  name: "Smith",
  age: 22
}]

Skip & Limit

Let's skip 1st object:

var newData = new Faltu(data).find().skip(1).limit(1).get();

newData:

[{
  name: "Doe",
  age: 18
}]

Filtering

You can also perform jQuery-esque filtering yourself. Call filter method, pass a function.

var newData = new Faltu(data).find().filter(function (person) {
  return person.age == 16; // return true if you want to keep the object
}).get();

newData:

[{
  name: "John",
  age: 16
}]

Iterate

each iterates over all the records returned.

var newData = new Faltu(data).find(null).each(function(person, index){
  console.log('User name:', person.name);
});