Filter your data according to its attributes in a quick and easy way ⚡
Reforged Logic is an open-source abstraction layer library that facilitates processing, allowing you to filter a dataset using logic principles. Reforged Logic is written in Typescript.
- Website: https://reforged.fr
- Community: Join us on Discord
Note: we take the reliability of Logic and the trust of our users very seriously. If you think you have discovered a security problem in the Logic
package, please report it to us in the issues section of the repository.
- Data structure: Creation of a binary tree for the distribution of conditions to facilitate processing.
- Filtering a dataset: Initialise the class, reference your conditions and data array and enjoy.
- Take advantage of the tools provided: A logical display of your conditions, a free parser!
npm install @reforged/logic
import { Logic } from '@reforged/logic'
export interface IUser {
firstname: string
lastname: string
email: string
numero: string
roles: string[]
permissions: string[]
}
const userData: IUser[] = [
{ firstname: 'Nathael', lastname: 'Bonnal', email: '[email protected]', numero: "123456789", permissions: [], roles: ["test"]},
{ firstname: 'Lorem', lastname: 'Ipsum', email: '[email protected]', numero: "987654321", permissions: [], roles: []}
]
const data = {
uid: '1',
kind: 'and',
nodes: [
{
uid: '2',
field: 'lastname',
operator: 'contains',
value: 'bonnal',
type: 'input',
},
{
uid: '3',
kind: 'or',
nodes: [
{
uid: '2231',
field: 'firstname',
operator: 'contains',
value: 'thibault',
type: 'input',
},
{
uid: '4',
field: 'roles',
operator: 'not contains',
value: 'admin',
type: 'select',
},
],
},
],
}
const logic = new Logic<IUser>(data, userData)
console.log(logic.getFormule().affiche())
// bonnal ∧ (thibault ∨ admin)
const filteredData = logic.filter()
See the LICENSE file for licensing information.