
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
combine predicate (bool returning) functions with propositional logic connectives (and, or, not)
combine predicate (bool returning) functions with propositional logic connectives (and, or, not)
$ npm install connective
var connective = require('connective')
var or = connective.or
var and = connective.and
var not = connective.and
function wearsFlannel (person) {
return person.wearing === 'flannel'
}
function ridesBikes (person) {
return person.rides === 'bikes'
}
var isSquare = not(or(wearsFlannel, ridesBikes))
var isHipster = and(wearsFlannel, ridesBikes)
var isLumberjack = and(wearsFlannel, not(ridesBikes))
var people = {
jon: { wearing: 'flannel', rides: 'nothing'}
kurt: { wearing: 'flannel', rides: 'bikes'}
bob: { wearing: 'hoodie', rides: 'scooters'}
}
for(var name in people) {
var person = people[name]
console.log(name, isSquare(person), isHipster(person), isLumberjack(person))
}
In propositional logic, boolean statements are joined together by connectives. Logicians would call them conjunctions, disjunctions, and negations, but programmers know them as &&
, ||
, and !
. The problem with using these language-level connective operators is that they apply at evaluation time, and thus aren't very composable.
Functions which take a value and return a boolean are known as predicates. They are useful, for example, in conditional branching, validation, and business rules.
The functions in connective
let you compose predicates into composite expressions which can be used as functions and evaluated later against other data.
In describing function signatures below, Predicate
is a function which takes any number of arguments and returns a boolean
: function(...) => boolean
connective.or: function (term1 : Predicate, ..., termN : Predicate) => Predicate
Returns a Predicate combining one or more Predicate terms with a logical or
(disjunction), roughly equivalent to writing
function (x) { return Predicate1(x) || Predicate2(x) }
The returned Predicate will pass through its this
context and arguments to each of the Predicate terms which are necessary to evaluate the expression.
connective.and: function (term1 : Predicate, ... termN : Predicate) => Predicate
Returns a Predicate combining one or more Predicate terms with a logical and
(conjunction), roughly equivalent to writing
function (x) { return Predicate1(x) && Predicate2(x) }
The returned Predicate will pass through its this
context and arguments to each of the Predicate terms.
connective.not: function (term : Predicate) => Predicate
Returns a Predicate negating term
, roughly equivalent to writing
function (x) { return !Predicate(x) }
The returned Predicate will pass through its this
context and arguments to term
$ npm install
$ npm test
jden jason@denizac.org
MIT. (c) 2013 Agile Diagnosis. See LICENSE.md
FAQs
combine predicate (bool returning) functions with propositional logic connectives (and, or, not)
The npm package connective receives a total of 1,276 weekly downloads. As such, connective popularity was classified as popular.
We found that connective demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.