Coder Social home page Coder Social logo

Add typescript typings about spinnies HOT 3 OPEN

jbcarpanelli avatar jbcarpanelli commented on May 29, 2024 5
Add typescript typings

from spinnies.

Comments (3)

cfanoulis avatar cfanoulis commented on May 29, 2024 1

Hello! Any status on this?

from spinnies.

reslear avatar reslear commented on May 29, 2024

or use Spinnies.d.ts based on @adamjarret #25

declare module "spinnies" {
  type StopAllStatus = "succeed" | "fail" | "stopped";
  type SpinnerStatus = StopAllStatus | "spinning" | "non-spinnable";

  interface Spinner {
    interval: number;
    frames: string[];
  }

  interface SpinnerOptions {
    text?: string;
    indent?: number;
    status?: SpinnerStatus;
    color?: string;
    succeedColor?: string;
    failColor?: string;
  }

  interface Options {
    color?: string;
    succeedColor?: string;
    failColor?: string;
    spinnerColor?: string;
    succeedPrefix?: string;
    failPrefix?: string;
    disableSpins?: boolean;
    spinner?: Spinner;
  }

  export default class Spinnies {
    static dots: Spinner;
    static dashes: Spinner;
    constructor(options?: Options);
    add: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    pick: (name: string) => SpinnerOptions;
    remove: (name: string) => SpinnerOptions;
    update: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    succeed: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    fail: (name: string, options?: SpinnerOptions) => SpinnerOptions;
    stopAll: (status?: StopAllStatus) => { [name: string]: SpinnerOptions };
    hasActiveSpinners: () => boolean;
  }
}

from spinnies.

benjamincburns avatar benjamincburns commented on May 29, 2024

I'm hoping to get types added to DefinitelyTyped over in DefinitelyTyped/DefinitelyTyped#59503. In the meantime, here is the slightly improved local type declarations file that I'm using in my project:

declare module "spinnies" {
  const dots: Spinner;
  const dashes: Spinner;

  type Color =
    "black"
    | "red"
    | "green"
    | "yellow"
    | "blue"
    | "magenta"
    | "cyan"
    | "white"
    | "gray"
    | "redBright"
    | "greenBright"
    | "yellowBright"
    | "blueBright"
    | "magentaBright"
    | "cyanBright"
    | "whiteBright";

  type StopAllStatus = "succeed" | "fail" | "stopped";
  type SpinnerStatus = StopAllStatus | "spinning" | "non-spinnable";

  interface Spinner {
    interval: number;
    frames: string[];
  }

  /**
   * The configuration for a given spinner
   */
  interface SpinnerOptions {
    /**
     * Text to show in the spinner. If none is provided, the name field will be shown.
     */
    text: string;

    /**
     * Indent the spinner with the given number of spaces.
     */
    indent: number;

    /**
     * Initial status of the spinner.
     */
    status: SpinnerStatus;

    /**
     * The color of the text that accompanies the spinner. If not specified, the console's default foreground color is used.
     */
    color?: Color;

    /**
     * The color for the text on success. Default value is `"green"`
     */
    succeedColor: Color;

    /**
     * The color for the text on failure. Default value is `"red"`.
     */
    failColor: Color;

    /**
     * The color of the spinner, when active. The default value is `"greenBright"`
     */
    spinnerColor: Color;
  }

  /**
   * Contains top-level configuration for the Spinnies class. Also allows the
   * caller to override default values used in `SpinnerOptions`.
   */
  interface Options {
    /**
     * The color of the text that accompanies the spinner. If not specified, the console's default foreground color is used.
     */
    color?: Color;

    /**
     * The color for the text on success. Default value is `"green"`
     */
    succeedColor: Color;

    /**
     * The color for the text on failure. Default value is `"red"`.
     */
    failColor: Color;

    /**
     * The color of the spinner, when active. The default value is `"greenBright"`
     */
    spinnerColor: Color;

    /**
     * The symbol to be used in place of the spinner on success. The default value is ✓.
     */
    succeedPrefix: string;

    /**
     * The symbol to be used in place of the spinner on failure. The default value is ✖.
     */
    failPrefix: string;

    /**
     * Disable spinner animations (will still print raw messages if `true`). The default value is `false`.
     */
    disableSpins: boolean;

    /**
     * Defines the animated spinner to be used while each spinner is active/spinning.
     */
    spinner: Spinner;
  }

  /**
   * A class that manages multiple CLI spinners.
   */
  export default class Spinnies {
    /**
     * The current configuration of this Spinnies object.
     */
    options: Spinnies.Options;

    constructor(options?: Partial<Spinnies.Options>);

    /**
     * Add a new spinner with the given name.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    add: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Get spinner by name.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    pick: (name: string) => Spinnies.SpinnerOptions;

    /**
     * Remove spinner with name.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    remove: (name: string) => Spinnies.SpinnerOptions;

    /**
     * Updates the spinner with name name with the provided options. Retains
     * the value of options that aren't specified.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    update: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Sets the specified spinner status as succeed.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    succeed: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Sets the specified spinner status as fail.
     *
     * @returns full `SpinnerOptions` object for the given spinner, with
     * defaults applied
     */
    fail: (name: string, options?: Partial<Spinnies.SpinnerOptions>) => Spinnies.SpinnerOptions;

    /**
     * Stops the spinners and sets the non-succeeded and non-failed ones to the provided status.
     *
     * @returns an object that maps spinner names to final `SpinnerOptions` objects for each spinner, with
     * defaults applied
     */
    stopAll: (status?: Spinnies.StopAllStatus) => { [name: string]: Spinnies.SpinnerOptions };

    /**
     * @returns false if all spinners have succeeded, failed or have been stopped
     */
    hasActiveSpinners: () => boolean;

    /**
     * Disables the spinner loop after all spinners have deactivated. Must be
     * called after calling `remove` on the final spinner, otherwise the
     * spinner loop will prevent the process from exiting.
     */
    checkIfActiveSpinners: () => void;
  }
}

from spinnies.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.