@markuplint/cli-utils 4.4.12 → 4.4.14

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [4.4.14](https://github.com/markuplint/markuplint/compare/@markuplint/cli-utils@4.4.13...@markuplint/cli-utils@4.4.14) (2026-02-10)
7
+
8
+ **Note:** Version bump only for package @markuplint/cli-utils
9
+
10
+ ## [4.4.13](https://github.com/markuplint/markuplint/compare/@markuplint/cli-utils@4.4.12...@markuplint/cli-utils@4.4.13) (2025-11-05)
11
+
12
+ **Note:** Version bump only for package @markuplint/cli-utils
13
+
6
14
  ## [4.4.12](https://github.com/markuplint/markuplint/compare/@markuplint/cli-utils@4.4.11...@markuplint/cli-utils@4.4.12) (2025-08-13)
7
15
 
8
16
  ### Bug Fixes
package/lib/color.d.ts CHANGED
@@ -1 +1,9 @@
1
+ /**
2
+ * Creates a curried function that applies an xTerm 256-color foreground color
3
+ * to the given text using ANSI escape sequences. Falls back to plain text
4
+ * when color output is not supported.
5
+ *
6
+ * @param index - The xTerm 256-color palette index (0-255)
7
+ * @returns A function that wraps the given text with the specified color escape codes
8
+ */
1
9
  export declare const xterm: (index: number) => (text: string) => string;
package/lib/color.js CHANGED
@@ -1,4 +1,12 @@
1
1
  import c from 'picocolors';
2
+ /**
3
+ * Creates a curried function that applies an xTerm 256-color foreground color
4
+ * to the given text using ANSI escape sequences. Falls back to plain text
5
+ * when color output is not supported.
6
+ *
7
+ * @param index - The xTerm 256-color palette index (0-255)
8
+ * @returns A function that wraps the given text with the specified color escape codes
9
+ */
2
10
  export const xterm = (index) => (text) => {
3
11
  // https://github.com/jaywcjlove/colors-cli/blob/d3a3152ec2f087c46655e7d2a663ef637ed5fea5/lib/color.js#L121
4
12
  return c.isColorSupported ? '\u001B[38;5;' + index + 'm' + text + '\u001B[0m' : text;
@@ -1 +1,8 @@
1
+ /**
2
+ * Calculates the visual display width of a string, accounting for
3
+ * East Asian wide characters that occupy two columns in a terminal.
4
+ *
5
+ * @param s - The string to measure
6
+ * @returns The total display width in terminal columns
7
+ */
1
8
  export declare function getWidth(s: string): number;
package/lib/get-width.js CHANGED
@@ -1,6 +1,13 @@
1
1
  // @ts-ignore
2
2
  import eastasianwidth from 'eastasianwidth';
3
3
  const eaw = eastasianwidth;
4
+ /**
5
+ * Calculates the visual display width of a string, accounting for
6
+ * East Asian wide characters that occupy two columns in a terminal.
7
+ *
8
+ * @param s - The string to measure
9
+ * @returns The total display width in terminal columns
10
+ */
4
11
  export function getWidth(s) {
5
12
  let width = 0;
6
13
  for (const char of s) {
package/lib/header.d.ts CHANGED
@@ -1 +1,9 @@
1
+ /**
2
+ * Generates a formatted CLI header box containing the markuplint logo,
3
+ * name, version, and the given sub-command name.
4
+ *
5
+ * @param subCommandName - The name of the sub-command to display in the header
6
+ * @param noColor - When true, strips ANSI color codes from the output
7
+ * @returns A multi-line string representing the boxed header
8
+ */
1
9
  export declare const header: (subCommandName: string, noColor?: boolean) => string;
package/lib/header.js CHANGED
@@ -5,6 +5,14 @@ import { logo } from './logo.js';
5
5
  import { name } from './name.js';
6
6
  const require = module.createRequire(import.meta.url);
7
7
  const version = require('../package.json').version;
8
+ /**
9
+ * Generates a formatted CLI header box containing the markuplint logo,
10
+ * name, version, and the given sub-command name.
11
+ *
12
+ * @param subCommandName - The name of the sub-command to display in the header
13
+ * @param noColor - When true, strips ANSI color codes from the output
14
+ * @returns A multi-line string representing the boxed header
15
+ */
8
16
  export const header = (subCommandName, noColor) => box([
9
17
  // Logo and name
10
18
  `${logo} ${name}`,
package/lib/index.d.ts CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @module @markuplint/cli-utils
3
+ *
4
+ * Shared CLI utility functions for the markuplint command-line interface.
5
+ * Provides terminal color helpers, text formatting, interactive prompts,
6
+ * module installation, and display utilities used across markuplint CLI commands.
7
+ */
1
8
  export { default as font } from 'picocolors';
2
9
  export { xterm } from './color.js';
3
10
  export { input, confirm, confirmSequence, select, multiSelect } from './prompt.js';
package/lib/index.js CHANGED
@@ -1,3 +1,10 @@
1
+ /**
2
+ * @module @markuplint/cli-utils
3
+ *
4
+ * Shared CLI utility functions for the markuplint command-line interface.
5
+ * Provides terminal color helpers, text formatting, interactive prompts,
6
+ * module installation, and display utilities used across markuplint CLI commands.
7
+ */
1
8
  export { default as font } from 'picocolors';
2
9
  export { xterm } from './color.js';
3
10
  export { input, confirm, confirmSequence, select, multiSelect } from './prompt.js';
@@ -1,5 +1,16 @@
1
+ /**
2
+ * Represents the outcome of an {@link installModule} operation.
3
+ */
1
4
  export type InstallModuleResult = {
2
5
  success: boolean;
3
6
  alreadyExists: boolean;
4
7
  };
8
+ /**
9
+ * Installs one or more npm packages using the detected package manager
10
+ * (yarn or npm). Skips modules that are already installed locally.
11
+ *
12
+ * @param module - An array of module names to install
13
+ * @param dev - When true, installs as a dev dependency (adds the `-D` flag)
14
+ * @returns The result indicating success and whether all modules already existed
15
+ */
5
16
  export declare function installModule(module: readonly string[], dev?: boolean): Promise<InstallModuleResult>;
@@ -3,6 +3,14 @@ import c from 'picocolors';
3
3
  // @ts-ignore
4
4
  import detectInstalled from 'detect-installed';
5
5
  import hasYarn from 'has-yarn';
6
+ /**
7
+ * Installs one or more npm packages using the detected package manager
8
+ * (yarn or npm). Skips modules that are already installed locally.
9
+ *
10
+ * @param module - An array of module names to install
11
+ * @param dev - When true, installs as a dev dependency (adds the `-D` flag)
12
+ * @returns The result indicating success and whether all modules already existed
13
+ */
6
14
  export async function installModule(module, dev = false) {
7
15
  module = module.map(m => m.trim());
8
16
  const uninstallMods = [];
@@ -1,7 +1,9 @@
1
1
  /**
2
- * Convert all characters to space.
2
+ * Converts all visible characters in a string to spaces, preserving
3
+ * the visual width. Tabs are expanded to four spaces before conversion.
4
+ * Useful for generating indentation-preserving blank lines in CLI output.
3
5
  *
4
- * @param str
5
- * @returns
6
+ * @param str - The input string whose characters will be replaced with spaces
7
+ * @returns A string of the same visual length consisting only of space characters
6
8
  */
7
9
  export declare function invisibleSpace(str: string): string;
@@ -1,8 +1,10 @@
1
1
  /**
2
- * Convert all characters to space.
2
+ * Converts all visible characters in a string to spaces, preserving
3
+ * the visual width. Tabs are expanded to four spaces before conversion.
4
+ * Useful for generating indentation-preserving blank lines in CLI output.
3
5
  *
4
- * @param str
5
- * @returns
6
+ * @param str - The input string whose characters will be replaced with spaces
7
+ * @returns A string of the same visual length consisting only of space characters
6
8
  */
7
9
  export function invisibleSpace(str) {
8
10
  return (str
package/lib/logo.d.ts CHANGED
@@ -1 +1,2 @@
1
+ /** The markuplint logo rendered as a styled checkmark for terminal display. */
1
2
  export declare const logo: string;
package/lib/logo.js CHANGED
@@ -1,3 +1,4 @@
1
1
  import { xterm } from './color.js';
2
2
  import { PRIMARY_COLOR } from './const.js';
3
+ /** The markuplint logo rendered as a styled checkmark for terminal display. */
3
4
  export const logo = `/${xterm(PRIMARY_COLOR)('✔')}\\`;
@@ -1 +1,9 @@
1
+ /**
2
+ * Combines a lint violation message with an optional reason string.
3
+ * When a reason is provided, it is appended after a " / " separator.
4
+ *
5
+ * @param message - The primary violation message
6
+ * @param reason - An optional supplementary reason or detail to append
7
+ * @returns The combined message string
8
+ */
1
9
  export declare function messageToString(message: string, reason?: string): string;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Combines a lint violation message with an optional reason string.
3
+ * When a reason is provided, it is appended after a " / " separator.
4
+ *
5
+ * @param message - The primary violation message
6
+ * @param reason - An optional supplementary reason or detail to append
7
+ * @returns The combined message string
8
+ */
1
9
  export function messageToString(message, reason) {
2
10
  if (!reason) {
3
11
  return message;
package/lib/name.d.ts CHANGED
@@ -1 +1,2 @@
1
+ /** The styled markuplint product name with the "lint" portion colored in the brand color. */
1
2
  export declare const name: string;
package/lib/name.js CHANGED
@@ -1,3 +1,4 @@
1
1
  import { xterm } from './color.js';
2
2
  import { PRIMARY_COLOR } from './const.js';
3
+ /** The styled markuplint product name with the "lint" portion colored in the brand color. */
3
4
  export const name = `Markup${xterm(PRIMARY_COLOR)('lint')}`;
package/lib/pad.d.ts CHANGED
@@ -1 +1,10 @@
1
+ /**
2
+ * Pads a string or number with spaces to reach the specified display width.
3
+ * Accounts for East Asian wide characters when calculating the current width.
4
+ *
5
+ * @param s - The value to pad (converted to string if numeric)
6
+ * @param pad - The target display width in terminal columns
7
+ * @param start - When true, prepends spaces (right-aligns); otherwise appends spaces (left-aligns)
8
+ * @returns The padded string
9
+ */
1
10
  export declare function pad(s: number | string, pad: number, start?: boolean): string;
package/lib/pad.js CHANGED
@@ -1,4 +1,13 @@
1
1
  import { getWidth } from './get-width.js';
2
+ /**
3
+ * Pads a string or number with spaces to reach the specified display width.
4
+ * Accounts for East Asian wide characters when calculating the current width.
5
+ *
6
+ * @param s - The value to pad (converted to string if numeric)
7
+ * @param pad - The target display width in terminal columns
8
+ * @param start - When true, prepends spaces (right-aligns); otherwise appends spaces (left-aligns)
9
+ * @returns The padded string
10
+ */
2
11
  export function pad(s, pad, start = false) {
3
12
  const l = getWidth(`${s}`.trim());
4
13
  const d = pad - l;
package/lib/prompt.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ /**
2
+ * Defines a question for single or multi-select prompts.
3
+ *
4
+ * @template T - The type of the value associated with each choice
5
+ */
1
6
  type SelectQuestion<T> = {
2
7
  readonly message: string;
3
8
  readonly choices: readonly {
@@ -5,12 +10,51 @@ type SelectQuestion<T> = {
5
10
  readonly value: T;
6
11
  }[];
7
12
  };
13
+ /**
14
+ * Displays an interactive single-select prompt and returns the chosen value.
15
+ *
16
+ * @template T - The type of the value returned by the selected choice
17
+ * @param question - The question configuration including message and available choices
18
+ * @returns The value of the selected choice
19
+ */
8
20
  export declare function select<T>(question: SelectQuestion<T>): Promise<T>;
21
+ /**
22
+ * Displays an interactive multi-select prompt and returns an array of chosen values.
23
+ *
24
+ * @template T - The type of the values returned by the selected choices
25
+ * @param question - The question configuration including message and available choices
26
+ * @returns An array of values corresponding to the selected choices
27
+ */
9
28
  export declare function multiSelect<T>(question: SelectQuestion<T>): Promise<T[]>;
29
+ /**
30
+ * Displays an interactive text input prompt. Re-prompts the user if the
31
+ * input fails the optional validation pattern.
32
+ *
33
+ * @template T - The string subtype returned by the prompt
34
+ * @param question - The message to display as the prompt question
35
+ * @param validation - An optional regex pattern the input must match
36
+ * @returns The validated user input string
37
+ */
10
38
  export declare function input<T extends string = string>(question: string, validation?: Readonly<RegExp>): Promise<T>;
39
+ /**
40
+ * Displays an interactive yes/no confirmation prompt.
41
+ *
42
+ * @param question - The message to display as the confirmation question
43
+ * @param options - Optional settings for the prompt
44
+ * @param options.initial - The default answer when the user presses Enter without input
45
+ * @returns `true` if the user confirmed, `false` otherwise
46
+ */
11
47
  export declare function confirm(question: string, options?: {
12
48
  readonly initial?: boolean;
13
49
  }): Promise<boolean>;
50
+ /**
51
+ * Displays a sequence of yes/no confirmation prompts and collects all answers
52
+ * into a single record keyed by each question's name.
53
+ *
54
+ * @template T - The string literal union type of question names
55
+ * @param questions - An array of question objects, each with a message and a unique name
56
+ * @returns A record mapping each question name to its boolean answer
57
+ */
14
58
  export declare function confirmSequence<T extends string = string>(questions: readonly {
15
59
  readonly message: string;
16
60
  readonly name: T;
package/lib/prompt.js CHANGED
@@ -1,5 +1,12 @@
1
1
  import c from 'picocolors';
2
2
  import Enquirer from 'enquirer';
3
+ /**
4
+ * Displays an interactive single-select prompt and returns the chosen value.
5
+ *
6
+ * @template T - The type of the value returned by the selected choice
7
+ * @param question - The question configuration including message and available choices
8
+ * @returns The value of the selected choice
9
+ */
3
10
  export async function select(question) {
4
11
  const res = await Enquirer.prompt({
5
12
  ...question,
@@ -13,6 +20,13 @@ export async function select(question) {
13
20
  // @ts-ignore
14
21
  return res['__Q__'];
15
22
  }
23
+ /**
24
+ * Displays an interactive multi-select prompt and returns an array of chosen values.
25
+ *
26
+ * @template T - The type of the values returned by the selected choices
27
+ * @param question - The question configuration including message and available choices
28
+ * @returns An array of values corresponding to the selected choices
29
+ */
16
30
  export async function multiSelect(question) {
17
31
  const res = await Enquirer.prompt({
18
32
  ...question,
@@ -29,6 +43,15 @@ export async function multiSelect(question) {
29
43
  // @ts-ignore
30
44
  return res['__Q__'];
31
45
  }
46
+ /**
47
+ * Displays an interactive text input prompt. Re-prompts the user if the
48
+ * input fails the optional validation pattern.
49
+ *
50
+ * @template T - The string subtype returned by the prompt
51
+ * @param question - The message to display as the prompt question
52
+ * @param validation - An optional regex pattern the input must match
53
+ * @returns The validated user input string
54
+ */
32
55
  export async function input(question, validation) {
33
56
  while (true) {
34
57
  const _res = await Enquirer.prompt({
@@ -45,6 +68,14 @@ export async function input(question, validation) {
45
68
  return res;
46
69
  }
47
70
  }
71
+ /**
72
+ * Displays an interactive yes/no confirmation prompt.
73
+ *
74
+ * @param question - The message to display as the confirmation question
75
+ * @param options - Optional settings for the prompt
76
+ * @param options.initial - The default answer when the user presses Enter without input
77
+ * @returns `true` if the user confirmed, `false` otherwise
78
+ */
48
79
  export async function confirm(question, options) {
49
80
  const res = await Enquirer.prompt({
50
81
  message: question,
@@ -55,6 +86,14 @@ export async function confirm(question, options) {
55
86
  // @ts-ignore
56
87
  return !!res['__Q__'];
57
88
  }
89
+ /**
90
+ * Displays a sequence of yes/no confirmation prompts and collects all answers
91
+ * into a single record keyed by each question's name.
92
+ *
93
+ * @template T - The string literal union type of question names
94
+ * @param questions - An array of question objects, each with a message and a unique name
95
+ * @returns A record mapping each question name to its boolean answer
96
+ */
58
97
  export async function confirmSequence(questions) {
59
98
  const res = await Enquirer.prompt(questions.map(question => {
60
99
  return {
package/lib/space.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
- * Replace space to visible characters.
2
+ * Replaces whitespace characters with visible symbols for debugging display.
3
+ * Spaces become middle dots (`\u2022`) and tabs become right arrows (`\u2192`) followed
4
+ * by three spaces. All whitespace is dimmed using xTerm color 8.
3
5
  *
4
- * @param str
5
- * @returns
6
+ * @param str - The input string containing whitespace to visualize
7
+ * @returns The string with whitespace replaced by visible indicator characters
6
8
  */
7
9
  export declare function space(str: string): string;
package/lib/space.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { xterm } from './color.js';
2
2
  /**
3
- * Replace space to visible characters.
3
+ * Replaces whitespace characters with visible symbols for debugging display.
4
+ * Spaces become middle dots (`\u2022`) and tabs become right arrows (`\u2192`) followed
5
+ * by three spaces. All whitespace is dimmed using xTerm color 8.
4
6
  *
5
- * @param str
6
- * @returns
7
+ * @param str - The input string containing whitespace to visualize
8
+ * @returns The string with whitespace replaced by visible indicator characters
7
9
  */
8
10
  export function space(str) {
9
11
  return str
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/cli-utils",
3
- "version": "4.4.12",
3
+ "version": "4.4.14",
4
4
  "description": "Utilities for CLI of Markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -24,9 +24,9 @@
24
24
  "detect-installed": "2.0.4",
25
25
  "eastasianwidth": "0.3.0",
26
26
  "enquirer": "2.4.1",
27
- "has-yarn": "3.0.0",
27
+ "has-yarn": "4.0.0",
28
28
  "picocolors": "1.1.1",
29
- "strip-ansi": "7.1.0"
29
+ "strip-ansi": "7.1.2"
30
30
  },
31
- "gitHead": "acbf53f7e30d7a59f850a0f279b617383266dab3"
31
+ "gitHead": "193ee7c1262bbed95424e38efdf1a8e56ff049f4"
32
32
  }