Json Function
It allows you to use methods such as where, limit, select, orderBy on JSON data.
Json-Function provides a lot of useful functions especially for your json data. It contains the methods you need too much to eliminate unnecessary code repetition.
You can use the Json-Function methods separately, but it is possible to use them all together. You can also chain it.
Github repository for your stars.
Usage
Install
$ npm install json-function
Import
import JsonFunction from 'json-function';
Usage
Example Data
const data = [
{
userId: 1,
id: 1,
title: "delectus aut autem",
completed: false
},
{
userId: 1,
id: 2,
title: "quis ut nam facilis et officia qui",
completed: false
},
{
userId: 1,
id: 3,
title: "fugiat veniam minus",
completed: false
},
{
userId: 1,
id: 4,
title: "et porro tempora",
completed: true
}
];
Chaining Syntax
JsonFunction
.where({ completed: false })
.select(["title", "completed"])
.orderBy("title", "DESC")
.limit(2)
.get(data);
Output
[
{
title: "quis ut nam facilis et officia qui",
completed: false
},
{
title: "fugiat veniam minus",
completed: false
}
];
Basic Syntax
JsonFunction.where({ completed: false });
JsonFunction.select(["title", "completed"]);
JsonFunction.orderBy("title", "DESC");
JsonFunction.limit(2);
const result = JsonFunction.get(data);
getQuery
Create a query and use it at any time.
const queryTwoIncompleteTasks = JsonFunction
.where({ completed: false })
.select(["title", "completed"])
.limit(2)
.getQuery();
setQuery
JsonFunction.setQuery(queryTwoIncompleteTasks).get(data);
or
JsonFunction.get(data, { query: queryTwoIncompleteTasks });
Last updated
Was this helpful?