# rondel

> Javascript library that makes use of the Proxy API to control objects through the use of handlers.

Latest version **1.1.0** (published 2019-08-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install rondel
pnpm add rondel
yarn add rondel
bun add rondel
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-08-16 |
| First published | 2019-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 283 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alfredo Narvaez Docimo |
| Maintainers | alfdocimo |
| Keywords | library, starter, es6 |

## Links

- npm: https://www.npmjs.com/package/rondel
- Repository: https://github.com/alfdocimo/rondel
- Issues: https://github.com/alfdocimo/rondel/issues
- npm.io page: https://npm.io/package/rondel

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-08-16
- 1.0.6 — 2019-06-28

## README

_Created by: Alfredo Narváez, 2019_

# 🛡️ Rondel

⚙️ **Travis CI** 🛠️

[![Build Status](https://travis-ci.com/alfdocimo/rondel.svg?branch=master)](https://travis-ci.com/alfdocimo/rondel)

👩‍🔬 **SonarQube** 👨‍🔬

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=alert_status)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=bugs)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=code_smells)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=coverage)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=ncloc)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=security_rating)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=alfdocimo_rondel&metric=sqale_index)](https://sonarcloud.io/dashboard?id=alfdocimo_rondel)

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_

![rondeljs](https://i.imgur.com/St4R0OL.png)

# Installing

First things first! You gotta install `rondel` as a dependency, so go ahead and run:

```
yarn add -D rondel
```

or if you're using npm:

```
npm install --save-dev rondel
```

Okay! Once that's done, you're ready to go!

# Protecting Objects:

Let's say you want to create a protected `Object`

```js
import Rondel from 'rondel';

const rondel = new Rondel();

const myObj = rondel.create().protected({
  obj: { name: 'John', lastName: 'Doe' },
  modifiers: {},
});

console.log(myObj.randomProp); // unset property
```

How about controlling the undefined props of our objects?

```js
import Rondel from 'rondel';

const rondel = new Rondel();

const myObj = rondel.create().protected({
  obj: { name: 'John', lastName: 'Doe' },
  modifiers: { exposeDefault: [] },
});

console.log(myObj.randomProp); // []
```

Alright... how about restricting setting properties?

```js
import Rondel from 'rondel';

const rondel = new Rondel();

const myObj = rondel.create().protected({
  obj: { name: 'John', lastName: 'Doe' },
  modifiers: { exposeDefault: [], setNotAllowed: true },
});

console.log(myObj.randomProp); // []

myObj.addPropHere = 'Hello World!'; // Will throw error
```

# Pseudo Type Validation

_Rondel_ has a built-in type validation that can be triggered along with `validateTypes: true` on the `modifiers` object.
We can then specify an array of the type of properties that we want to validate, so we end up getting something like this:

```js
const myObj = rondel.create().protected({
  obj: { name: 'John', lastName: 'Doe' },
  modifiers: { validateTypes: true, areStrings: ['lastName', 'name'] },
});
```

if we then proceed to change `name` to a number like this:

```js
myObj.name = 123;
```

A TypeError with the message _Expected a string value for property name_ will be thrown.

Currently supported:

- areStrings
- areNumbers
- areObjects

For more information please visit the [Test file](tests/test.spec.js)

# Querying Objects by props

Proxies are very powerful. They also allow us to access dynamically generated properties.

Let's look at the following snippet:

```js
const arr = rondel.create().searchable([
  {
    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

```js
arr.findWhereNameEquals('John'); // will give us all the objects that contain John in the name property
```

## Other Examples

```js
arr.findWhereNationalityIsNull(); // will give us all the objects that contain null in the nationality property
```

```js
arr.findWhereSkillsIncludes('JavaScript'); // will give us all the objects that contain JavaScript inside an array of skills.
```

Currently supported methods:

**findWhereXEquals**

Returns an array of objects of all matching <X> objects to value.

```ts
findWhereXEquals(value: any) : [{}];
```

**findWhereXIsNull**

Returns an array of objects of all matching <X> null objects.

```ts
findWhereXIsNull() : [{}];
```

**findWhereXIsUndefined**

Returns an array of objects of all matching <X> undefined objects.

```ts
findWhereXIsUndefined() : [{}];
```

**findWhereXIsEmpty**

Returns an array of objects of all matching <X> Empty objects.

```ts
findWhereXIsEmpty() : [{}];
```

**findWhereXIsIncludes**

Returns an array of objects of all matching <X> to the value/s provided.

```ts
findWhereXIsIncludes(value: any) : [{}];
```

**findWhereXIsLowerThan** & **findWhereXIsGreaterThan**

Returns an array of objects of all matching <X> wether is lower or greater than a value provided.

```ts
findWhereXIsLowerThan(value: any) : [{}];
findWhereXIsGreaterThan(value: any) : [{}];
```

---
_Source: https://npm.io/package/rondel · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
