echo-banner 0.1.0 → 0.3.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/README.md CHANGED
@@ -39,19 +39,16 @@ console.log(result);
39
39
 
40
40
  ### `banner(options)`
41
41
 
42
- Generate a formatted banner string.
42
+ Generate a formatted banner string. See the [API docs](https://teneplaysofficial.github.io/echo-banner/functions/banner.html)
43
43
 
44
44
  ```ts
45
45
  banner(options: BannerOptions): string
46
46
  ```
47
47
 
48
- #### Options
48
+ ### `print(options)`
49
49
 
50
- | Option | Type | Default | Description |
51
- | ---------------- | ------------------------------------- | --------------------------------------- | -------------------------------------------------------------- |
52
- | `pkg` | `PackageMeta` | **required** | Package metadata (usually imported from `package.json`). |
53
- | `shebang` | `string \| false` | `false` | Adds a shebang line before the banner (useful for CLI builds). |
54
- | `style` | `'js'` | `'js'` | Banner comment style. |
55
- | `useDisplayName` | `boolean` | `false` | Use `displayName` instead of `name`. |
56
- | `prefixVersion` | `string` | `'v'` | Prefix added before the version. |
57
- | `fallback` | `{ name?: string; version?: string }` | `{ name: 'unknown', version: '0.0.0' }` | Fallback values when metadata is missing. |
50
+ Prints a stylized ASCII banner for CLI applications. See the [API docs](https://teneplaysofficial.github.io/echo-banner/functions/print.html)
51
+
52
+ ```ts
53
+ print(options: PrintOptions): Promise<void>
54
+ ```
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * echo-banner v0.1.0
2
+ * echo-banner v0.3.0
3
3
  * Generate multiline build banners and ASCII CLI titles
4
4
  *
5
5
  * (c) 2026 Sriman
@@ -8,4 +8,4 @@
8
8
  * https://teneplaysofficial.github.io/echo-banner
9
9
  * https://github.com/teneplaysofficial/echo-banner
10
10
  */
11
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`node:os`);function t({pkg:t,shebang:n=!1,style:r=`js`,useDisplayName:i=!1,prefixVersion:a=`v`,fallback:o={name:`unknown`,version:`0.0.0`}}){if(!t||typeof t!=`object`)throw TypeError(`Expected valid metadata`);let s=``,c=[],l=new Date().getFullYear(),u=/^(git\+)|(\.git)$/g;n&&(s+=n+e.EOL.repeat(2)),c.push(`${(i?t.displayName:t.name)??o.name} ${a}${t.version??o.version}`),c.push(t.description??``),c.push(``),c.push(`(c) ${l} ${(typeof t.author==`object`?t.author.name:t.author)??``}`),t.license&&c.push(`Released under the ${t.license} License`),c.push(``);let d=t.homepage;d&&c.push(d);let f=typeof t.repository==`object`?t.repository.url?.replace(u,``):t.repository?.replace(u,``);switch(f&&c.push(f),r){case`js`:s+=[`/*!`,...c.slice(0,c.findLastIndex(e=>e!==``)+1).map(e=>` * ${e}`),` */`].join(e.EOL);break}return s}exports.banner=t;
11
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:os`),l=require(`figlet`);l=s(l);let u=require(`use-colors`);u=s(u);function d({pkg:e,shebang:t=!1,style:n=`js`,useDisplayName:r=!1,prefixVersion:i=`v`,fallback:a={name:`unknown`,version:`0.0.0`}}){if(!e||typeof e!=`object`)throw TypeError(`Expected valid metadata`);let o=``,s=[],l=new Date().getFullYear(),u=/^(git\+)|(\.git)$/g;t&&(o+=t+c.EOL.repeat(2)),s.push(`${(r?e.displayName:e.name)??a.name} ${i}${e.version??a.version}`),s.push(e.description??``),s.push(``),s.push(`(c) ${l} ${(typeof e.author==`object`?e.author.name:e.author)??``}`),e.license&&s.push(`Released under the ${e.license} License`),s.push(``);let d=e.homepage;d&&s.push(d);let f=typeof e.repository==`object`?e.repository.url?.replace(u,``):e.repository?.replace(u,``);switch(f&&s.push(f),n){case`js`:o+=[`/*!`,...s.slice(0,s.findLastIndex(e=>e!==``)+1).map(e=>` * ${e}`),` */`].join(c.EOL);break}return o}async function f({pkg:e,useVersion:t=!0,useDisplayName:n=!0,prefixVersion:r=`v`,font:i=`Slant`,color:a=!0}){let o=n&&e.displayName||e.name;if(!o)return;a||u.default.config({level:0});let s=await l.default.text(o,{font:i});if(!t||!e.version){console.log(u.default.cyanBright(s));return}let d=s.split(c.EOL),f=u.default.gray`${r}${e.version}`,p=d.findLastIndex(e=>e.trim().length>0);if(p<0){console.log(u.default.cyanBright(s));return}let m=Math.max(...d.map(e=>e.trimEnd().length)),h=d[p].trimEnd(),g=m-h.length+2;d[p]=u.default.cyanBright(h)+` `.repeat(g)+f,console.log(d.join(c.EOL))}exports.banner=d,exports.print=f;
package/dist/index.d.cts CHANGED
@@ -4,6 +4,51 @@ import { PackageJson, SHEBANG } from "js-utils-kit";
4
4
  //#region lib/index.d.ts
5
5
  type Shebang = (typeof SHEBANG)[keyof typeof SHEBANG];
6
6
  type PackageMeta = Pick<PackageJson, 'name' | 'displayName' | 'version' | 'description' | 'author' | 'license' | 'homepage' | 'repository'>;
7
+ /**
8
+ * Generate a production banner comment from package metadata.
9
+ *
10
+ * @remarks
11
+ * This utility creates a formatted banner typically used at the top of bundled files (e.g., Rollup, tsdown, esbuild, webpack outputs).
12
+ *
13
+ * The banner includes:
14
+ * - Package name or display name
15
+ * - Version (with optional prefix)
16
+ * - Description
17
+ * - Copyright
18
+ * - License
19
+ * - Homepage
20
+ * - Repository URL
21
+ *
22
+ * Repository URLs are normalized by removing common prefixes such as `git+` and suffixes like `.git`.
23
+ *
24
+ * @returns A formatted banner string suitable for insertion at the top of bundled files.
25
+ *
26
+ * @throws {TypeError} Thrown if the provided `pkg` value is not a valid object.
27
+ *
28
+ * @example Basic usage
29
+ * ```ts
30
+ * import pkg from "../package.json";
31
+ *
32
+ * const text = banner({ pkg });
33
+ * console.log(text);
34
+ * ```
35
+ *
36
+ * @example With shebang for CLI tools
37
+ * ```ts
38
+ * const text = banner({
39
+ * pkg,
40
+ * shebang: "#!/usr/bin/env node"
41
+ * });
42
+ * ```
43
+ *
44
+ * @example Using display name
45
+ * ```ts
46
+ * const text = banner({
47
+ * pkg,
48
+ * useDisplayName: true
49
+ * });
50
+ * ```
51
+ */
7
52
  declare function banner({
8
53
  pkg,
9
54
  shebang,
@@ -12,15 +57,133 @@ declare function banner({
12
57
  prefixVersion,
13
58
  fallback
14
59
  }: {
15
- pkg: PackageMeta;
60
+ /** Package metadata used to construct the banner */pkg: PackageMeta;
61
+ /**
62
+ * Optional shebang line (for CLI binaries).
63
+ *
64
+ * @default false
65
+ */
16
66
  shebang?: Shebang | false;
17
- style?: 'js';
67
+ /**
68
+ * Banner comment style.
69
+ *
70
+ * Currently supports:
71
+ * - `js`
72
+ *
73
+ * @default "js"
74
+ */
75
+ style?: 'js'; /** Prefer `displayName` over `name` when available */
18
76
  useDisplayName?: boolean;
19
- prefixVersion?: string;
77
+ /**
78
+ * Prefix applied before the version.
79
+ *
80
+ * @default "v"
81
+ */
82
+ prefixVersion?: string; /** Fallback values when `name` or `version` are missing */
20
83
  fallback?: {
21
84
  name?: string;
22
85
  version?: string;
23
86
  };
24
87
  }): string;
88
+ type FontName = '1Row' | '3-D' | '3D Diagonal' | '3D-ASCII' | '3x5' | '4Max' | '5 Line Oblique' | 'Standard' | 'Ghost' | 'Big' | 'Block' | 'Bubble' | 'Digital' | 'Ivrit' | 'Mini' | 'Script' | 'Shadow' | 'Slant' | 'Small' | 'Speed' | 'Tinker-Toy';
89
+ /**
90
+ * Prints a stylized banner of a package name using a FIGlet font.
91
+ *
92
+ * The banner can optionally include the package version appended to the last visible line of the generated ASCII text.
93
+ *
94
+ * This is useful for CLI tools to display a startup banner with project name and version.
95
+ *
96
+ * @remarks
97
+ * - If `displayName` is available and `useDisplayName` is `true`, it will be used instead of `name`.
98
+ * - If `useVersion` is enabled and `pkg.version` exists, the version will be aligned to the
99
+ * right side of the banner's last visible line.
100
+ * - If the banner contains no printable lines, the raw FIGlet output is printed.
101
+ * - If `color` is disabled, all ANSI styling is turned off.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { print } from "echo-banner";
106
+ * import pkg from "../package.json";
107
+ *
108
+ * await print({
109
+ * pkg,
110
+ * font: "Slant"
111
+ * });
112
+ * ```
113
+ *
114
+ * @example Custom version prefix
115
+ * ```ts
116
+ * await print({
117
+ * pkg,
118
+ * prefixVersion: "@",
119
+ * });
120
+ * ```
121
+ *
122
+ * @example Disable version output
123
+ * ```ts
124
+ * await print({
125
+ * pkg,
126
+ * useVersion: false
127
+ * });
128
+ * ```
129
+ *
130
+ * @example Use package name instead of display name
131
+ * ```ts
132
+ * await print({
133
+ * pkg,
134
+ * useDisplayName: false
135
+ * });
136
+ * ```
137
+ *
138
+ * @example Disable colors
139
+ * ```ts
140
+ * await print({
141
+ * pkg,
142
+ * color: false
143
+ * });
144
+ * ```
145
+ */
146
+ declare function print({
147
+ pkg,
148
+ useVersion,
149
+ useDisplayName,
150
+ prefixVersion,
151
+ font,
152
+ color
153
+ }: {
154
+ /** Package metadata containing the name, optional display name, and version. */pkg: Pick<PackageMeta, 'name' | 'displayName' | 'version'>;
155
+ /**
156
+ * Whether to append the version to the banner.
157
+ *
158
+ * @default true
159
+ */
160
+ useVersion?: boolean;
161
+ /**
162
+ * Prefer `displayName` over `name` when available.
163
+ *
164
+ * @default true
165
+ */
166
+ useDisplayName?: boolean;
167
+ /**
168
+ * Prefix added before the version string.
169
+ *
170
+ * @default "v"
171
+ *
172
+ * @example "v1.0.0"
173
+ */
174
+ prefixVersion?: string;
175
+ /**
176
+ * Figlet font used to render the banner.
177
+ *
178
+ * @default "Slant"
179
+ */
180
+ font?: FontName;
181
+ /**
182
+ * Enable or disable colored output.
183
+ *
184
+ * @default true
185
+ */
186
+ color?: boolean;
187
+ }): Promise<void>;
25
188
  //#endregion
26
- export { banner };
189
+ export { banner, print };
package/dist/index.d.mts CHANGED
@@ -4,6 +4,51 @@ import { PackageJson, SHEBANG } from "js-utils-kit";
4
4
  //#region lib/index.d.ts
5
5
  type Shebang = (typeof SHEBANG)[keyof typeof SHEBANG];
6
6
  type PackageMeta = Pick<PackageJson, 'name' | 'displayName' | 'version' | 'description' | 'author' | 'license' | 'homepage' | 'repository'>;
7
+ /**
8
+ * Generate a production banner comment from package metadata.
9
+ *
10
+ * @remarks
11
+ * This utility creates a formatted banner typically used at the top of bundled files (e.g., Rollup, tsdown, esbuild, webpack outputs).
12
+ *
13
+ * The banner includes:
14
+ * - Package name or display name
15
+ * - Version (with optional prefix)
16
+ * - Description
17
+ * - Copyright
18
+ * - License
19
+ * - Homepage
20
+ * - Repository URL
21
+ *
22
+ * Repository URLs are normalized by removing common prefixes such as `git+` and suffixes like `.git`.
23
+ *
24
+ * @returns A formatted banner string suitable for insertion at the top of bundled files.
25
+ *
26
+ * @throws {TypeError} Thrown if the provided `pkg` value is not a valid object.
27
+ *
28
+ * @example Basic usage
29
+ * ```ts
30
+ * import pkg from "../package.json";
31
+ *
32
+ * const text = banner({ pkg });
33
+ * console.log(text);
34
+ * ```
35
+ *
36
+ * @example With shebang for CLI tools
37
+ * ```ts
38
+ * const text = banner({
39
+ * pkg,
40
+ * shebang: "#!/usr/bin/env node"
41
+ * });
42
+ * ```
43
+ *
44
+ * @example Using display name
45
+ * ```ts
46
+ * const text = banner({
47
+ * pkg,
48
+ * useDisplayName: true
49
+ * });
50
+ * ```
51
+ */
7
52
  declare function banner({
8
53
  pkg,
9
54
  shebang,
@@ -12,15 +57,133 @@ declare function banner({
12
57
  prefixVersion,
13
58
  fallback
14
59
  }: {
15
- pkg: PackageMeta;
60
+ /** Package metadata used to construct the banner */pkg: PackageMeta;
61
+ /**
62
+ * Optional shebang line (for CLI binaries).
63
+ *
64
+ * @default false
65
+ */
16
66
  shebang?: Shebang | false;
17
- style?: 'js';
67
+ /**
68
+ * Banner comment style.
69
+ *
70
+ * Currently supports:
71
+ * - `js`
72
+ *
73
+ * @default "js"
74
+ */
75
+ style?: 'js'; /** Prefer `displayName` over `name` when available */
18
76
  useDisplayName?: boolean;
19
- prefixVersion?: string;
77
+ /**
78
+ * Prefix applied before the version.
79
+ *
80
+ * @default "v"
81
+ */
82
+ prefixVersion?: string; /** Fallback values when `name` or `version` are missing */
20
83
  fallback?: {
21
84
  name?: string;
22
85
  version?: string;
23
86
  };
24
87
  }): string;
88
+ type FontName = '1Row' | '3-D' | '3D Diagonal' | '3D-ASCII' | '3x5' | '4Max' | '5 Line Oblique' | 'Standard' | 'Ghost' | 'Big' | 'Block' | 'Bubble' | 'Digital' | 'Ivrit' | 'Mini' | 'Script' | 'Shadow' | 'Slant' | 'Small' | 'Speed' | 'Tinker-Toy';
89
+ /**
90
+ * Prints a stylized banner of a package name using a FIGlet font.
91
+ *
92
+ * The banner can optionally include the package version appended to the last visible line of the generated ASCII text.
93
+ *
94
+ * This is useful for CLI tools to display a startup banner with project name and version.
95
+ *
96
+ * @remarks
97
+ * - If `displayName` is available and `useDisplayName` is `true`, it will be used instead of `name`.
98
+ * - If `useVersion` is enabled and `pkg.version` exists, the version will be aligned to the
99
+ * right side of the banner's last visible line.
100
+ * - If the banner contains no printable lines, the raw FIGlet output is printed.
101
+ * - If `color` is disabled, all ANSI styling is turned off.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { print } from "echo-banner";
106
+ * import pkg from "../package.json";
107
+ *
108
+ * await print({
109
+ * pkg,
110
+ * font: "Slant"
111
+ * });
112
+ * ```
113
+ *
114
+ * @example Custom version prefix
115
+ * ```ts
116
+ * await print({
117
+ * pkg,
118
+ * prefixVersion: "@",
119
+ * });
120
+ * ```
121
+ *
122
+ * @example Disable version output
123
+ * ```ts
124
+ * await print({
125
+ * pkg,
126
+ * useVersion: false
127
+ * });
128
+ * ```
129
+ *
130
+ * @example Use package name instead of display name
131
+ * ```ts
132
+ * await print({
133
+ * pkg,
134
+ * useDisplayName: false
135
+ * });
136
+ * ```
137
+ *
138
+ * @example Disable colors
139
+ * ```ts
140
+ * await print({
141
+ * pkg,
142
+ * color: false
143
+ * });
144
+ * ```
145
+ */
146
+ declare function print({
147
+ pkg,
148
+ useVersion,
149
+ useDisplayName,
150
+ prefixVersion,
151
+ font,
152
+ color
153
+ }: {
154
+ /** Package metadata containing the name, optional display name, and version. */pkg: Pick<PackageMeta, 'name' | 'displayName' | 'version'>;
155
+ /**
156
+ * Whether to append the version to the banner.
157
+ *
158
+ * @default true
159
+ */
160
+ useVersion?: boolean;
161
+ /**
162
+ * Prefer `displayName` over `name` when available.
163
+ *
164
+ * @default true
165
+ */
166
+ useDisplayName?: boolean;
167
+ /**
168
+ * Prefix added before the version string.
169
+ *
170
+ * @default "v"
171
+ *
172
+ * @example "v1.0.0"
173
+ */
174
+ prefixVersion?: string;
175
+ /**
176
+ * Figlet font used to render the banner.
177
+ *
178
+ * @default "Slant"
179
+ */
180
+ font?: FontName;
181
+ /**
182
+ * Enable or disable colored output.
183
+ *
184
+ * @default true
185
+ */
186
+ color?: boolean;
187
+ }): Promise<void>;
25
188
  //#endregion
26
- export { banner };
189
+ export { banner, print };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * echo-banner v0.1.0
2
+ * echo-banner v0.3.0
3
3
  * Generate multiline build banners and ASCII CLI titles
4
4
  *
5
5
  * (c) 2026 Sriman
@@ -8,4 +8,4 @@
8
8
  * https://teneplaysofficial.github.io/echo-banner
9
9
  * https://github.com/teneplaysofficial/echo-banner
10
10
  */
11
- import{EOL as e}from"node:os";function t({pkg:t,shebang:n=!1,style:r=`js`,useDisplayName:i=!1,prefixVersion:a=`v`,fallback:o={name:`unknown`,version:`0.0.0`}}){if(!t||typeof t!=`object`)throw TypeError(`Expected valid metadata`);let s=``,c=[],l=new Date().getFullYear(),u=/^(git\+)|(\.git)$/g;n&&(s+=n+e.repeat(2)),c.push(`${(i?t.displayName:t.name)??o.name} ${a}${t.version??o.version}`),c.push(t.description??``),c.push(``),c.push(`(c) ${l} ${(typeof t.author==`object`?t.author.name:t.author)??``}`),t.license&&c.push(`Released under the ${t.license} License`),c.push(``);let d=t.homepage;d&&c.push(d);let f=typeof t.repository==`object`?t.repository.url?.replace(u,``):t.repository?.replace(u,``);switch(f&&c.push(f),r){case`js`:s+=[`/*!`,...c.slice(0,c.findLastIndex(e=>e!==``)+1).map(e=>` * ${e}`),` */`].join(e);break}return s}export{t as banner};
11
+ import{EOL as e}from"node:os";import t from"figlet";import n from"use-colors";function r({pkg:t,shebang:n=!1,style:r=`js`,useDisplayName:i=!1,prefixVersion:a=`v`,fallback:o={name:`unknown`,version:`0.0.0`}}){if(!t||typeof t!=`object`)throw TypeError(`Expected valid metadata`);let s=``,c=[],l=new Date().getFullYear(),u=/^(git\+)|(\.git)$/g;n&&(s+=n+e.repeat(2)),c.push(`${(i?t.displayName:t.name)??o.name} ${a}${t.version??o.version}`),c.push(t.description??``),c.push(``),c.push(`(c) ${l} ${(typeof t.author==`object`?t.author.name:t.author)??``}`),t.license&&c.push(`Released under the ${t.license} License`),c.push(``);let d=t.homepage;d&&c.push(d);let f=typeof t.repository==`object`?t.repository.url?.replace(u,``):t.repository?.replace(u,``);switch(f&&c.push(f),r){case`js`:s+=[`/*!`,...c.slice(0,c.findLastIndex(e=>e!==``)+1).map(e=>` * ${e}`),` */`].join(e);break}return s}async function i({pkg:r,useVersion:i=!0,useDisplayName:a=!0,prefixVersion:o=`v`,font:s=`Slant`,color:c=!0}){let l=a&&r.displayName||r.name;if(!l)return;c||n.config({level:0});let u=await t.text(l,{font:s});if(!i||!r.version){console.log(n.cyanBright(u));return}let d=u.split(e),f=n.gray`${o}${r.version}`,p=d.findLastIndex(e=>e.trim().length>0);if(p<0){console.log(n.cyanBright(u));return}let m=Math.max(...d.map(e=>e.trimEnd().length)),h=d[p].trimEnd(),g=m-h.length+2;d[p]=n.cyanBright(h)+` `.repeat(g)+f,console.log(d.join(e))}export{r as banner,i as print};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "echo-banner",
3
3
  "displayName": "Echo Banner",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "description": "Generate multiline build banners and ASCII CLI titles",
6
6
  "keywords": [
7
7
  "cli",
@@ -41,6 +41,7 @@
41
41
  },
42
42
  "scripts": {
43
43
  "build": "tsdown",
44
+ "build:docs": "typedoc",
44
45
  "fmt": "prettier --write .",
45
46
  "fmt:check": "prettier --check .",
46
47
  "lint": "biome check",
@@ -52,7 +53,8 @@
52
53
  },
53
54
  "dependencies": {
54
55
  "figlet": "^1.10.0",
55
- "js-utils-kit": "^2.1.0"
56
+ "js-utils-kit": "^2.1.0",
57
+ "use-colors": "^0.1.0"
56
58
  },
57
59
  "devDependencies": {
58
60
  "@biomejs/biome": "^2.4.5",
@@ -63,6 +65,7 @@
63
65
  "lint-staged": "^16.3.2",
64
66
  "prettier": "^3.8.1",
65
67
  "tsdown": "^0.20.3",
68
+ "typedoc": "^0.28.17",
66
69
  "typescript": "^5.9.3",
67
70
  "vitest": "^4.0.18"
68
71
  },