Package Exports
- json-function
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-function) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Active Record
Full Size ~5.292 kb
Install
yarn add json-function
npm install json-function
Usage
Full class
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
import JsonFunction from 'json-function';
const result = JsonFunction
.where({ completed: false })
.select(["title", "completed"])
.orderBy("title", "DESC")
.limit(2)
.get(data);
or Standart
import JsonFunction from 'json-function';
JsonFunction.where({ completed: false });
JsonFunction.select(["title", "completed"]);
JsonFunction.orderBy("title", "DESC");
JsonFunction.limit(2);
const result = JsonFunction.get(data);
Output
[
{
title: "quis ut nam facilis et officia qui",
completed: false
},
{
title: "fugiat veniam minus",
completed: false
}
]
Config
resetRecord
JsonFunction.limit(2).get(data);
console.log(JsonFunction.option.limit); // null
console.log(JsonFunction.data); // []
JsonFunction.limit(2).get(data, { resetRecord: false });
console.log(JsonFunction.option.limit); // [2, 0]
console.log(JsonFunction.data); // [{..}, {..}]
// Manual Reset Method
JsonFunction.reset();
Methods
Instead of an entire "class", you can use only the methods you need.
Where
Size 1.004 kb
import { Where } from 'json-function';
// Single
// (completed === false)
Where(data, { completed: false });
// Multiple (or)
// (completed === false || userId === 2)
Where(data, [{completed: false}, {userId: 2}]);
Select
Size 0,964 kb
import { Select } from 'json-function';
// Single
Select(data, "title");
// Multiple
Select(data, ["title", "completed"]);
Limit
Size 0.423 kb
import { Limit } from 'json-function';
// Limit
Limit(data, 2);
// Limit and Start
Limit(data, 2, 2);
OrderBy
Size 0.606 kb
import { OrderBy } from 'json-function';
OrderBy(data, "title", "DESC");