npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mind-flow-js

v1.0.1

Published

MindFlowJS =======

Downloads

6

Readme

MindFlowJS

MindFlowJS adds logic programming to JavaScript.

Installation

npm install mind-flow-js

getVar

returns logical variable

ask

returns a generator of answers

import {ask, getVar, equal, or} from 'mind-flow-js'

const name = getVar()
const people = (name) => {
    return or(
        equal(name, 'James'),
        equal(name, 'Robert'),
        equal(name, 'John')
    )
}

console.log(...ask([name], people(name)))
// [ 'James' ] [ 'Robert' ] [ 'John' ]

check

check if there is answer

import {check, equal, or} from 'mind-flow-js'

const people = (name) => {
    return or(
        equal(name, 'James'),
        equal(name, 'Robert'),
        equal(name, 'John')
    )
}

console.log(check(people('James')))
// true

console.log(check(people('Michael')))
// false

custom recursion function example

import {ask, equal, getVar, sub, mul, and, oneOf, lessOrEqual} from 'mind-flow-js'

const x = getVar()

const fact = (x, result) => {
    const x1 = getVar()
    const result1 = getVar()
    return () => 
      oneOf(
          and(
              lessOrEqual(x, 1),
              equal(result, 1)
          ),
          and(
              sub(x, 1, x1),
              fact(x1, result1),
              mul(x, result1, result)
          )
      )()
    
}

console.log(...ask([x], fact(10, x)))
// [ 3628800 ]

add

import {ask, getVar, add} from 'mind-flow-js'

const x = getVar()

const toSolve = add(2, 3, x)

console.log(...ask([x], toSolve))
// [ 5 ]

and

import {ask, getVar, and, equal} from 'mind-flow-js'

const x = getVar()
const y = getVar()
const z = getVar()

const toSolve = and(equal(x, y), equal(y, z), equal(z, 5))

console.log(...ask([x, y, z], toSolve))
// [ 5, 5, 5 ]

between

import {ask, getVar, between} from 'mind-flow-js'

const x = getVar()

const toSolve = between(1, 4, x)

console.log(...ask([x], toSolve))
// [ 1 ] [ 2 ] [ 3 ] [ 4 ]

div

import {ask, getVar, div} from 'mind-flow-js'

const x = getVar()

const toSolve = div(5, 2, x)

console.log(...ask([x], toSolve))
// [ 2.5 ]

equal

import {ask, getVar, equal} from 'mind-flow-js'

const x = getVar()

const toSolve = equal(x, 5)

console.log(...ask([x], toSolve))
// [ 5 ]

execFunc

import {ask, getVar, execFunc} from 'mind-flow-js'

const x = getVar()

const toSolve = execFunc(x, (a, b) => a + b, 5, 4)

console.log(...ask([x], toSolve))
// [ 9 ]

execMethod

import {ask, getVar, execMethod} from 'mind-flow-js'

const x = getVar()

const toSolve = execMethod([1, 2, 3], x, 'map', el => el * 2)

console.log(...ask([x], toSolve))
// [ [ 2, 4, 6 ] ]

getMember

import {ask, getVar, getMember} from 'mind-flow-js'

const x = getVar()

const toSolve = getMember([1, 2, 3], x, 'length')

console.log(...ask([x], toSolve))
// [ 3 ]

getMember

import {ask, getVar, getMember} from 'mind-flow-js'

const x = getVar()

const toSolve = getMember([1, 2, 3], x, 'length')

console.log(...ask([x], toSolve))
// [ 3 ]

greater

import {check, greater} from 'mind-flow-js'

console.log(check(greater(1, 5)))
// false
console.log(check(greater(7, 3)))
// true

greaterOrEqual

import {check, greaterOrEqual} from 'mind-flow-js'

console.log(check(greaterOrEqual(5, 5)))
// true
console.log(check(greaterOrEqual(3, 5)))
// false

int

import {ask, getVar, int} from 'mind-flow-js'

const x = getVar()

const toSolve = int(x)

console.log(...ask([x], toSolve, 5))
// [ 0 ] [ 1 ] [ -1 ] [ 2 ] [ -2 ]

less

import {check, less} from 'mind-flow-js'

console.log(check(less(5, 1)))
// false
console.log(check(greater(3, 7)))
// true

lessOrEqual

import {check, lessOrEqual} from 'mind-flow-js'

console.log(check(lessOrEqual(5, 5)))
// true
console.log(check(lessOrEqual(5, 3)))
// false

member

import {ask, getVar, member} from 'mind-flow-js'

const x = getVar()

const toSolve = member([1, 2, 3], x)

console.log(...ask([x], toSolve))
// [ 1 ] [ 2 ] [ 3 ]

mod

import {ask, getVar, mod} from 'mind-flow-js'

const x = getVar()

const toSolve = mod(25, 7, x)

console.log(...ask([x], toSolve))
// [ 4 ]

mul

import {ask, getVar, mul} from 'mind-flow-js'

const x = getVar()

const toSolve = mul(4, 8, x)

console.log(...ask([x], toSolve))
// [ 32 ]

int

import {ask, getVar, nat} from 'mind-flow-js'

const x = getVar()

const toSolve = nat(x)

console.log(...ask([x], toSolve, 5))
// [ 0 ] [ 1 ] [ 2 ] [ 3 ] [ 4 ]

not

import {ask, getVar, not, equal, and, or} from 'mind-flow-js'

const x = getVar()

const toSolve = and(
    or(equal(x, 1), equal(x, 2)),
    not(equal(x, 1))
)

console.log(...ask([x], toSolve))
// [ 2 ]

notEqual

import {ask, getVar, notEqual, equal, and, or} from 'mind-flow-js'

const x = getVar()

const toSolve = and(
    or(equal(x, 1), equal(x, 2)),
    notEqual(x, 1)
)

console.log(...ask([x], toSolve))
// [ 2 ]

num

import {ask, getVar, nat} from 'mind-flow-js'

const x = getVar()

const toSolve = num(x)

console.log(...ask([x], toSolve, 5))
// [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ]

oneOf

import {ask, getVar, oneOf, equal, and, greaterOrEqual} from 'mind-flow-js'

const x = getVar()

const toSolve = oneOf(
    and(greaterOrEqual(1, 2), equal(x, 1)),
    and(greaterOrEqual(2, 2), equal(x, 2)),
    and(greaterOrEqual(3, 2), equal(x, 3)),
)

console.log(...ask([x], toSolve))
// [ 2 ]

or

import {ask, getVar, or, equal, and, greaterOrEqual} from 'mind-flow-js'

const x = getVar()

const toSolve = or(
    and(greaterOrEqual(1, 2), equal(x, 1)),
    and(greaterOrEqual(2, 2), equal(x, 2)),
    and(greaterOrEqual(3, 2), equal(x, 3)),
)

console.log(...ask([x], toSolve))
// [ 2 ] [ 3 ]

add

import {ask, getVar, sub} from 'mind-flow-js'

const x = getVar()

const toSolve = sub(2, 3, x)

console.log(...ask([x], toSolve))
// [ -1 ]

tuple

import {ask, getVar, tuple} from 'mind-flow-js'

const x = getVar()
const y = getVar()
const z = getVar()

const toSolve = tuple(x, y, z)

console.log(...ask([x, y, z], toSolve, 10))
// [ 0, 0, 0 ] [ 0, 0, 1 ] [ 0, 1, 0 ] [ 1, 0, 0 ] [ 0, 0, 2 ]
// [ 0, 1, 1 ] [ 0, 2, 0 ] [ 1, 0, 1 ] [ 1, 1, 0 ] [ 2, 0, 0 ]