Registry / serialization / ternary

ternary

JSON →
library0.1jsnpmunverified

This utility package generates a string representing a JavaScript ternary conditional statement (`condition ? whenTruthy : whenFalsy`). It is currently at version 1.0.0, published over a decade ago in 2013, indicating it is no longer actively maintained. The package functions as a basic string concatenation tool for programmatically constructing conditional expressions, rather than providing any runtime evaluation capabilities. Its core differentiator is its singular focus on producing a standard ternary operator string, which can be useful in scenarios requiring dynamic code generation or templating where the resulting expression needs to be embedded into a larger script. It offers no advanced parsing, validation, or execution features, simply combining three input strings into the 'condition ? expr1 : expr2' format.

npm install ternary
INSTALL
IMPORT
SIG · TERNARY
T
ternary
serializationjavascriptv0.1
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.

ternary
const ternary = require('ternary')
import ternary from 'ternary'
This package is CommonJS-only and does not support ES Modules natively.
ternary
import { ternary } from 'ternary'
The package exports a single default function, not named exports. It is also CommonJS-only.

Demonstrates how to use the `ternary` function to generate a JavaScript ternary expression string.

const ternary = require('ternary'); const isActiveCondition = 'user.status === "active"'; const displayTruthy = '"User is active"'; const displayFalsy = '"User is inactive"'; const ternaryString = ternary(isActiveCondition, displayTruthy, displayFalsy); console.log(ternaryString); // Expected output: user.status === "active" ? "User is active" : "User is inactive" // To actually evaluate this string, you would typically use it in a larger code context // For example: // const user = { status: 'active' }; // const result = eval(ternaryString); // WARNING: eval is dangerous and should generally be avoided // console.log(result);
Debug
Known issues
gotchaThe `ternary` function returns a string representation of a ternary expression, not an evaluated result. Users must integrate this string into their code for execution, often in scenarios like code generation or templating. It does not perform any runtime evaluation itself.
fix
Understand that the output is a string. If runtime evaluation is needed, ensure the string is correctly used within an executable JavaScript context (e.g., template literals, dynamic function creation, or with extreme caution, `eval`).
affects: >=1.0.0
breakingThis package is CommonJS-only. It does not provide native ES Module (ESM) support, meaning `import` statements will fail in pure ESM environments.
fix
If using an ESM project, you may need to configure your bundler (e.g., Webpack, Rollup) to handle CommonJS modules, or use a dynamic `import()` statement if supported by your runtime. Prefer `require()` in Node.js CJS environments.
affects: >=1.0.0
deprecatedThe package `ternary` (version 1.0.0) was last published 11 years ago and is considered abandoned. There are no ongoing updates, bug fixes, or new feature development expected. It has minimal dependents.
fix
Consider its static nature when integrating. For critical applications, evaluate if a simple string literal or a more modern, actively maintained string utility would be a safer or more flexible alternative.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (intermediate value)(...) is not a function
Attempting to use an ES Module `import` statement in a CommonJS-only package, or incorrectly trying to call a non-existent default export.
fix
Ensure you are using `const ternary = require('ternary')` for CommonJS environments. This package does not have named exports or native ESM support.
ReferenceError: ternary is not defined
The package was not correctly imported or required, or the variable name `ternary` is shadowed or out of scope.
fix
Verify that `const ternary = require('ternary')` is present and correctly positioned in your CommonJS file. In ESM contexts, you cannot directly import this CJS module without special bundler configuration.
Upgrade
Version history
0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
ternary — npm install ternary · libregistry