{"id":17304685,"url":"https://github.com/moinism/faltu","last_synced_at":"2025-10-10T19:04:09.766Z","repository":{"id":57232652,"uuid":"70596238","full_name":"moinism/faltu","owner":"moinism","description":"Search sort, filter, limit an array of objects in Mongo-style.","archived":false,"fork":false,"pushed_at":"2016-10-19T20:33:08.000Z","size":11,"stargazers_count":111,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-28T02:24:09.900Z","etag":null,"topics":["array","filter","javascript","mongo-style","nodejs","objects","search","sort"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moinism.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-11T13:29:11.000Z","updated_at":"2022-10-27T10:44:01.000Z","dependencies_parsed_at":"2022-08-31T20:51:08.065Z","dependency_job_id":null,"html_url":"https://github.com/moinism/faltu","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinism%2Ffaltu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinism%2Ffaltu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinism%2Ffaltu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinism%2Ffaltu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moinism","download_url":"https://codeload.github.com/moinism/faltu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248836246,"owners_count":21169368,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array","filter","javascript","mongo-style","nodejs","objects","search","sort"],"created_at":"2024-10-15T11:53:38.160Z","updated_at":"2025-10-10T19:04:04.729Z","avatar_url":"https://github.com/moinism.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![travis-ci](https://api.travis-ci.org/moinism/faltu.svg?branch=master)](https://travis-ci.org/moinism/faltu)\n[![Coverage Status](https://coveralls.io/repos/github/moinism/faltu/badge.svg?branch=master)](https://coveralls.io/github/moinism/faltu?branch=master)\n[![npm version](https://badge.fury.io/js/faltu.svg)](https://badge.fury.io/js/faltu)\n[![License](https://img.shields.io/badge/license-MIT%20License-blue.svg?style=flat)](https://github.com/moinism/faltu/blob/master/LICENSE)\n\n\n# Faltu\n\n\u003e Search sort, filter, limit and iterate over an array of objects in Mongo-style.\n\n\n## Installation\n\n\nIn __NodeJS__:\n\n````bash\nnpm install faltu --save\n````\n\nFor other projects simply \u003ca href=\"https://raw.githubusercontent.com/moinism/faltu/master/build/faltu.min.js\"\ntarget=\"_blank\"\u003edownload\u003c/a\u003e and include the file in your pages:\n\n````html\n\u003cscript src=\"faltu.min.js\"\u003e\u003c/script\u003e\n````\n\n## Usage\n\nAll the data passed is expected to be an array or objects.\n\ne.g:\n````\n[array, array, ..., array]\n````\n\nAll the data returned is also of the same type.\n\nFor example:\n\n````javascript\nvar data = [{\n  name: \"John\",\n  age: 16\n},{\n  name: \"Doe\",\n  age: 18\n},{\n  name: \"Smith\",\n  age: 22\n}];\n````\n\nPass the array to constructor:\n\nIn __NodeJS__:\n\n````javascript\nvar Faltu = require('faltu');\nvar faltuData = new Faltu(data);\n````\n\nIn other environments:\n\n````javascript\nvar faltuData = new Faltu(data);\n````\n\n\n### Searching\n\nYou can use `find` method for searching.\nSearch for all the guys who are 18 years of age:\n\n```javascript\nvar newData = new Faltu(data).find({\n  age: 18\n}).get();\n```\n\n`newData` would look something like:\n\n```javascript\n[{\n  name: \"Doe\",\n  age: 18\n}]\n```\n\nYou should always call `get` at the end if you want an array back. Or It'll just return the `faltu` instance.\n\n\nSearch for all the guys who are 18 years of age or older:\n\n```javascript\nvar newData = new Faltu(data).find({\n  age: {\n    $gte: 18 // $gte is similar to \u003e= (greater than or equal to)\n  }\n}).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"Doe\",\n  age: 18\n},{\n  name: \"Smith\",\n  age: 22\n}]\n```\n\nOther supported comparison operators in `find` are:\n\n- `$lt`: \u003c\n- `$lte`: \u003c=\n- `$gt`: \u003e\n- `$ne`: !=\n\nSearch for all the guys who are 18 or 16 years of age:\n\n```javascript\nvar newData = new Faltu(data).find({\n  age: [16, 18]\n}).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"John\",\n  age: 16\n},{\n  name: \"Doe\",\n  age: 18\n}]\n```\n\nPassing `null`, empty object `{}` or nothing to `find` means not performing any search. `find` accepts options as second argument.\n\ne.g:\n\n```javascript\nvar newData = new Faltu(data).find({\n  age: [16, 18]\n}, {\n  sort: {\n    age: -1\n  }\n}).get();\n```\n\nWill return the data in descending order by `age`. Other than `sort` you can also pass:\n\n- `skip`\n- `limit`\n- `unique`\n\n\n### Sorting\n\nUse `sort` to sort the result in descending order by `age`:\n\n```javascript\nvar newData = new Faltu(data).find({\n  age: [16, 18]\n}).sort({\n  age: -1 // 1 = ASC, -1 = DESC\n}).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"Doe\",\n  age: 18\n},{\n  name: \"John\",\n  age: 16\n}]\n```\n\n### Limit\n\nLet's get only 1 object back:\n\n```javascript\nvar newData = new Faltu(data).find().limit(1).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"John\",\n  age: 16\n}]\n```\n\n\n### Skip\n\nLet's skip 1st object:\n\n```javascript\nvar newData = new Faltu(data).find().skip(1).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"Doe\",\n  age: 18\n},{\n  name: \"Smith\",\n  age: 22\n}]\n```\n\n\n### Skip \u0026 Limit\n\nLet's skip 1st object:\n\n```javascript\nvar newData = new Faltu(data).find().skip(1).limit(1).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"Doe\",\n  age: 18\n}]\n```\n\n\n### Unique\n\nYou can have result returned that is unique by a key.\n\n```javascript\nvar newData = new Faltu(data).find().unique('age').get();\n```\n\n\n### Filtering\n\nYou can also perform `jQuery`-esque filtering yourself. Call `filter` method, pass a `function`.\n\n\n```javascript\nvar newData = new Faltu(data).find().filter(function (person) {\n  return person.age == 16; // return true if you want to keep the object\n}).get();\n```\n\n`newData`:\n\n```javascript\n[{\n  name: \"John\",\n  age: 16\n}]\n```\n\n### Iterate\n\n`each` iterates over all the records returned.\n\n\n````javascript\nvar newData = new Faltu(data).find(null).each(function(person, index){\n  console.log('User name:', person.name);\n});\n````\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinism%2Ffaltu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoinism%2Ffaltu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinism%2Ffaltu/lists"}