Skip to content

Change Case

Wrapper for change-case.

โšก๏ธ Prerequisites

  • Install the change-case package:
$ pnpm add change-case

---> 100%

๐ŸŽฌ Usage

<script>
    import {change_case} from "@sveu/extend/change_case"

    let value = "Svelte Action"
</script>

<h1>{change_case(value, "snakeCase")}</h1>

<input bind:value>

๐Ÿ‘ฉโ€๐Ÿ’ปAPI

๐Ÿ‘ป Arguments

Name Description Type Required
input The string to convert string Yes
type The type of conversion to perform string Yes

๐Ÿ™ˆ Options

Read the change-case documentation for more information.

โ†ฉ๏ธ Returns

The converted string.

๐Ÿงช Playground

Source Code ๐Ÿ‘€

Source Code
import type { Options } from "change-case"

import * as _changeCase from "./changeCase"

export type ChangeCaseType = keyof typeof _changeCase

/**
 * Wrapper for change-case
 *
 * @param input - Input string
 *
 * @param type - Type of change case
 *
 * @param options - [Change-case options](https://github.com/blakeembrey/change-case#options)
 *
 * @returns Changed string
 */
export function change_case(
    input: string,
    type: ChangeCaseType,
    options?: Options | undefined
) {
    return _changeCase[type](input, options)
}

Last update: 2023-02-17