cstyler 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +45 -0
- package/package.json +18 -0
- package/readme.txt +12 -0
package/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class cstyle {
|
|
2
|
+
constructor() {
|
|
3
|
+
return this.createStyler([]);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
createStyler(styles) {
|
|
7
|
+
const styler = (text) => {
|
|
8
|
+
return styles.reduce((str, styleCode) => styleCode.open + str + styleCode.close, text);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const addStyle = (open, close) => this.createStyler([...styles, { open, close }]);
|
|
12
|
+
|
|
13
|
+
const styleMap = {
|
|
14
|
+
// Text styles
|
|
15
|
+
bold: ['\x1b[1m', '\x1b[22m'],
|
|
16
|
+
italic: ['\x1b[3m', '\x1b[23m'],
|
|
17
|
+
underline: ['\x1b[4m', '\x1b[24m'],
|
|
18
|
+
dark: ['\x1b[2m', '\x1b[22m'],
|
|
19
|
+
// Foreground colors
|
|
20
|
+
red: ['\x1b[31m', '\x1b[39m'],
|
|
21
|
+
green: ['\x1b[32m', '\x1b[39m'],
|
|
22
|
+
yellow: ['\x1b[33m', '\x1b[39m'],
|
|
23
|
+
blue: ['\x1b[34m', '\x1b[39m'],
|
|
24
|
+
purpal: ['\x1b[35m', '\x1b[39m'],
|
|
25
|
+
gray: ['\x1b[30m', '\x1b[39m'],
|
|
26
|
+
// Background colors
|
|
27
|
+
bgRed: ['\x1b[41m', '\x1b[49m'],
|
|
28
|
+
bgGreen: ['\x1b[42m', '\x1b[49m'],
|
|
29
|
+
bgYellow: ['\x1b[43m', '\x1b[49m'],
|
|
30
|
+
bgBlue: ['\x1b[44m', '\x1b[49m'],
|
|
31
|
+
bgPurpal: ['\x1b[45m', '\x1b[49m'],
|
|
32
|
+
bgGray: ['\x1b[40m', '\x1b[49m']
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
for (const [name, [open, close]] of Object.entries(styleMap)) {
|
|
36
|
+
Object.defineProperty(styler, name, {
|
|
37
|
+
get: () => addStyle(open, close)
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return styler;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = new cstyle();
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cstyler",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Chainable terminal text styling tool (bold, colors, etc.)",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"console",
|
|
8
|
+
"style",
|
|
9
|
+
"color",
|
|
10
|
+
"chainable",
|
|
11
|
+
"bold",
|
|
12
|
+
"style",
|
|
13
|
+
"styler"
|
|
14
|
+
],
|
|
15
|
+
"author": "MD Nasiruddin Ahmed",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"type": "commonjs"
|
|
18
|
+
}
|
package/readme.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Hello World!
|
|
2
|
+
|
|
3
|
+
This cstyle kit is fully free to use. You can colorize your console log useing this kit. You can use dot notation to add more style like 'bold, underline, italic, dark(for color), bg for background'. You have all red, green, blue, yellow, cyan, purpal, colors on both text color and background color.
|
|
4
|
+
|
|
5
|
+
You can not use two color names e.g. 'red.blue'.
|
|
6
|
+
How to use:
|
|
7
|
+
|
|
8
|
+
const cstyle = require("cstyle");
|
|
9
|
+
console.log(cstyle.bold.underline.italic.dark.yellow("Here goes your text"));
|
|
10
|
+
|
|
11
|
+
Feel free to use.
|
|
12
|
+
Regards from kormoi.com
|