Registry / serialization / ntcjs
library1.1.3jsnpmunverified

NTCJS is a Node.js CommonJS-compatible wrapper for the original Name That Color JavaScript library by Chirag Mehta. It provides a straightforward utility to convert hexadecimal color codes (e.g., `#6195ED`) into human-readable color names, along with the closest matching RGB value and an exact match boolean. The current stable version, 1.1.3 (or 1.1.4 for `@trihargianto/ntcjs`), has not been updated in several years, indicating a maintenance or effectively abandoned status. It primarily targets CommonJS environments, but ships TypeScript types for enhanced developer experience. Its key differentiator is its simplicity and direct port of the well-known 'Name That Color' algorithm, without additional features like i18n or advanced color manipulation found in other libraries.

npm install ntcjs
INSTALL
IMPORT
SIG · NTCJS
N
ntcjs
serializationjavascriptv1.1.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.

ntc
const ntc = require('ntcjs');
import ntc from 'ntcjs';
The `ntcjs` package is explicitly designed for CommonJS environments. While bundlers might allow `import ntc from 'ntcjs';` for ESM projects, native Node.js ESM will require dynamic import or a CommonJS wrapper. TypeScript users typically use `import` syntax, and the provided types assist here, but it transpiles to `require` for CJS targets.
name
ntc.name('#6195ED');
ntc('#6195ED');
The main function to resolve a color name is a method on the imported `ntc` object, specifically `ntc.name()`. Calling `ntc` directly as a function will result in an error.
NTCResult
import type { NTCResult } from 'ntcjs';
import { NTCResult } from 'ntcjs';
As the library ships TypeScript types, you can import the `NTCResult` type for type-checking the output. Using `import type` ensures it's purely a type import and is removed during compilation, avoiding potential runtime issues with non-existent value imports.

This quickstart demonstrates how to import and use the `ntcjs` library to get the name of a given hexadecimal color code. It shows the structured array output including the closest RGB value, the color name, and whether it was an exact match. It uses `import` syntax suitable for TypeScript.

import { readFileSync } from 'node:fs'; import ntc from 'ntcjs'; // In a real ESM setup, this might require a bundler or Node.js --experimental-json-modules // Example of usage from the README const hexColor = '#6195ED'; const n_match = ntc.name(hexColor); const n_rgb = n_match[0]; // RGB value of closest match const n_name = n_match[1]; // Text string: Color name const n_exactmatch = n_match[2]; // True if exact color match console.log(`Input Hex: ${hexColor}`); console.log(`Closest RGB: ${n_rgb}`); console.log(`Color Name: ${n_name}`); console.log(`Exact Match: ${n_exactmatch}`); // Demonstrating with another color const anotherHex = '#FF0000'; const another_match = ntc.name(anotherHex); console.log(`\nInput Hex: ${anotherHex}`); console.log(`Closest RGB: ${another_match[0]}`); console.log(`Color Name: ${another_match[1]}`); console.log(`Exact Match: ${another_match[2]}`); // Demonstrating with a slightly off color const offHex = '#FE0001'; const off_match = ntc.name(offHex); console.log(`\nInput Hex: ${offHex}`); console.log(`Closest RGB: ${off_match[0]}`); console.log(`Color Name: ${off_match[1]}`); console.log(`Exact Match: ${off_match[2]}`);
Debug
Known issues
gotchaThe `ntcjs` package is primarily a CommonJS module. While it ships TypeScript types, native Node.js ESM environments might require specific `package.json` configurations (`"type": "module"` with `"exports"`) or dynamic `import()` to use it, or a bundler to transpile correctly.
fix
For Node.js ESM, consider using `import(pkgName)` for dynamic imports. For TypeScript, ensure your `tsconfig.json` `module` option is compatible (e.g., `"CommonJS"` or a bundler-friendly option) or configure your build system to handle CJS imports in ESM contexts. If you encounter `ERR_REQUIRE_ESM`, you'll need to adjust your module resolution strategy.
affects: >=1.0.0
gotchaThe `ntc.name()` function returns an array, not an object. Developers often forget the order of elements (RGB value, color name, exact match boolean) and might access `n_match.name` instead of `n_match[1]`.
fix
Destructure the array immediately after calling `ntc.name()` for better readability and maintainability: `const [rgbValue, colorName, isExactMatch] = ntc.name('#HEX');`.
affects: >=1.0.0
gotchaThe library expects hexadecimal color strings as input, typically prefixed with '#'. Providing invalid formats (e.g., shorthand hex, named colors, RGB/HSL strings, or hex without '#') may lead to incorrect results or errors. The original NTC library primarily deals with hex input.
fix
Always ensure the input is a 6-digit hexadecimal string prefixed with '#', such as '#RRGGBB'. Validate user input if colors are dynamic.
affects: >=1.0.0
deprecatedThe `ntcjs` package has not received updates for several years (version 1.1.3 published 5 years ago, although `@trihargianto/ntcjs` is 1.1.4 and 2 years old). While the core functionality is stable, it means no new features, performance improvements, or official security patches are likely to be released.
fix
For new projects requiring active maintenance or broader color space support (like HSL, CMYK, i18n, or more modern color names), consider alternatives like `chroma.js` or wrappers that build upon it, such as `@oz-tal/name-that-color-and-hue-i18n`, which actively maintain and extend similar functionality.
affects: <=1.1.3
Errors
Common errors & fixes
TypeError: ntc is not a function
Attempting to call the imported `ntc` module directly as a function instead of using its `name` method.
fix
Call the `name` method: `ntc.name('#6195ED');`
ReferenceError: require is not defined
Attempting to use `require()` in a Node.js ESM module context without proper configuration or transpilation.
fix
In a Node.js ESM project, use `import ntc from 'ntcjs';` if your setup (e.g., bundler or `package.json` `exports` field) allows interoperability, or consider dynamic import: `const ntc = await import('ntcjs');`.
Property 'name' does not exist on type 'string[]'.
Trying to access `n_match.name` on the array returned by `ntc.name()`, which is a common JavaScript mistake when an array is mistaken for an object with named properties.
fix
Access array elements by index: `n_match[1]` for the name. For better readability, destructure the array: `const [rgb, name, exact] = ntc.name('#HEX');`.
Upgrade
Version history
1.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
ntcjs — npm install ntcjs · libregistry