Function toCommaSepareted

  • Converts a string to comma-separated format by replacing all non-word characters and underscores with commas.

    Example

    toCommaSepareted("one two")
    // => { ok: true, value: 'one,two' }

    toCommaSepareted("one;two")
    // => { ok: true, value: 'one,two' }

    toCommaSepareted("one-two")
    // => { ok: true, value: 'one,two' }

    toCommaSepareted("one_two")
    // => { ok: true, value: 'one,two' }

    Example

    Handle an invalid input string:

    toCommaSeparated(42)
    // => { ok: false, error: Error('[strings.toCommaSeparated] Expected string value as input') }

    Parameters

    • str: string

      The string to convert to comma-separated format.

    Returns Result<string, Error>

    A Result object with either the converted string on success, or an Error object if the provided input is not a string.

Generated using TypeDoc v0.24.7