Registry / serialization / pure-conditions

pure-conditions

JSON →
library1.2.3jsnpmunverified

pure-conditions is a JavaScript utility library providing a collection of pure, isolated functions designed to simplify common conditional logic. It offers methods for tasks like checking for duplicates in arrays, determining if an object or array is empty, validating email formats, and string manipulations such as checking if a string ends with a specific substring. The current stable version is 1.2.3. As a small, focused utility, it doesn't adhere to a strict release cadence but updates as new common conditions are identified or minor improvements are made. Its key differentiators include its adherence to pure function principles (no side effects, predictable output) and the complete isolation of functions, which benefits bundlers and compilers by allowing for efficient tree-shaking and minimal bundle sizes. It focuses on functional programming paradigms for robustness and testability.

npm install pure-conditions
INSTALL
IMPORT
SIG · PURE-CONDITIONS
P
pure-conditions
serializationjavascriptv1.2.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

hasDuplicates
import { hasDuplicates } from 'pure-conditions';
const { hasDuplicates } = require('pure-conditions');
CommonJS `require` is shown in the README, but ESM `import` is preferred for modern Node.js and browser environments.
isEmpty
import { isEmpty } from 'pure-conditions';
import isEmpty from 'pure-conditions'; // Incorrect default import
All functions are named exports; there is no default export. Destructuring is required.
isEmail
import { isEmail } from 'pure-conditions';
require('pure-conditions').isEmail;
While functional, direct property access like `require('pkg').func` can sometimes lead to issues with bundlers or static analysis compared to explicit destructuring.

Demonstrates importing and using several utility functions like `hasDuplicates`, `isEmpty`, `endsWith`, and `isEmail` to perform common conditional checks.

import { hasDuplicates, isEmpty, endsWith, isEmail } from 'pure-conditions'; console.log('--- pure-conditions Quickstart ---'); // Check for duplicates in an array const listWithDuplicates = ['apple', 'banana', 'apple']; console.log(`Has duplicates (['apple', 'banana', 'apple']): ${hasDuplicates(listWithDuplicates)}`); // Check if an object is empty const emptyObject = {}; const filledObject = { id: 1 }; console.log(`Is {} empty? ${isEmpty(emptyObject)}`); console.log(`Is { id: 1 } empty? ${isEmpty(filledObject)}`); // Check if a string ends with another string const sentence = 'Hello, world!'; console.log(`'Hello, world!' ends with 'world!'? ${endsWith(sentence, 'world!')}`); console.log(`'Hello, world!' ends with 'universe'? ${endsWith(sentence, 'universe')}`); // Validate an email address const validEmail = 'test@example.com'; const invalidEmail = 'invalid-email'; console.log(`'test@example.com' is a valid email? ${isEmail(validEmail)}`); console.log(`'invalid-email' is a valid email? ${isEmail(invalidEmail)}`);
Debug
Known issues
gotchaThe library primarily uses named exports. Attempting to use a default import (e.g., `import PConditions from 'pure-conditions'`) will result in `undefined` or an error, as there is no default export.
fix
Always use named imports with destructuring: `import { functionName } from 'pure-conditions';`
affects: >=1.0.0
gotchaAs a 'pure' utility, functions are designed for immutable operations. While convenient, ensure you understand that these functions do not modify their inputs, but rather return a boolean or new value based on the condition.
fix
No fix needed, this is by design. Understand that functions like `hasDuplicates` do not change the array, they only evaluate it.
affects: >=1.0.0
gotchaOlder Node.js environments or build setups might require specific configuration for ESM `import` statements. The README's examples use CommonJS `require`, which is universally supported but less modern.
fix
For modern Node.js and bundlers, use ESM `import`. If targeting older environments, ensure your build setup transpiles ESM to CommonJS, or stick to `require()` if feasible for your module type.
affects: <14.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'hasDuplicates')
Attempting to call `hasDuplicates` on an `undefined` or incorrectly imported object, often due to a wrong import statement (e.g., default import or no destructuring).
fix
Ensure you are using named imports with destructuring: `import { hasDuplicates } from 'pure-conditions';` or `const { hasDuplicates } = require('pure-conditions');`
SyntaxError: Unexpected token '{'
Using `import { someFunction } from 'pure-conditions';` in a CommonJS module context (a file without `'type': 'module'` in `package.json` and `.js` extension, or a `.cjs` file).
fix
Either convert your file/project to an ESM module by setting `'type': 'module'` in `package.json` or rename the file to `.mjs`, or use CommonJS `require`: `const { someFunction } = require('pure-conditions');`
Upgrade
Version history
1.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
pure-conditions — npm install pure-conditions · libregistry