@prm-programmer/safe-chalk 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.
Files changed (2) hide show
  1. package/index.js +33 -0
  2. package/package.json +10 -0
package/index.js ADDED
@@ -0,0 +1,33 @@
1
+ const ANSI_CODES = {
2
+ reset: '\x1b[0m',
3
+ bold: '\x1b[1m',
4
+ underline: '\x1b[4m',
5
+ red: '\x1b[31m',
6
+ green: '\x1b[32m',
7
+ yellow: '\x1b[33m',
8
+ blue: '\x1b[34m',
9
+ magenta: '\x1b[35m',
10
+ cyan: '\x1b[36m',
11
+ bgRed: '\x1b[41m',
12
+ bgGreen: '\x1b[42m',
13
+ bgYellow: '\x1b[43m',
14
+ bgBlue: '\x1b[44m'
15
+ };
16
+
17
+ function createChalk(activeCodes = []) {
18
+ const builder = (text) => {
19
+ return `${activeCodes.join('')}${text}${ANSI_CODES.reset}`;
20
+ };
21
+
22
+ return new Proxy(builder, {
23
+ get(target, prop) {
24
+ if (prop in ANSI_CODES) {
25
+ return createChalk([...activeCodes, ANSI_CODES[prop]]);
26
+ }
27
+ return target[prop];
28
+ }
29
+ });
30
+ }
31
+
32
+ const myChalk = createChalk();
33
+ export default myChalk;
package/package.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@prm-programmer/safe-chalk",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "description": "A secure and lightweight alternative to chalk using pure ANSI codes",
7
+ "keywords": ["chalk", "ansi", "color", "terminal", "safe"],
8
+ "author": "prm-programmer",
9
+ "license": "MIT"
10
+ }