npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

invert-color

v2.0.0

Published

Generates inverted (opposite) version of the given color.

Downloads

279,382

Readme

invert-color

build-status Coverage Status dependencies Known Vulnerabilities maintained
npm release downloads license typescript

© 2018, Onur Yıldırım (@onury). MIT License.

Generates inverted (opposite) version of the given color. (<1KB)

This passes a long test suite of Adobe Photoshop CC inverted colors...
Generating exactly the same results with it.

Invert Animation

Usage

npm i invert-color

// Node, CommonJS
const invert = require('invert-color');
// ES2015, JSNext
import invert from 'invert-color';
// TypeScript
import invert, { RGB, RgbArray, HexColor, BlackWhite } from 'invert-color';

For UMD in browser, use lib/invert.min.js. See other exports.

invert(color[, bw])

  • color : String|Array|Object
    Color in HEX string, RGB array or RGB object to be inverted.
  • bw : Boolean|Object
    Optional. A boolean value indicating whether the output should be amplified to black (#000000) or white (#ffffff), according to the luminance of the original color. You can set custom black/white values (and/or luminance threshold) by passing an object.
invert('#000')              // —> #ffffff
invert('#282b35')           // —> #d7d4ca

// input color as RGB array or object
invert([69, 191, 189])              // —> #ba4042
invert({ r: 249, g: 119, b: 121 })  // —> #068886

// amplify to black or white
invert('#282b35', true)     // —> #ffffff

// amplify to custom black or white color
invert('#282b35', { black: '#3a3a3a', white: '#fafafa' })     // —> #fafafa

// amplify with custom luminance threshold (default is invert.defaultThreshold = ~0.179)
invert('#282b35', { black: '#3a3a3a', white: '#fafafa', threshold: 0.01 })     // —> #3a3a3a

invert.asRGB(color[, bw])

Invert and output result as RGB object.

invert.asRGB('#fff')          // —> { r: 0, g: 0, b: 0 }

invert.asRgbArray(color[, bw])

Invert and output result as RGB array.

invert.asRgbArray('#000')      // —> [255, 255, 255]

bw option

This is useful in case, you need to create contrast (i.e. background vs foreground, for better readability). The animation at the top is a demonstration.

Contributing

Clone original project:

git clone https://github.com/onury/invert-color.git

Install (dev) dependencies:

npm install

Add tests into test/unit.test.ts and run:

npm run cover

Travis build should pass, coverage should not degrade.

Change-Log

v2.0.0 (2018-11-09)

  • Breaking: In order to be consistent; now using default export only. Added ESM, UMD, CommonJS bundles (with rollup). See Usage section.
  • In addition to main, package.json now also defines module, jsnext:main and browser.
  • Added threshold: number to BlackWhite options (interface). Fixes #16.
  • Added invert.defaultThreshold constant.

v1.5.0 (2018-08-22)

  • Re-written in TypeScript.
  • Added .asRGB() - alias of .asRgbObject().

v1.2.3 (2018-04-05)

v1.2.2 (2017-12-07)

  • Fixed an issue with UMD output. Fixes #7.
  • (Dev) Adapted webpack for UMD.

v1.2.0 (2017-11-24)

  • Added UMD support. (PR #6 by @criography - revised for latest Babel.)
  • (Dev) Migrated tests to Jest (dropped Jasmine).

v1.1.0 (2017-11-07)

  • Added ability to customize black/white color values. (PR #3 by @BrainCrumbz)
  • Fixed typo. (PR #1 by @villfa)
  • Minor revisions.

v1.0.0 (2017-08-22)

  • Initial version.

License

MIT.