1.0.0 • Published 3 years ago
logika v1.0.0
Node package for logic operations
Realeased operators
- Not
- Or
- And
Installation
npm i logika
Import
- Node
```js const { or, and } = require('logika') ```
- Babel
```js import { or, and } from 'logika' ```
Usage
const users = [
{ _id: 1, age: 28, name: 'John' },
{ _id: 2, age: 30, name: 'Garrus' },
{ _id: 3, age: 34, name: 'Jane' },
{ _id: 4, age: 32, name: 'Grunt' }
]
const nameStartsWith = char => user => user.name.split('')[0] === char
const olderThen = age => user => user.age > age
console.log(
users
.filter(and(nameStartsWith('J'), olderThen(30)))
.map(user => user._id)
) // output is [ 3 ]
console.log(
users
.filter(or(nameStartsWith('G'), olderThen(33)))
.map(user => user._id)
) // output is [ 2, 3, 4 ]
const john = users[0]
console.log(not(nameStartsWith('A'))(john)) // output is true
1.0.0
3 years ago