XOR Utility Function
component-xor is a minuscule JavaScript utility package providing a single function, `xor(bool, bool)`, to compute the exclusive OR of two boolean values. Released under the MIT license, its latest version is 0.0.4, published in 2015. This package is part of the 'component' ecosystem, an early web package manager that predates modern module bundlers and is no longer actively maintained. Due to its age and the deprecation of its original ecosystem, it lacks modern features like ES Modules support and active development. Its key differentiator was its extreme simplicity and adherence to the 'component' philosophy, but it is now effectively abandoned. For new projects, developers should implement the simple XOR logic directly or use modern alternatives, as `component-xor` does not receive updates or support.
Common errors
-
TypeError: (0 , component_xor__WEBPACK_IMPORTED_MODULE_0__.xor) is not a function
cause Attempting to use ES Module `import { xor } from 'component-xor';` syntax in a project that expects CommonJS modules or when the bundler doesn't correctly handle CJS interoperability.fixReplace the import statement with the CommonJS `require()` syntax: `const xor = require('component-xor');`. -
ReferenceError: xor is not defined
cause The package was either not installed, or the import/require statement was incorrect, leading to the `xor` function not being available in the current scope.fixVerify that `component-xor` is listed in your `package.json` and `node_modules`. Ensure you have a correct `const xor = require('component-xor');` statement at the top of your file.
Warnings
- breaking This package and its original 'component' ecosystem are abandoned. It has not been updated since 2015 and will not receive bug fixes, security patches, or new features.
- gotcha The package is CommonJS-only and does not support ES Modules (`import`/`export`) syntax directly. Using `import` statements will cause runtime errors in modern environments unless transpiled or handled by a compatible module loader.
- gotcha Minimal functionality: `component-xor` only provides a basic boolean XOR. For bitwise XOR (`^`) or more advanced logical operations, this package is insufficient.
Install
-
npm install component-xor -
yarn add component-xor -
pnpm add component-xor
Imports
- xor
import { xor } from 'component-xor';const xor = require('component-xor');
Quickstart
const xor = require('component-xor');
console.log('XOR Truth Table:');
console.log(`true, true => ${xor(true, true)}`); // Expected: false
console.log(`true, false => ${xor(true, false)}`); // Expected: true
console.log(`false, true => ${xor(false, true)}`); // Expected: true
console.log(`false, false => ${xor(false, false)}`); // Expected: false
const a = true;
const b = false;
const c = true;
console.log(`\nCustom examples:`);
console.log(`xor(${a}, ${b}) is ${xor(a, b)}`);
console.log(`xor(${a}, ${c}) is ${xor(a, c)}`);
console.log(`xor(${b}, ${c}) is ${xor(b, c)}`);
// Demonstrating non-boolean input behavior (JavaScript coercion)
console.log(`\nCoercion examples:`);
console.log(`xor(1, 0) => ${xor(1, 0)}`); // Coerces to xor(true, false) => true
console.log(`xor(1, 1) => ${xor(1, 1)}`); // Coerces to xor(true, true) => false