xor-js
Basic XOR in JS
Last updated 3 months ago by jakxz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install xor-js 
SYNC missed versions from official npm registry.

xor-js

Build Status codecov 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 (...);
}

You will need the --harmony flag or babel for node 4.9.x.

Credits

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

Current Tags

  • 1.0.5                                ...           latest (3 months ago)

6 Versions

  • 1.0.5                                ...           3 months ago
  • 1.0.4                                ...           10 months ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 6
Last Month 0
Dependencies (0)
None
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |