All Projects → moinism → Faltu

moinism / Faltu

Licence: mit
Search sort, filter, limit an array of objects in Mongo-style.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Faltu

Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (+33.93%)
Mutual labels:  search, sort, filter
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-65.18%)
Mutual labels:  search, filter
Leetcode
Provide all my solutions and explanations in Chinese for all the Leetcode coding problems.
Stars: ✭ 5,619 (+4916.96%)
Mutual labels:  sort, array
React Grid Table
A modular table, based on a CSS grid layout, optimized for customization.
Stars: ✭ 57 (-49.11%)
Mutual labels:  search, sort
Mixitup
A high-performance, dependency-free library for animated filtering, sorting, insertion, removal and more
Stars: ✭ 4,431 (+3856.25%)
Mutual labels:  sort, filter
Filterizr
✨ Filterizr is a JavaScript library that sorts, shuffles and filters responsive galleries using CSS3 transitions ✨
Stars: ✭ 546 (+387.5%)
Mutual labels:  sort, filter
Pgo
Go library for PHP community with convenient functions
Stars: ✭ 51 (-54.46%)
Mutual labels:  array, filter
Gridjs
Advanced table plugin
Stars: ✭ 3,231 (+2784.82%)
Mutual labels:  sort, filter
Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (-32.14%)
Mutual labels:  sort, filter
Java
All Algorithms implemented in Java
Stars: ✭ 42,893 (+38197.32%)
Mutual labels:  search, sort
C
Collection of various algorithms in mathematics, machine learning, computer science, physics, etc implemented in C for educational purposes.
Stars: ✭ 11,897 (+10522.32%)
Mutual labels:  search, sort
Ngx Mat Select Search
Angular component providing an input field for searching / filtering MatSelect options of the Angular Material library.
Stars: ✭ 416 (+271.43%)
Mutual labels:  search, filter
Algorithms
Minimal examples of data structures and algorithms in Python
Stars: ✭ 20,123 (+17866.96%)
Mutual labels:  search, sort
Sieve
⚗️ Clean & extensible Sorting, Filtering, and Pagination for ASP.NET Core
Stars: ✭ 560 (+400%)
Mutual labels:  sort, filter
React Search Input
🔍 Simple react.js component for a search input, providing a filter function.
Stars: ✭ 300 (+167.86%)
Mutual labels:  search, filter
Twig Lambda
Lambda expressions for Twig and filters that make use of them
Stars: ✭ 40 (-64.29%)
Mutual labels:  sort, filter
Muuri
Infinite responsive, sortable, filterable and draggable layouts
Stars: ✭ 9,797 (+8647.32%)
Mutual labels:  sort, filter
Jschema
A simple, easy to use data modeling framework for JavaScript
Stars: ✭ 261 (+133.04%)
Mutual labels:  sort, filter
Graphql To Mongodb
Allows for generic run-time generation of filter types for existing graphql types and parsing client requests to mongodb find queries
Stars: ✭ 261 (+133.04%)
Mutual labels:  sort, filter
Array Sort
Fast and powerful array sorting. Sort an array of objects by one or more properties. Any number of nested properties or custom comparison functions may be used.
Stars: ✭ 58 (-48.21%)
Mutual labels:  sort, array

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:

[array, array, ..., array]

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);

In other environments:

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
}]

You should always call get at the end if you want an array back. Or It'll just return the faltu instance.

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. find accepts options as second argument.

e.g:

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

Will return the data in descending order by age. Other than sort you can also pass:

  • skip
  • limit
  • unique

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
}]

Unique

You can have result returned that is unique by a key.

var newData = new Faltu(data).find().unique('age').get();

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);
});
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].