xor-js

2.0.0 • Public • Published

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.

/xor-js/

    Package Sidebar

    Install

    npm i xor-js

    Weekly Downloads

    7

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    2.94 kB

    Total Files

    4

    Last publish

    Collaborators

    • jakxz