react-sift
v1.0.0
Published
A simple query tool for React data structures
Maintainers
Readme
React Sift
A simple query tool for React data structures that allows you to filter, search, and manipulate JSON data using natural language queries.
Description
React Sift provides an Object Query Method (OQM) that enables you to query JSON arrays and objects using simple, intuitive commands. It's designed to make data manipulation and filtering more accessible for React applications.
Installation
npm install react-siftUsage
Basic Usage
import { oqm } from 'react-sift';
const data = [
{
id: 1000,
question_source: "vocab",
category: [{ id: 1000, title: "Vocabulary" }],
question_text: "pundit",
difficulty: "Medium",
// ... more properties
},
// ... more items
];
// Show available keys in the data
const keys = oqm(data, "show keys");
console.log(keys); // ['id', 'question_source', 'category', 'question_text', 'difficulty', ...]Query Examples (Coming Soon)
// Count items with specific criteria
const count = oqm(data, "count where difficulty = 'easy'");
// Sort data
const sorted = oqm(data, "sort by difficulty");
const sortedDesc = oqm(data, "sort by difficulty desc");
// Filter and limit results
const filtered = oqm(data, "where difficulty = 'medium' limit 10");
// Group data
const grouped = oqm(data, "group by difficulty");
// Show available keys
const keys = oqm(data, "show keys");API Reference
oqm(data: JsonArray, query: string): any
The main function for querying data.
Parameters:
data: An array of JSON objects to queryquery: A string containing the query command
Returns:
- The result of the query operation
Supported Query Commands
show keys- Returns the keys available in the first object of the arraycount where [condition]- Counts items matching the specified conditionsort by [field]- Sorts the data by the specified fieldsort by [field] desc- Sorts the data by the specified field in descending orderwhere [condition]- Filters data based on the specified conditionlimit [number]- Limits the number of resultsgroup by [field]- Groups data by the specified field
Development
Prerequisites
- Node.js
- npm or yarn
- TypeScript
Setup
- Clone the repository
- Install dependencies:
npm install
Build
npm run buildTest
npm testLicense
MIT License - see the LICENSE file for details.
Author
Tom Zhang
