Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyraspopov committed May 14, 2024
1 parent a014200 commit 5f0c047
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [v1.0.1](https://github.com/alexeyraspopov/picocolors/releases/tag/v1.0.0)

- Updated color detection mechanism to work properly on Vercel Edge Runtime ([#64](https://github.com/alexeyraspopov/picocolors/pull/64))
- Remove use of recursion to avoid possible stack overflow for very long inputs ([#56](https://github.com/alexeyraspopov/picocolors/pull/56))

## [v1.0.0](https://github.com/alexeyraspopov/picocolors/releases/tag/v1.0.0)

- Removed several code elements to reduce the package size ([#31](https://github.com/alexeyraspopov/picocolors/pull/31))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picocolors",
"version": "1.0.0",
"version": "1.0.1",
"main": "./picocolors.js",
"types": "./picocolors.d.ts",
"browser": {
Expand Down
59 changes: 31 additions & 28 deletions picocolors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,37 @@ let replaceClose = (string, close, replace, index) => {
return result + string.substring(cursor)
}

let createColors = (enabled = isColorSupported) => ({
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,
})
let createColors = (enabled = isColorSupported) => {
let init = enabled ? formatter : () => String
return {
isColorSupported: enabled,
reset: init("\x1b[0m", "\x1b[0m"),
bold: init("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
dim: init("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
italic: init("\x1b[3m", "\x1b[23m"),
underline: init("\x1b[4m", "\x1b[24m"),
inverse: init("\x1b[7m", "\x1b[27m"),
hidden: init("\x1b[8m", "\x1b[28m"),
strikethrough: init("\x1b[9m", "\x1b[29m"),
black: init("\x1b[30m", "\x1b[39m"),
red: init("\x1b[31m", "\x1b[39m"),
green: init("\x1b[32m", "\x1b[39m"),
yellow: init("\x1b[33m", "\x1b[39m"),
blue: init("\x1b[34m", "\x1b[39m"),
magenta: init("\x1b[35m", "\x1b[39m"),
cyan: init("\x1b[36m", "\x1b[39m"),
white: init("\x1b[37m", "\x1b[39m"),
gray: init("\x1b[90m", "\x1b[39m"),
bgBlack: init("\x1b[40m", "\x1b[49m"),
bgRed: init("\x1b[41m", "\x1b[49m"),
bgGreen: init("\x1b[42m", "\x1b[49m"),
bgYellow: init("\x1b[43m", "\x1b[49m"),
bgBlue: init("\x1b[44m", "\x1b[49m"),
bgMagenta: init("\x1b[45m", "\x1b[49m"),
bgCyan: init("\x1b[46m", "\x1b[49m"),
bgWhite: init("\x1b[47m", "\x1b[49m"),
}
}

module.exports = createColors()
module.exports.createColors = createColors

0 comments on commit 5f0c047

Please sign in to comment.