Skip to content

Commit 8da9119

Browse files
feat: fill scaffolded packages #194
PR URL: #194 Reviewed-by: OpenINF-bot <openinfbot@open.inf.is> --------- Signed-off-by: Derek Lewis <dereknongeneric@open.inf.is>
1 parent d339098 commit 8da9119

File tree

23 files changed

+992
-1
lines changed

23 files changed

+992
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"private": true,
44
"version": "0.0.0-development",
55
"description": "Package-based monorepo for @openinf/util-text and friends",
6-
"workspaces": ["packages/*"],
6+
"workspaces": [
7+
"packages/*"
8+
],
79
"packageManager": "pnpm@9.1.2",
810
"license": "MIT OR Apache-2.0",
911
"author": "The OpenINF Authors",

packages/colorette/.gitkeep

Whitespace-only changes.

packages/colorette/LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright © Jorge Bucaran <<https://jorgebucaran.com>>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

packages/colorette/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# 🌈Colorette
2+
3+
> Easily set your terminal text color & styles.
4+
5+
- No dependecies
6+
- Automatic color support detection
7+
- Up to [2x faster](#benchmarks) than alternatives
8+
- TypeScript support
9+
- [`NO_COLOR`](https://no-color.org) friendly
10+
- Node >= `10`
11+
12+
> [**Upgrading from Colorette `1.x`?**](https://github.com/jorgebucaran/colorette/issues/70)
13+
14+
## Quickstart
15+
16+
```js
17+
import { blue, bold, underline } from "colorette"
18+
19+
console.log(
20+
blue("I'm blue"),
21+
bold(blue("da ba dee")),
22+
underline(bold(blue("da ba daa")))
23+
)
24+
```
25+
26+
Here's an example using [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
27+
28+
```js
29+
console.log(`
30+
There's a ${underline(blue("house"))},
31+
With a ${bold(blue("window"))},
32+
And a ${blue("corvette")}
33+
And everything is blue
34+
`)
35+
```
36+
37+
You can also nest styles without breaking existing color sequences.
38+
39+
```js
40+
console.log(bold(`I'm ${blue(`da ba ${underline("dee")} da ba`)} daa`))
41+
```
42+
43+
Need to override terminal color detection? You can do that too.
44+
45+
```js
46+
import { createColors } from "colorette"
47+
48+
const { blue } = createColors({ useColor: false })
49+
50+
console.log(blue("Blue? Nope, nah"))
51+
```
52+
53+
## Installation
54+
55+
```console
56+
npm install colorette
57+
```
58+
59+
## API
60+
61+
### \<color\>()
62+
63+
> See all [supported colors](#supported-colors).
64+
65+
```js
66+
import { blue } from "colorette"
67+
68+
blue("I'm blue") //=> \x1b[34mI'm blue\x1b[39m
69+
```
70+
71+
### createColors()
72+
73+
Override terminal color detection via `createColors({ useColor })`.
74+
75+
```js
76+
import { createColors } from "colorette"
77+
78+
const { blue } = createColors({ useColor: false })
79+
```
80+
81+
### isColorSupported
82+
83+
`true` if your terminal supports color, `false` otherwise. Used internally, but exposed for convenience.
84+
85+
## Environment
86+
87+
You can override color detection from the CLI by setting the `--no-color` or `--color` flags.
88+
89+
```console
90+
$ ./example.js --no-color | ./consumer.js
91+
```
92+
93+
Or if you can't use CLI flags, by setting the `NO_COLOR=` or `FORCE_COLOR=` environment variables.
94+
95+
```console
96+
$ NO_COLOR= ./example.js | ./consumer.js
97+
```
98+
99+
## Supported colors
100+
101+
| Colors | Background Colors | Bright Colors | Bright Background Colors | Modifiers |
102+
| ------- | ----------------- | ------------- | ------------------------ | ----------------- |
103+
| black | bgBlack | blackBright | bgBlackBright | dim |
104+
| red | bgRed | redBright | bgRedBright | **bold** |
105+
| green | bgGreen | greenBright | bgGreenBright | hidden |
106+
| yellow | bgYellow | yellowBright | bgYellowBright | _italic_ |
107+
| blue | bgBlue | blueBright | bgBlueBright | <u>underline</u> |
108+
| magenta | bgMagenta | magentaBright | bgMagentaBright | ~~strikethrough~~ |
109+
| cyan | bgCyan | cyanBright | bgCyanBright | reset |
110+
| white | bgWhite | whiteBright | bgWhiteBright | |
111+
| gray | | | | |
112+
113+
## [Benchmarks](https://github.com/jorgebucaran/colorette/actions/workflows/bench.yml)
114+
115+
```console
116+
npm --prefix bench start
117+
```
118+
119+
```diff
120+
chalk 1,786,703 ops/sec
121+
kleur 1,618,960 ops/sec
122+
colors 646,823 ops/sec
123+
ansi-colors 786,149 ops/sec
124+
picocolors 2,871,758 ops/sec
125+
+ colorette 3,002,751 ops/sec
126+
```
127+
128+
## Acknowledgments
129+
130+
Colorette started out in 2015 by [@jorgebucaran](https://github.com/jorgebucaran) as a lightweight alternative to [Chalk](https://github.com/chalk/chalk) and was introduced originally as [Clor](https://github.com/jorgebucaran/colorette/commit/b01b5b9961ceb7df878583a3002e836fae9e37ce). Our terminal color detection logic borrows heavily from [@sindresorhus](https://github.com/sindresorhus) and [@Qix-](https://github.com/Qix-) work on Chalk. The idea of slicing strings to clear bleeding sequences was adapted from a similar technique used by [@alexeyraspopov](https://github.com/alexeyraspopov) in [picocolors](https://github.com/alexeyraspopov/picocolors). Thank you to all our contributors! <3
131+
132+
## License
133+
134+
[MIT](LICENSE.md)

packages/colorette/index.cjs

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, '__esModule', { value: true });
4+
5+
var tty = require('tty');
6+
7+
function _interopNamespace(e) {
8+
if (e && e.__esModule) return e;
9+
var n = Object.create(null);
10+
if (e) {
11+
Object.keys(e).forEach(function (k) {
12+
if (k !== 'default') {
13+
var d = Object.getOwnPropertyDescriptor(e, k);
14+
Object.defineProperty(n, k, d.get ? d : {
15+
enumerable: true,
16+
get: function () { return e[k]; }
17+
});
18+
}
19+
});
20+
}
21+
n["default"] = e;
22+
return Object.freeze(n);
23+
}
24+
25+
var tty__namespace = /*#__PURE__*/_interopNamespace(tty);
26+
27+
const {
28+
env = {},
29+
argv = [],
30+
platform = "",
31+
} = typeof process === "undefined" ? {} : process;
32+
33+
const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
34+
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
35+
const isWindows = platform === "win32";
36+
const isDumbTerminal = env.TERM === "dumb";
37+
38+
const isCompatibleTerminal =
39+
tty__namespace && tty__namespace.isatty && tty__namespace.isatty(1) && env.TERM && !isDumbTerminal;
40+
41+
const isCI =
42+
"CI" in env &&
43+
("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);
44+
45+
const isColorSupported =
46+
!isDisabled &&
47+
(isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI);
48+
49+
const replaceClose = (
50+
index,
51+
string,
52+
close,
53+
replace,
54+
head = string.substring(0, index) + replace,
55+
tail = string.substring(index + close.length),
56+
next = tail.indexOf(close)
57+
) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
58+
59+
const clearBleed = (index, string, open, close, replace) =>
60+
index < 0
61+
? open + string + close
62+
: open + replaceClose(index, string, close, replace) + close;
63+
64+
const filterEmpty =
65+
(open, close, replace = open, at = open.length + 1) =>
66+
(string) =>
67+
string || !(string === "" || string === undefined)
68+
? clearBleed(
69+
("" + string).indexOf(close, at),
70+
string,
71+
open,
72+
close,
73+
replace
74+
)
75+
: "";
76+
77+
const init = (open, close, replace) =>
78+
filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`, replace);
79+
80+
const colors = {
81+
reset: init(0, 0),
82+
bold: init(1, 22, "\x1b[22m\x1b[1m"),
83+
dim: init(2, 22, "\x1b[22m\x1b[2m"),
84+
italic: init(3, 23),
85+
underline: init(4, 24),
86+
inverse: init(7, 27),
87+
hidden: init(8, 28),
88+
strikethrough: init(9, 29),
89+
black: init(30, 39),
90+
red: init(31, 39),
91+
green: init(32, 39),
92+
yellow: init(33, 39),
93+
blue: init(34, 39),
94+
magenta: init(35, 39),
95+
cyan: init(36, 39),
96+
white: init(37, 39),
97+
gray: init(90, 39),
98+
bgBlack: init(40, 49),
99+
bgRed: init(41, 49),
100+
bgGreen: init(42, 49),
101+
bgYellow: init(43, 49),
102+
bgBlue: init(44, 49),
103+
bgMagenta: init(45, 49),
104+
bgCyan: init(46, 49),
105+
bgWhite: init(47, 49),
106+
blackBright: init(90, 39),
107+
redBright: init(91, 39),
108+
greenBright: init(92, 39),
109+
yellowBright: init(93, 39),
110+
blueBright: init(94, 39),
111+
magentaBright: init(95, 39),
112+
cyanBright: init(96, 39),
113+
whiteBright: init(97, 39),
114+
bgBlackBright: init(100, 49),
115+
bgRedBright: init(101, 49),
116+
bgGreenBright: init(102, 49),
117+
bgYellowBright: init(103, 49),
118+
bgBlueBright: init(104, 49),
119+
bgMagentaBright: init(105, 49),
120+
bgCyanBright: init(106, 49),
121+
bgWhiteBright: init(107, 49),
122+
};
123+
124+
const createColors = ({ useColor = isColorSupported } = {}) =>
125+
useColor
126+
? colors
127+
: Object.keys(colors).reduce(
128+
(colors, key) => ({ ...colors, [key]: String }),
129+
{}
130+
);
131+
132+
const {
133+
reset,
134+
bold,
135+
dim,
136+
italic,
137+
underline,
138+
inverse,
139+
hidden,
140+
strikethrough,
141+
black,
142+
red,
143+
green,
144+
yellow,
145+
blue,
146+
magenta,
147+
cyan,
148+
white,
149+
gray,
150+
bgBlack,
151+
bgRed,
152+
bgGreen,
153+
bgYellow,
154+
bgBlue,
155+
bgMagenta,
156+
bgCyan,
157+
bgWhite,
158+
blackBright,
159+
redBright,
160+
greenBright,
161+
yellowBright,
162+
blueBright,
163+
magentaBright,
164+
cyanBright,
165+
whiteBright,
166+
bgBlackBright,
167+
bgRedBright,
168+
bgGreenBright,
169+
bgYellowBright,
170+
bgBlueBright,
171+
bgMagentaBright,
172+
bgCyanBright,
173+
bgWhiteBright,
174+
} = createColors();
175+
176+
exports.bgBlack = bgBlack;
177+
exports.bgBlackBright = bgBlackBright;
178+
exports.bgBlue = bgBlue;
179+
exports.bgBlueBright = bgBlueBright;
180+
exports.bgCyan = bgCyan;
181+
exports.bgCyanBright = bgCyanBright;
182+
exports.bgGreen = bgGreen;
183+
exports.bgGreenBright = bgGreenBright;
184+
exports.bgMagenta = bgMagenta;
185+
exports.bgMagentaBright = bgMagentaBright;
186+
exports.bgRed = bgRed;
187+
exports.bgRedBright = bgRedBright;
188+
exports.bgWhite = bgWhite;
189+
exports.bgWhiteBright = bgWhiteBright;
190+
exports.bgYellow = bgYellow;
191+
exports.bgYellowBright = bgYellowBright;
192+
exports.black = black;
193+
exports.blackBright = blackBright;
194+
exports.blue = blue;
195+
exports.blueBright = blueBright;
196+
exports.bold = bold;
197+
exports.createColors = createColors;
198+
exports.cyan = cyan;
199+
exports.cyanBright = cyanBright;
200+
exports.dim = dim;
201+
exports.gray = gray;
202+
exports.green = green;
203+
exports.greenBright = greenBright;
204+
exports.hidden = hidden;
205+
exports.inverse = inverse;
206+
exports.isColorSupported = isColorSupported;
207+
exports.italic = italic;
208+
exports.magenta = magenta;
209+
exports.magentaBright = magentaBright;
210+
exports.red = red;
211+
exports.redBright = redBright;
212+
exports.reset = reset;
213+
exports.strikethrough = strikethrough;
214+
exports.underline = underline;
215+
exports.white = white;
216+
exports.whiteBright = whiteBright;
217+
exports.yellow = yellow;
218+
exports.yellowBright = yellowBright;

0 commit comments

Comments
 (0)