1.1.0 • Published 7 years ago
@njlr/vop v1.1.0
vop
Value-orientated programming tools for JavaScript 💎
yarn add @njlr/vopWhy?
JavaScript does not support custom value-types, but we can get most of the way there using the pipeline operator (|>) and a comparison library. 
The first concept we need to abstract away is equality. Here, an equality is defined as an object with hashCode and equals. JavaScript's default equality might look like this: 
const strictEquality = {
  hashCode: _ => 0, 
  equals: x => y => x === y, 
}; From an equality object, we can construct an equals function:
import { equalsFromEquality } from '@njlr/vop'; 
const equals = equalsFromEquality(strictEquality);
equals(1)(1) // true
// Or using |> ...
1 |> equals(1) // trueWe're almost there. This library implements structural equality, which has the behaviour we want!
import { equals } from '@njlr/vop';
const p = {
  x: 1, 
  y: 2,
};
p |> equals({ x: 1, y: 2}); // true
[ 1, 2, 3 ] |> equals([ 1, 2, 3]); // true
1 |> equals(1) // true
'abc' |> equals('abc') // trueDevelopment
Dependencies are managed by Yarn:
yarn install --pure-lockfileTo run all tests:
yarn test To build the library:
yarn build