2.0.0 • Published 2 years ago

xor-js v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

xor-js

Node.js CI npm Version npm Downloads Monthly

This package provides a rudimentary XOR check of a list of arguments in JS. Given any arity of arguments it will return true iff only one of the arguments is truthy, otherwise, it will return false.

Example Usage

npm install xor-js
# XOR ;)
yarn add xor-js

A powerful application is to combine this package with invariant to create rules for your API.

import xor from 'xor-js';
import invariant from 'invariant';

function MyComponent({ primary, secondary, tertiary, ...props }) {
  invariant(xor(primary, secondary, tertiary), 'Only one of primary, secondary, or tertiary may be true.')
  
  return (...);
}

Credits

This was adapted and inspired from this post on Code Review.

2.0.0

2 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago