@reliverse/rempts 1.7.10 → 1.7.11

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.
@@ -1,20 +1,64 @@
1
+ import { type Color, type Options as OraOptions } from "ora";
1
2
  type SpinnerOptions = {
2
3
  text: string;
4
+ color?: Color;
5
+ spinner?: OraOptions["spinner"];
6
+ successText?: string;
7
+ failText?: string;
3
8
  };
4
9
  type SpinnerControls = {
5
- start: () => SpinnerControls;
10
+ start: (text?: string) => SpinnerControls;
6
11
  stop: () => void;
7
12
  setText: (text: string) => void;
13
+ succeed: (text?: string) => void;
14
+ fail: (text?: string) => void;
15
+ warn: (text?: string) => void;
16
+ info: (text?: string) => void;
17
+ isSpinning: () => boolean;
18
+ clear: () => void;
8
19
  };
9
20
  /**
10
- * Creates a terminal spinner.
21
+ * Creates a terminal spinner with enhanced controls and styling options.
11
22
  *
12
23
  * @example
13
- * \`\`\`typescript
14
- * const spinner = useSpinner({ text: "preparing something..." }).start();
15
- * // user's code
24
+ * ```typescript
25
+ * // Basic usage
26
+ * const spinner = useSpinner({ text: "Loading..." }).start();
16
27
  * spinner.stop();
17
- * \`\`\`
28
+ *
29
+ * // With custom color and spinner
30
+ * const spinner = useSpinner({
31
+ * text: "Processing...",
32
+ * color: "cyan",
33
+ * spinner: "dots"
34
+ * }).start();
35
+ *
36
+ * // With success/failure states
37
+ * const spinner = useSpinner({
38
+ * text: "Uploading...",
39
+ * successText: "Upload complete!",
40
+ * failText: "Upload failed!"
41
+ * }).start();
42
+ * try {
43
+ * await uploadFile();
44
+ * spinner.succeed();
45
+ * } catch (error) {
46
+ * spinner.fail();
47
+ * }
48
+ *
49
+ * // Using the wrapper for async operations
50
+ * await useSpinner.promise(
51
+ * async () => { await longOperation(); },
52
+ * {
53
+ * text: "Working...",
54
+ * successText: "Done!",
55
+ * failText: "Failed!"
56
+ * }
57
+ * );
58
+ * ```
18
59
  */
19
60
  export declare function useSpinner(options: SpinnerOptions): SpinnerControls;
61
+ export declare namespace useSpinner {
62
+ var promise: <T>(operation: () => Promise<T>, options: SpinnerOptions) => Promise<T>;
63
+ }
20
64
  export {};
@@ -2,9 +2,18 @@ import ora from "ora";
2
2
  export function useSpinner(options) {
3
3
  let spinnerInstance = null;
4
4
  const controls = {
5
- start: () => {
5
+ start: (text) => {
6
+ if (text) {
7
+ options.text = text;
8
+ }
6
9
  if (!spinnerInstance) {
7
- spinnerInstance = ora(options.text);
10
+ spinnerInstance = ora({
11
+ text: options.text,
12
+ color: options.color,
13
+ spinner: options.spinner
14
+ });
15
+ } else {
16
+ spinnerInstance.text = options.text;
8
17
  }
9
18
  spinnerInstance.start();
10
19
  return controls;
@@ -20,7 +29,46 @@ export function useSpinner(options) {
20
29
  } else {
21
30
  options.text = text;
22
31
  }
32
+ },
33
+ succeed: (text) => {
34
+ if (spinnerInstance) {
35
+ spinnerInstance.succeed(text ?? options.successText);
36
+ }
37
+ },
38
+ fail: (text) => {
39
+ if (spinnerInstance) {
40
+ spinnerInstance.fail(text ?? options.failText);
41
+ }
42
+ },
43
+ warn: (text) => {
44
+ if (spinnerInstance) {
45
+ spinnerInstance.warn(text);
46
+ }
47
+ },
48
+ info: (text) => {
49
+ if (spinnerInstance) {
50
+ spinnerInstance.info(text);
51
+ }
52
+ },
53
+ isSpinning: () => {
54
+ return spinnerInstance?.isSpinning ?? false;
55
+ },
56
+ clear: () => {
57
+ if (spinnerInstance) {
58
+ spinnerInstance.clear();
59
+ }
23
60
  }
24
61
  };
25
62
  return controls;
26
63
  }
64
+ useSpinner.promise = async (operation, options) => {
65
+ const spinner = useSpinner(options).start();
66
+ try {
67
+ const result = await operation();
68
+ spinner.succeed();
69
+ return result;
70
+ } catch (error) {
71
+ spinner.fail();
72
+ throw error;
73
+ }
74
+ };
package/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "license": "MIT",
29
29
  "name": "@reliverse/rempts",
30
30
  "type": "module",
31
- "version": "1.7.10",
31
+ "version": "1.7.11",
32
32
  "author": "reliverse",
33
33
  "bugs": {
34
34
  "email": "blefnk@gmail.com",
@@ -44,7 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@biomejs/biome": "1.9.4",
46
46
  "@eslint/js": "^9.26.0",
47
- "@reliverse/dler": "^1.2.4",
47
+ "@reliverse/dler": "^1.2.5",
48
48
  "@reliverse/relidler-cfg": "^1.1.3",
49
49
  "@stylistic/eslint-plugin": "^4.2.0",
50
50
  "@total-typescript/ts-reset": "^0.6.1",