@alfdocimo/rondel v1.0.5
Created by: Alfredo Narváez, 2019
🛡️ Rondel
⚙️ Travis CI 🛠️
👩🔬 SonarQube 👨🔬
Rondel is a library that makes use of the JavaScript Proxy API and exposes certain functionalities to protect & control objects through the use of handlers.
Why "Rondel"?
A rondel (ˈrɒndl) is a circular piece of metal used for protection in suits of armor

Installing
First things first! You gotta install rondel as a dependency, so go ahead and run:
yarn add -D rondelor if you're using npm:
npm install --save-dev rondelOkay! Once that's done, you're ready to go!
Protecting Objects:
Let's say you want to create a protected Object
import Rondel from 'rondel';
const rondel = new Rondel();
const myObj = rondel.createProtected({
obj: { name: 'John', lastName: 'Doe' },
modifiers: {},
});
console.log(myObj.randomProp); // unset propertyHow about controlling the undefined props of our objects?
import Rondel from 'rondel';
const rondel = new Rondel();
const myObj = rondel.createProtected({
obj: { name: 'John', lastName: 'Doe' },
modifiers: { exposeDefault: [] },
});
console.log(myObj.randomProp); // []Alright... how about restricting setting properties?
import Rondel from 'rondel';
const rondel = new Rondel();
const myObj = rondel.createProtected({
obj: { name: 'John', lastName: 'Doe' },
modifiers: { exposeDefault: [], setNotAllowed: true },
});
console.log(myObj.randomProp); // []
myObj.addPropHere = 'Hello World!'; // Will throw errorQuerying Objects by props
Proxies are very powerful. They also allow us to access dynamically generated properties.
Let's look at the following snippet:
const arr = rondel.getProtected([
{
name: 'John',
age: 30,
skills: ['React', 'Node'],
position: 'Sr Dev',
salary: 100000,
},
{ name: 'Mathew', age: 26, skills: ['JavaScript'], salary: 0 },
{
name: 'Claudia',
nationality: null,
age: 33,
skills: ['AWS', 'Azure', 'DevOps', 'JavaScript'],
salary: 80000,
},
]);By using findWhere<Property>Equals(<String>) we'll get all the matching results
arr.findWhereNameEquals('John')); // will give us all the object that contains JohnOther Examples
arr.findWhereNationalityIsNull()); // will give us all the object that contains Claudiaarr.findWhereSkillsIncludes('JavaScript')); // will give us all the object that contains MathewCurrently supported methods:
findWhereXEquals
Returns an array of objects of all matching objects to value.
findWhereXEquals(value: any) : [{}];findWhereXIsNull
Returns an array of objects of all matching null objects.
findWhereXIsNull() : [{}];findWhereXIsUndefined
Returns an array of objects of all matching undefined objects.
findWhereXIsUndefined() : [{}];findWhereXIsEmpty
Returns an array of objects of all matching Empty objects.
findWhereXIsEmpty() : [{}];findWhereXIsIncludes
Returns an array of objects of all matching to the value/s provided.
findWhereXIsIncludes(value: any) : [{}];findWhereXIsLowerThan & findWhereXIsGreaterThan
Returns an array of objects of all matching wether is lower or greater than a value provided.
findWhereXIsLowerThan(value: any) : [{}];
findWhereXIsGreaterThan(value: any) : [{}];6 years ago