• Stars
    star
    288
  • Rank 143,818 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

invert-color

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

© 2021, 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.

More Repositories

1

accesscontrol

Role and Attribute based Access Control for Node.js
TypeScript
2,132
star
2

geolocator

A utility for getting geo-location information via HTML5 and IP look-ups, geocoding, address look-ups, distance and durations, timezone information and more...
JavaScript
641
star
3

docma

A powerful tool to easily generate beautiful HTML documentation from JavaScript (JSDoc), Markdown and HTML files.
JavaScript
330
star
4

tasktimer

An accurate timer utility for running periodic tasks on the given interval ticks or dates. (Node and Browser)
TypeScript
121
star
5

perfy

A simple, light-weight NodeJS utility for measuring code execution in high-resolution real times.
JavaScript
55
star
6

jsonc

Everything you need in JSON land.
TypeScript
38
star
7

grunt-jasmine-nodejs

[DEPRECATED] Jasmine (v2.x) Grunt multi-task for NodeJS with built-in reporters such as Default (Console) Reporter, JUnit XML, NUnit XML, Terminal Reporter, TeamCity, TAP Reporter. Supports the latest Jasmine features: fdescribe, fit, beforeAll, afterAll, etc...
JavaScript
35
star
8

custom-error-test

Compare and test various custom error implementations.
JavaScript
33
star
9

alfred-video-downloader

Video Downloader is an Alfred workflow written in Bash/Shell for easily downloading videos (and/or extracting audio) from various websites such as YouTube, Vimeo, DailyMotion and more...
Shell
32
star
10

jasmine-console-reporter

Progressive Console Reporter for Jasmine. Outputs detailed test results to the console, with beautiful layout and colors.
JavaScript
32
star
11

notation

Utility for modifying / processing the contents of Javascript objects via object notation strings or globs.
JavaScript
28
star
12

jsdoc-x

Parser for outputting a Javascript object from documented code via JSDoc's explain (-X) command.
JavaScript
13
star
13

re

RegExp API for Humans!
JavaScript
4
star
14

json-more

Deprecated. Use jsonc instead.
JavaScript
3
star
15

grunt-docma

DEPRECATED! Instead use Docma in your npm scripts.
JavaScript
2
star
16

ocli

CLI tools for most used operations and development workflows.
JavaScript
1
star
17

onury.github.io

Documentation for my libraries, apps...
HTML
1
star
18

tilo

Tiny logger with styles and levels for Node/TypeScript.
TypeScript
1
star