@reliverse/relico 1.2.0 → 1.3.1

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.
@@ -0,0 +1,55 @@
1
+ // Example configuration for relico benchmarks
2
+ // Copy this file to config.ts and modify as needed
3
+
4
+ import type { BenchmarkConfig } from "./config";
5
+
6
+ // Custom configuration example
7
+ export const customConfig: BenchmarkConfig = {
8
+ sourceDirs: {
9
+ src: "../../src", // Source TypeScript files
10
+ distNpmBin: "../../dist-npm/bin", // Binary distribution files
11
+ },
12
+
13
+ // Choose which directories to test
14
+ enabledDirs: ["src", "distNpmBin"], // Only test src and dist-npm/bin
15
+
16
+ performance: {
17
+ iterations: 50_000, // Reduce iterations for faster testing
18
+ warmupRuns: 500, // Reduce warmup runs
19
+ },
20
+
21
+ bundleAnalysis: {
22
+ includeSourceMaps: false, // Skip source map analysis
23
+ analyzeDependencies: true, // Include dependency analysis
24
+ },
25
+ };
26
+
27
+ // Example: Test only source files
28
+ export const sourceOnlyConfig: BenchmarkConfig = {
29
+ ...customConfig,
30
+ enabledDirs: ["src"],
31
+ };
32
+
33
+ // Example: Test only built files
34
+ export const builtOnlyConfig: BenchmarkConfig = {
35
+ ...customConfig,
36
+ enabledDirs: ["distNpmBin"],
37
+ };
38
+
39
+ // Example: High-performance testing
40
+ export const highPerfConfig: BenchmarkConfig = {
41
+ ...customConfig,
42
+ performance: {
43
+ iterations: 1_000_000, // 1M iterations for accurate results
44
+ warmupRuns: 10_000, // 10K warmup runs
45
+ },
46
+ };
47
+
48
+ // Example: Quick testing
49
+ export const quickConfig: BenchmarkConfig = {
50
+ ...customConfig,
51
+ performance: {
52
+ iterations: 10_000, // 10K iterations for quick results
53
+ warmupRuns: 100, // Minimal warmup
54
+ },
55
+ };
@@ -0,0 +1,93 @@
1
+ // Benchmark configuration for relico
2
+ export interface BenchmarkConfig {
3
+ // Source directories to test
4
+ sourceDirs: {
5
+ src?: string;
6
+ distNpmBin: string;
7
+ };
8
+
9
+ // Which directories to include in testing
10
+ enabledDirs: ("src" | "distNpmBin")[];
11
+
12
+ // Performance test settings
13
+ performance: {
14
+ iterations: number;
15
+ warmupRuns: number;
16
+ };
17
+
18
+ // Bundle analysis settings
19
+ bundleAnalysis: {
20
+ includeSourceMaps: boolean;
21
+ analyzeDependencies: boolean;
22
+ };
23
+ }
24
+
25
+ // Default configuration
26
+ export const defaultConfig: BenchmarkConfig = {
27
+ sourceDirs: {
28
+ src: "../../src",
29
+ distNpmBin: "../../dist-npm/bin", // Binary distribution (where .js and .d.ts files are)
30
+ },
31
+
32
+ // Test source directory by default since we don't have a built version
33
+ enabledDirs: ["src"],
34
+
35
+ performance: {
36
+ iterations: 100_000,
37
+ warmupRuns: 1000,
38
+ },
39
+
40
+ bundleAnalysis: {
41
+ includeSourceMaps: false,
42
+ analyzeDependencies: true,
43
+ },
44
+ };
45
+
46
+ // Helper function to get import path for a specific directory
47
+ export function getImportPath(dir: keyof BenchmarkConfig["sourceDirs"], module = "mod"): string {
48
+ const config = defaultConfig;
49
+ const basePath = config.sourceDirs[dir];
50
+
51
+ switch (dir) {
52
+ case "src":
53
+ return `${basePath}/${module}.ts`;
54
+ case "distNpmBin":
55
+ return `${basePath}/${module}.js`;
56
+ default:
57
+ return `${basePath}/${module}.ts`;
58
+ }
59
+ }
60
+
61
+ // Helper function to get file paths for analysis (both .js and .d.ts files)
62
+ export function getFilePaths(
63
+ dir: keyof BenchmarkConfig["sourceDirs"],
64
+ module = "mod",
65
+ ): { js?: string; dts?: string } {
66
+ const config = defaultConfig;
67
+ const basePath = config.sourceDirs[dir];
68
+
69
+ switch (dir) {
70
+ case "src":
71
+ return { js: `${basePath}/${module}.ts` };
72
+ case "distNpmBin":
73
+ return {
74
+ js: `${basePath}/${module}.js`,
75
+ dts: `${basePath}/${module}.d.ts`,
76
+ };
77
+ default:
78
+ return { js: `${basePath}/${module}.ts` };
79
+ }
80
+ }
81
+
82
+ // Helper to check if directory is enabled
83
+ export function isDirEnabled(dir: keyof BenchmarkConfig["sourceDirs"]): boolean {
84
+ return defaultConfig.enabledDirs.includes(dir);
85
+ }
86
+
87
+ // Helper to get all enabled directories
88
+ export function getEnabledDirs(): (keyof BenchmarkConfig["sourceDirs"])[] {
89
+ return defaultConfig.enabledDirs;
90
+ }
91
+
92
+ // Export the config for easy access
93
+ export const config = defaultConfig;
@@ -0,0 +1,174 @@
1
+ // Performance benchmarks for relico optimizations
2
+
3
+ import { dirname, resolve } from "path";
4
+ import { performance } from "perf_hooks";
5
+ import { fileURLToPath } from "url";
6
+ import { config, getEnabledDirs, getImportPath } from "./config";
7
+
8
+ // Constants
9
+ const MILLISECONDS_PER_SECOND = 1000;
10
+ const COLOR_LEVEL_BASIC = 1;
11
+ const COLOR_LEVEL_TRUECOLOR = 3;
12
+ const MULTILINE_TEST_SIZE = 50;
13
+
14
+ // Get the directory where this benchmark file is located
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = dirname(__filename);
17
+
18
+ // Dynamic imports for different source directories
19
+ async function importFromDir(dir: string) {
20
+ try {
21
+ const resolvedPath = resolve(__dirname, dir);
22
+ const module = await import(resolvedPath);
23
+ return module;
24
+ } catch (error) {
25
+ const errorMessage = error instanceof Error ? error.message : String(error);
26
+ console.warn(`⚠️ Could not import from ${dir}:`, errorMessage);
27
+ return null;
28
+ }
29
+ }
30
+
31
+ interface ModuleExports {
32
+ // biome-ignore lint/suspicious/noExplicitAny: <>
33
+ re: any;
34
+ // biome-ignore lint/suspicious/noExplicitAny: <>
35
+ chain: any;
36
+ setColorLevel: (level: number) => void;
37
+ }
38
+
39
+ // Run benchmarks for a specific module
40
+ function runBenchmarks(module: ModuleExports) {
41
+ const { re, chain, setColorLevel } = module;
42
+ const { iterations, warmupRuns } = config.performance;
43
+
44
+ function benchmark(name: string, fn: () => void, iterCount = iterations) {
45
+ // Warmup runs
46
+ for (let i = 0; i < warmupRuns; i++) {
47
+ fn();
48
+ }
49
+
50
+ const start = performance.now();
51
+ for (let i = 0; i < iterCount; i++) {
52
+ fn();
53
+ }
54
+ const end = performance.now();
55
+ const time = end - start;
56
+ const opsPerSec = Math.round((iterCount * MILLISECONDS_PER_SECOND) / time);
57
+ console.log(` ${name}: ${time.toFixed(2)}ms (${opsPerSec.toLocaleString()} ops/sec)`);
58
+ }
59
+
60
+ // Test basic color operations
61
+ benchmark("Basic color access", () => {
62
+ re.red("test");
63
+ });
64
+
65
+ benchmark("Chained colors", () => {
66
+ re.bold.red.underline("test");
67
+ });
68
+
69
+ benchmark("Extended named colors", () => {
70
+ re.orange("test");
71
+ });
72
+
73
+ benchmark("Bright color variants", () => {
74
+ re.redBright("test");
75
+ });
76
+
77
+ benchmark("Chain function", () => {
78
+ chain(re.bold, re.red, re.underline)("test");
79
+ });
80
+
81
+ benchmark("Background colors", () => {
82
+ re.bgRed.white("test");
83
+ });
84
+
85
+ benchmark("Bright background colors", () => {
86
+ re.bgRedBright.white("test");
87
+ });
88
+
89
+ benchmark("Complex style combinations", () => {
90
+ re.bold.italic.underline.red("test");
91
+ });
92
+
93
+ benchmark("Style methods", () => {
94
+ re.dim.strikethrough("test");
95
+ });
96
+
97
+ benchmark("Color level changes", () => {
98
+ setColorLevel(COLOR_LEVEL_BASIC);
99
+ re.red("test");
100
+ setColorLevel(COLOR_LEVEL_TRUECOLOR); // Reset to truecolor
101
+ });
102
+
103
+ benchmark("Multiline text (small)", () => {
104
+ re.red("line1\nline2\nline3");
105
+ });
106
+
107
+ benchmark("Multiline text (large)", () => {
108
+ const largeText = new Array(MULTILINE_TEST_SIZE).fill("text").join("\n");
109
+ re.red(largeText);
110
+ });
111
+
112
+ benchmark("Mixed background and foreground", () => {
113
+ re.bgBlue.yellow.bold("test");
114
+ });
115
+
116
+ benchmark("All basic colors iteration", () => {
117
+ const colors = ["red", "green", "blue", "yellow", "magenta", "cyan", "white", "black"];
118
+ for (const color of colors) {
119
+ re[color]("test");
120
+ }
121
+ });
122
+
123
+ benchmark("Extended colors iteration", () => {
124
+ const extendedColors = [
125
+ "orange",
126
+ "pink",
127
+ "purple",
128
+ "teal",
129
+ "lime",
130
+ "brown",
131
+ "navy",
132
+ "maroon",
133
+ "olive",
134
+ "silver",
135
+ ];
136
+ for (const color of extendedColors) {
137
+ re[color]("test");
138
+ }
139
+ });
140
+
141
+ console.log("\n 📊 Bundle Size Test:");
142
+ console.log(` Core exports imported: ${Object.keys({ re, chain, setColorLevel }).length}`);
143
+ }
144
+
145
+ // Test all enabled directories
146
+ async function runBenchmarksForAllDirs() {
147
+ const enabledDirs = getEnabledDirs();
148
+
149
+ for (const dir of enabledDirs) {
150
+ const importPath = getImportPath(dir);
151
+ console.log(`\n🔍 Testing ${dir.toUpperCase()} directory: ${importPath}`);
152
+ console.log("=".repeat(60));
153
+
154
+ const module = await importFromDir(importPath);
155
+ if (!module) {
156
+ continue;
157
+ }
158
+
159
+ // Run benchmarks for this directory
160
+ runBenchmarks(module);
161
+ }
162
+ }
163
+
164
+ // Main execution
165
+ console.log("🚀 Relico Performance Benchmarks");
166
+ console.log("=".repeat(50));
167
+
168
+ runBenchmarksForAllDirs()
169
+ .then(() => {
170
+ console.log("\n✅ All benchmarks completed!");
171
+ })
172
+ .catch((error) => {
173
+ console.error("❌ Benchmark error:", error);
174
+ });
@@ -0,0 +1,62 @@
1
+ import { chain, re, setColorLevel } from "~/mod";
2
+
3
+ const COLOR_LEVEL_TRUECOLOR = 3;
4
+
5
+ function main() {
6
+ setColorLevel(COLOR_LEVEL_TRUECOLOR);
7
+
8
+ console.log("--- Basic Color Examples ---");
9
+ console.log(re.bold.red.underline("Hello"));
10
+ console.log(chain(re.bold, re.red)("world"));
11
+
12
+ // Additional color tests
13
+ console.log("\n--- Named Color Examples ---");
14
+ console.log(re.blue("Blue text"));
15
+ console.log(re.green.bold("Bold green text"));
16
+ console.log(re.yellow.underline("Yellow underlined text"));
17
+ console.log(re.magenta.italic("Magenta italic text"));
18
+ console.log(re.bgRed.white("White text on red background"));
19
+ console.log(re.bgBlue.yellow("Yellow text on blue background"));
20
+
21
+ console.log("\n--- Extended Named Colors ---");
22
+ console.log(re.orange.bold("Orange text"));
23
+ console.log(re.pink.underline("Pink text"));
24
+ console.log(re.purple.italic("Purple text"));
25
+ console.log(re.teal.bold("Teal text"));
26
+ console.log(re.lime("Lime text"));
27
+ console.log(re.brown("Brown text"));
28
+ console.log(re.navy("Navy text"));
29
+ console.log(re.maroon("Maroon text"));
30
+ console.log(re.olive("Olive text"));
31
+ console.log(re.silver("Silver text"));
32
+
33
+ console.log("\n--- Bright Color Variants ---");
34
+ console.log(re.redBright("Bright red text"));
35
+ console.log(re.greenBright.bold("Bold bright green text"));
36
+ console.log(re.blueBright.underline("Underlined bright blue text"));
37
+ console.log(re.yellowBright.italic("Italic bright yellow text"));
38
+
39
+ console.log("\n--- Background Colors ---");
40
+ console.log(re.bgOrange.white("White text on orange background"));
41
+ console.log(re.bgPink.black("Black text on pink background"));
42
+ console.log(re.bgPurple.white("White text on purple background"));
43
+ console.log(re.bgTeal.white("White text on teal background"));
44
+
45
+ console.log("\n--- Bright Background Colors ---");
46
+ console.log(re.bgRedBright.white("White text on bright red background"));
47
+ console.log(re.bgGreenBright.black("Black text on bright green background"));
48
+ console.log(re.bgBlueBright.white("White text on bright blue background"));
49
+
50
+ console.log("\n--- Style Combinations ---");
51
+ console.log(re.bold.italic.underline.red("Bold italic underlined red text"));
52
+ console.log(re.dim.strikethrough.cyan("Dim strikethrough cyan text"));
53
+ console.log(re.inverse.magenta("Inverse magenta text"));
54
+ console.log(re.hidden("Hidden text (you might not see this)"));
55
+
56
+ console.log("\n--- Chaining Examples ---");
57
+ console.log(chain(re.bold, re.red, re.underline)("Chained formatting"));
58
+ console.log(chain(re.italic, re.blue, re.bgYellow)("Blue italic on yellow background"));
59
+ console.log(chain(re.dim, re.green)("Dim green text"));
60
+ }
61
+
62
+ main();
package/knip.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://unpkg.com/knip@5/schema.json",
3
+ "project": ["**/*.{ts,js}"],
4
+ "entry": [".*/**/*.ts", "*.{config,cfg}.{ts,js}", "src/mod.ts"],
5
+ "ignore": [
6
+ "node_modules",
7
+ "dist-jsr",
8
+ "dist-npm",
9
+ "dist-libs",
10
+ "tests/mod.test.ts"
11
+ ],
12
+ "ignoreBinaries": ["dler"]
13
+ }
package/package.json CHANGED
@@ -1,40 +1,32 @@
1
1
  {
2
- "dependencies": {
3
- "@reliverse/runtime": "^1.0.3",
4
- "c12": "^3.1.0",
5
- "pathe": "^2.0.3"
6
- },
7
- "description": "@reliverse/relico is a themeable, chainable, typed, truecolor-powered, modern terminal styling toolkit. Designed to make your CLI output colorful, accessible, and human-friendly. It gives you a flexible way to apply colors and styles — with reliability and a smart developer experience baked in. Built for humans, not just terminals.",
8
- "homepage": "https://docs.reliverse.org",
9
- "license": "MIT",
10
2
  "name": "@reliverse/relico",
11
- "type": "module",
12
- "version": "1.2.0",
13
3
  "author": "reliverse",
14
- "bugs": {
15
- "email": "blefnk@gmail.com",
16
- "url": "https://github.com/reliverse/relico/issues"
17
- },
18
- "keywords": [
19
- "reliverse"
20
- ],
21
- "repository": {
22
- "type": "git",
23
- "url": "git+https://github.com/reliverse/relico.git"
24
- },
25
- "devDependencies": {},
4
+ "version": "1.3.1",
5
+ "type": "module",
6
+ "description": "@reliverse/relico is a themeable, chainable, typed, truecolor-powered, modern terminal styling toolkit. Designed to make your CLI output colorful, accessible, and human-friendly. It gives you a flexible way to apply colors and styles — with reliability and a smart developer experience baked in. Built for humans, not just terminals.",
26
7
  "exports": {
27
- ".": "./bin/mod.js"
8
+ ".": "./src/mod.ts"
28
9
  },
29
- "files": [
30
- "bin",
31
- "package.json",
32
- "README.md",
33
- "LICENSE"
34
- ],
35
- "main": "./bin/mod.js",
36
- "module": "./bin/mod.js",
37
10
  "publishConfig": {
38
11
  "access": "public"
12
+ },
13
+ "scripts": {
14
+ "pub": "dler pub",
15
+ "dev": "bun examples/core.ts",
16
+ "latest": "bun update --latest && bun check",
17
+ "check": "tsc --noEmit && biome check --fix --unsafe",
18
+ "bench": "bun examples/benchmarks/performance.ts",
19
+ "size": "bun examples/benchmarks/bundle-size.ts",
20
+ "perf": "bun bench && bun size"
21
+ },
22
+ "devDependencies": {
23
+ "@biomejs/biome": "2.2.0",
24
+ "@reliverse/dler": "^1.7.92",
25
+ "@reliverse/rse-cfg": "^1.7.12",
26
+ "@total-typescript/ts-reset": "^0.6.1",
27
+ "@types/bun": "^1.2.20",
28
+ "@types/node": "^24.3.0",
29
+ "typescript": "^5.9.2",
30
+ "ultracite": "^5.1.5"
39
31
  }
40
- }
32
+ }
package/reset.d.ts ADDED
@@ -0,0 +1 @@
1
+ import "@total-typescript/ts-reset";