Socket
Socket
Sign inDemoInstall

picocolors

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

18

package.json
{
"name": "picocolors",
"version": "0.1.0",
"type": "module",
"main": "./picocolors.cjs",
"module": "./picocolors.js",
"exports": {
".": {
"require": "./picocolors.cjs",
"import": "./picocolors.js",
"default": "./picocolors.js"
},
"./package.json": "./package.json"
},
"version": "0.2.0",
"main": "./picocolors.js",
"types": "./picocolors.d.ts",
"browser": {
"./picocolors.js": "./picocolors.browser.js",
"./picocolors.cjs": "./picocolors.browser.cjs"
"./picocolors.js": "./picocolors.browser.js"
},

@@ -19,0 +9,0 @@ "sideEffects": false,

@@ -1,2 +0,4 @@

let x=(v)=>v,f=false;
export {f as isColorSupported,x as reset,x as bold,x as dim,x as italic,x as underline,x as inverse,x as hidden,x as strikethrough,x as black,x as red,x as green,x as yellow,x as blue,x as magenta,x as cyan,x as white,x as gray,x as bgBlack,x as bgRed,x as bgGreen,x as bgYellow,x as bgBlue,x as bgMagenta,x as bgCyan,x as bgWhite};
var x=String;
var create=function() {return {isColorSupported:false,reset:x,bold:x,dim:x,italic:x,underline:x,inverse:x,hidden:x,strikethrough:x,black:x,red:x,green:x,yellow:x,blue:x,magenta:x,cyan:x,white:x,gray:x,bgBlack:x,bgRed:x,bgGreen:x,bgYellow:x,bgBlue:x,bgMagenta:x,bgCyan:x,bgWhite:x}};
module.exports=create();
module.exports.createColors = create;

@@ -1,26 +0,32 @@

export let isColorSupported: boolean;
export function reset(input: string): string;
export function bold(input: string): string;
export function dim(input: string): string;
export function italic(input: string): string;
export function underline(input: string): string;
export function inverse(input: string): string;
export function hidden(input: string): string;
export function strikethrough(input: string): string;
export function black(input: string): string;
export function red(input: string): string;
export function green(input: string): string;
export function yellow(input: string): string;
export function blue(input: string): string;
export function magenta(input: string): string;
export function cyan(input: string): string;
export function white(input: string): string;
export function gray(input: string): string;
export function bgBlack(input: string): string;
export function bgRed(input: string): string;
export function bgGreen(input: string): string;
export function bgYellow(input: string): string;
export function bgBlue(input: string): string;
export function bgMagenta(input: string): string;
export function bgCyan(input: string): string;
export function bgWhite(input: string): string;
export type Formatter = (input: string | number | null | undefined) => string;
export interface Colors {
isColorSupported: boolean;
reset: Formatter;
bold: Formatter;
dim: Formatter;
italic: Formatter;
underline: Formatter;
inverse: Formatter;
hidden: Formatter;
strikethrough: Formatter;
black: Formatter;
red: Formatter;
green: Formatter;
yellow: Formatter;
blue: Formatter;
magenta: Formatter;
cyan: Formatter;
white: Formatter;
gray: Formatter;
bgBlack: Formatter;
bgRed: Formatter;
bgGreen: Formatter;
bgYellow: Formatter;
bgBlue: Formatter;
bgMagenta: Formatter;
bgCyan: Formatter;
bgWhite: Formatter;
}
export = Colors & { createColors: (enabled: boolean) => Colors };

@@ -1,53 +0,60 @@

import tty from "tty";
let tty = require("tty");
export let isColorSupported =
!("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
("FORCE_COLOR" in process.env ||
process.argv.includes("--color") ||
process.platform === "win32" ||
(tty.isatty(1) && process.env.TERM !== "dumb") ||
"CI" in process.env);
let isColorSupported =
!("NO_COLOR" in process.env || process.argv.includes("--no-color")) &&
("FORCE_COLOR" in process.env ||
process.argv.includes("--color") ||
process.platform === "win32" ||
(tty.isatty(1) && process.env.TERM !== "dumb") ||
"CI" in process.env);
function formatter(open, close, replace = open) {
return isColorSupported
? (string) => {
let index = string.indexOf(close, open.length);
return !~index
? open + string + close
: open + replaceClose(string, close, replace, index) + close;
}
: (string) => string;
return (input) => {
let string = "" + input;
let index = string.indexOf(close, open.length);
return !~index
? open + string + close
: open + replaceClose(string, close, replace, index) + close;
};
}
function replaceClose(string, close, replace, index) {
if (!~index) return string;
let start = string.substring(0, index) + replace;
let end = string.substring(index + close.length);
return start + replaceClose(end, close, replace, end.indexOf(close));
let start = string.substring(0, index) + replace;
let end = string.substring(index + close.length);
let nextIndex = end.indexOf(close);
return !~nextIndex ? start + end : start + replaceClose(end, close, replace, nextIndex);
}
export let reset = (s) => `\x1b[0m${s}\x1b[0m`;
export let bold = formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m");
export let dim = formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m");
export let italic = formatter("\x1b[3m", "\x1b[23m");
export let underline = formatter("\x1b[4m", "\x1b[24m");
export let inverse = formatter("\x1b[7m", "\x1b[27m");
export let hidden = formatter("\x1b[8m", "\x1b[28m");
export let strikethrough = formatter("\x1b[9m", "\x1b[29m");
export let black = formatter("\x1b[30m", "\x1b[39m");
export let red = formatter("\x1b[31m", "\x1b[39m");
export let green = formatter("\x1b[32m", "\x1b[39m");
export let yellow = formatter("\x1b[33m", "\x1b[39m");
export let blue = formatter("\x1b[34m", "\x1b[39m");
export let magenta = formatter("\x1b[35m", "\x1b[39m");
export let cyan = formatter("\x1b[36m", "\x1b[39m");
export let white = formatter("\x1b[37m", "\x1b[39m");
export let gray = formatter("\x1b[90m", "\x1b[39m");
export let bgBlack = formatter("\x1b[40m", "\x1b[49m");
export let bgRed = formatter("\x1b[41m", "\x1b[49m");
export let bgGreen = formatter("\x1b[42m", "\x1b[49m");
export let bgYellow = formatter("\x1b[43m", "\x1b[49m");
export let bgBlue = formatter("\x1b[44m", "\x1b[49m");
export let bgMagenta = formatter("\x1b[45m", "\x1b[49m");
export let bgCyan = formatter("\x1b[46m", "\x1b[49m");
export let bgWhite = formatter("\x1b[47m", "\x1b[49m");
function createColors(enabled) {
return {
isColorSupported: enabled,
reset: enabled ? (s) => `\x1b[0m${s}\x1b[0m` : String,
bold: enabled ? formatter("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m") : String,
dim: enabled ? formatter("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m") : String,
italic: enabled ? formatter("\x1b[3m", "\x1b[23m") : String,
underline: enabled ? formatter("\x1b[4m", "\x1b[24m") : String,
inverse: enabled ? formatter("\x1b[7m", "\x1b[27m") : String,
hidden: enabled ? formatter("\x1b[8m", "\x1b[28m") : String,
strikethrough: enabled ? formatter("\x1b[9m", "\x1b[29m") : String,
black: enabled ? formatter("\x1b[30m", "\x1b[39m") : String,
red: enabled ? formatter("\x1b[31m", "\x1b[39m") : String,
green: enabled ? formatter("\x1b[32m", "\x1b[39m") : String,
yellow: enabled ? formatter("\x1b[33m", "\x1b[39m") : String,
blue: enabled ? formatter("\x1b[34m", "\x1b[39m") : String,
magenta: enabled ? formatter("\x1b[35m", "\x1b[39m") : String,
cyan: enabled ? formatter("\x1b[36m", "\x1b[39m") : String,
white: enabled ? formatter("\x1b[37m", "\x1b[39m") : String,
gray: enabled ? formatter("\x1b[90m", "\x1b[39m") : String,
bgBlack: enabled ? formatter("\x1b[40m", "\x1b[49m") : String,
bgRed: enabled ? formatter("\x1b[41m", "\x1b[49m") : String,
bgGreen: enabled ? formatter("\x1b[42m", "\x1b[49m") : String,
bgYellow: enabled ? formatter("\x1b[43m", "\x1b[49m") : String,
bgBlue: enabled ? formatter("\x1b[44m", "\x1b[49m") : String,
bgMagenta: enabled ? formatter("\x1b[45m", "\x1b[49m") : String,
bgCyan: enabled ? formatter("\x1b[46m", "\x1b[49m") : String,
bgWhite: enabled ? formatter("\x1b[47m", "\x1b[49m") : String,
};
}
module.exports = createColors(isColorSupported);
module.exports.createColors = createColors;

@@ -8,5 +8,5 @@ # picocolors

```javascript
import { green, italic } from "picocolors";
import pc from "picocolors";
console.log(green(`How are ${italic(`you`)} doing?`));
console.log(pc.green(`How are ${pc.italic(`you`)} doing?`));
```

@@ -16,3 +16,3 @@

- 3x faster and 10x smaller than `chalk`
- [TypeScript](https://www.typescriptlang.org/) & [Flowtype](https://flow.org/) support
- [TypeScript](https://www.typescriptlang.org/) support
- [`NO_COLOR`](https://no-color.org/) friendly

@@ -23,25 +23,4 @@ - Node.js v6+ & browsers support

- No dependencies and the smallest `node_modules` footprint
- Tree-shakeable (in case a Node.js package needs it?)
## Prior Art
Credits go to the following projects:
- [Nanocolors](https://github.com/ai/nanocolors) by [@ai](https://github.com/ai)
- [Colorette](https://github.com/jorgebucaran/colorette) by [@jorgebucaran](https://github.com/jorgebucaran)
- [Kleur](https://github.com/lukeed/kleur) by [@lukeed](https://github.com/lukeed)
- [Colors.js](https://github.com/Marak/colors.js) by [@Marak](https://github.com/Marak)
- [Chalk](https://github.com/chalk/chalk) by [@sindresorhus](https://github.com/sindresorhus)
## Replacing nanocolors
Just replace imports
```diff
-import { green, italic } from 'nanocolors';
+import { green, italic } from 'picocolors';
```
## API
The same as in [`nanocolors`](https://github.com/ai/nanocolors#api)
## Docs
Read **[full docs](https://github.com/alexeyraspopov/picocolors#readme)** on GitHub.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc