logika
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Node package for logic operations

Realeased operators

  • Not
  • Or
  • And

Installation

npm i logika

Import

  • Node
     const { or, and } = require('logika')
  • Babel
     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

Package Sidebar

Install

npm i logika

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

10.7 kB

Total Files

25

Last publish

Collaborators

  • voiceless