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 ntcjsVerified import paths — ran on the pinned version, not inferred.
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.
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.
Destructure the array immediately after calling `ntc.name()` for better readability and maintainability: `const [rgbValue, colorName, isExactMatch] = ntc.name('#HEX');`.Always ensure the input is a 6-digit hexadecimal string prefixed with '#', such as '#RRGGBB'. Validate user input if colors are dynamic.
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.
Call the `name` method: `ntc.name('#6195ED');`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');`.Access array elements by index: `n_match[1]` for the name. For better readability, destructure the array: `const [rgb, name, exact] = ntc.name('#HEX');`.No dependency data recorded yet.