Skip to content

Commit

Permalink
Remove c.js. Close #12.
Browse files Browse the repository at this point in the history
  • Loading branch information
jojibucaran committed Aug 26, 2017
1 parent e8b3613 commit 6a3d87f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 234 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
example.js
node_modules
clor.js
yarn.lock
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,5 +1,6 @@
language: node_js
node_js:
- 8
- 7
- 6
- 5
Expand Down
46 changes: 19 additions & 27 deletions README.md
@@ -1,75 +1,64 @@
# clor
# Clor
[![](http://img.shields.io/travis/jbucaran/clor.svg)](https://travis-ci.org/jbucaran/clor)
[![](https://img.shields.io/npm/v/clor.svg)](https://www.npmjs.org/package/clor)

Clor is a Node.js library for colorizing text using ANSI escape sequences.

* **Safe**: Clor does not extend the [String.prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/prototype).
* **Simple**: Clor has no dependencies nor is it broken into a dozen tiny modules that only work well together.
* **It Just Works™**: Out of the box, Clor detects if your terminal supports colors and knows how to fail gracefully.
* **It Just Works™**: Out of the box, Clor detects if your terminal supports colors and knows how to fail with grace.

## Installation
<pre>
npm i -S <a href="https://www.npmjs.com/package/clor">clor</a>
npm i <a href="https://www.npmjs.com/package/clor">clor</a>
</pre>

## Usage

```jsx
const clor = require("clor")
```

## Examples

Compose a color expression.

```jsx
console.log(
`${clor.red.bold("What's").newLine.inverse("up?")}`
`${clor.red.bold("What's").newLine.inverse("up?")}`
)
```

Concatenate expressions.

```jsx
console.log(
clor.red.bold("What's") + "\n" + clor.red.inverse("up?")
clor.red.bold("What's") + "\n" + clor.red.inverse("up?")
)
```

Nest expressions to reuse styles.

```jsx
console.log(`${clor.bold(clor.red("Bold & Red"))}`)
```

Create your own styles.

```jsx
const Styles = {
em: s => clor.bgBlack.yellow(s)
em(s) {
return clor.bgBlack.yellow(s)
}
}

console.log(Styles.em("Alert!"))
```

And wrap them in a `clor()` or `clor.<style>()` function call to continue the sequence.
And wrap them in a `clor()` or <code>clor.<em>\<style\></em>()</code> function call to continue the sequence.

```jsx
console.log(`${clor(Styles.em("Known trope")).bold(" or meme")}`)
```

Optionally, require the [tagged literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) `c`.

```js
const c = require("clor/c")
```

Colorize text using pseudo HTML.

```jsx
console.log(c`<inverse>Hey Ho, <bold>Lets Go!</bold></inverse>`)
```

Embed complex expressions.

```jsx
console.log(c`Hello ${name ? c`<italic>${name}</italic>` : "everyone"}.`)
```

## Styles
| Colors | Background Colors | Modifiers | Other |
|---------|-------------------|---------------|---------|
Expand All @@ -83,3 +72,6 @@ console.log(c`Hello ${name ? c`<italic>${name}</italic>` : "everyone"}.`)
| white | bgWhite | | |
| gray | | | |

## License

Clor is MIT licensed. See [LICENSE](LICENSE.md).
70 changes: 34 additions & 36 deletions ansi.js
@@ -1,41 +1,39 @@
const support =
process.env.FORCE_COLOR ||
process.platform === "win32" ||
(process.stdout.isTTY &&
process.env.TERM &&
process.env.TERM !== "dumb")

const none = ansi => (support ? ansi : ["", ""])

module.exports = {
reset: none(["\x1b[0m"]),
module.exports = (strip => ({
reset: strip(["\x1b[0m"]),
newLine: ["\n", ""],
tab: ["\t", ""],

black: none(["\x1b[30m", "\x1b[39m"]),
red: none(["\x1b[31m", "\x1b[39m"]),
green: none(["\x1b[32m", "\x1b[39m"]),
yellow: none(["\x1b[33m", "\x1b[39m"]),
blue: none(["\x1b[34m", "\x1b[39m"]),
magenta: none(["\x1b[35m", "\x1b[39m"]),
cyan: none(["\x1b[36m", "\x1b[39m"]),
white: none(["\x1b[37m", "\x1b[39m"]),
gray: none(["\x1B[90m", "\x1b[39m"]),
black: strip(["\x1b[30m", "\x1b[39m"]),
red: strip(["\x1b[31m", "\x1b[39m"]),
green: strip(["\x1b[32m", "\x1b[39m"]),
yellow: strip(["\x1b[33m", "\x1b[39m"]),
blue: strip(["\x1b[34m", "\x1b[39m"]),
magenta: strip(["\x1b[35m", "\x1b[39m"]),
cyan: strip(["\x1b[36m", "\x1b[39m"]),
white: strip(["\x1b[37m", "\x1b[39m"]),
gray: strip(["\x1B[90m", "\x1b[39m"]),

bgBlack: none(["\x1b[40m", "\x1b[49m"]),
bgRed: none(["\x1b[41m", "\x1b[49m"]),
bgGreen: none(["\x1b[42m", "\x1b[49m"]),
bgYellow: none(["\x1b[43m", "\x1b[49m"]),
bgBlue: none(["\x1b[44m", "\x1b[49m"]),
bgMagenta: none(["\x1b[45m", "\x1b[49m"]),
bgCyan: none(["\x1b[46m", "\x1b[49m"]),
bgWhite: none(["\x1b[47m", "\x1b[49m"]),
bgBlack: strip(["\x1b[40m", "\x1b[49m"]),
bgRed: strip(["\x1b[41m", "\x1b[49m"]),
bgGreen: strip(["\x1b[42m", "\x1b[49m"]),
bgYellow: strip(["\x1b[43m", "\x1b[49m"]),
bgBlue: strip(["\x1b[44m", "\x1b[49m"]),
bgMagenta: strip(["\x1b[45m", "\x1b[49m"]),
bgCyan: strip(["\x1b[46m", "\x1b[49m"]),
bgWhite: strip(["\x1b[47m", "\x1b[49m"]),

dim: none(["\x1b[2m", "\x1b[22m"]),
bold: none(["\x1b[1m", "\x1b[22m"]),
hidden: none(["\x1b[8m", "\x1b[28m"]),
italic: none(["\x1b[3m", "\x1b[23m"]),
underline: none(["\x1b[4m", "\x1b[24m"]),
inverse: none(["\x1b[7m", "\x1b[27m"]),
strikethrough: none(["\x1b[9m", "\x1b[29m"])
}
dim: strip(["\x1b[2m", "\x1b[22m"]),
bold: strip(["\x1b[1m", "\x1b[22m"]),
hidden: strip(["\x1b[8m", "\x1b[28m"]),
italic: strip(["\x1b[3m", "\x1b[23m"]),
underline: strip(["\x1b[4m", "\x1b[24m"]),
inverse: strip(["\x1b[7m", "\x1b[27m"]),
strikethrough: strip(["\x1b[9m", "\x1b[29m"])
}))(
ansi =>
process.env.FORCE_COLOR ||
process.platform === "win32" ||
(process.stdout.isTTY && process.env.TERM && process.env.TERM !== "dumb")
? ansi
: ["", ""]
)
123 changes: 0 additions & 123 deletions c.js

This file was deleted.

4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -5,11 +5,11 @@ module.exports = (function Clor(old, close) {

clor.toString = s => old + (s || "") + (close || ansi.reset[0])

Object.keys(ansi).forEach(name =>
Object.keys(ansi).forEach(name => {
Object.defineProperty(clor, name, {
get: () => Clor(old + ansi[name][0], ansi[name][1])
})
)
})

return clor
})("")
17 changes: 5 additions & 12 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "clor",
"version": "5.2.0",
"description": "Functional terminal styles",
"version": "6.0.0",
"description": "Node.js library for colorizing text using ANSI escape sequences.",
"main": "index.js",
"scripts": {
"test": "node test.js",
Expand All @@ -11,19 +11,12 @@
"type": "git",
"url": "https://github.com/jbucaran/clor"
},
"keywords": [
"color",
"terminal",
"cli",
"chalk",
"ansi",
"ansi"
],
"files": ["index.js", "ansi.js"],
"keywords": ["color", "terminal", "cli", "ansi"],
"author": "Jorge Bucaran",
"license": "MIT",
"bugs": {
"url": "https://github.com/jbucaran/clor/issues"
},
"homepage": "https://github.com/jbucaran/clor",
"dependencies": {}
"homepage": "https://github.com/jbucaran/clor"
}

0 comments on commit 6a3d87f

Please sign in to comment.