@untitledq/string-toolkit
v1.1.0
Published
A small JavaScript utility library for string cases conversions.
Downloads
241
Readme
@untitledq/string-toolkit
A small JavaScript utility library for string case conversion.
Table of Contents
Overview
This project currently exposes two utility functions:
toSnakeCase(str): converts a string to lowercase snake_case by trimming leading and trailing whitespace and replacing internal whitespace with underscores.toKebabCase(str): converts a string to lowercase kebab-case by trimming leading and trailing whitespace and replacing internal whitespace with hyphens.
Example:
toSnakeCase("Hello World");
// "hello_world"toKebabCase("Hello World");
// "hello-world"Installation
Install dependencies for local development:
npm installIf you want to use the package as a dependency:
npm install @untitledq/string-toolkitUsage
Example:
const { toSnakeCase, toKebabCase } = require("@untitledq/string-toolkit");
console.log(toSnakeCase("Hello World"));
// "hello_world"
console.log(toKebabCase("Hello World"));
// "hello-world"Example with extra whitespace:
const { toSnakeCase, toKebabCase } = require("@untitledq/string-toolkit");
console.log(toSnakeCase(" Multiple Words Here "));
// "multiple_words_here"
console.log(toKebabCase(" Multiple Words Here "));
// "multiple-words-here"API
toSnakeCase(str)
Converts a string into snake_case.
Behavior:
- trims leading and trailing whitespace
- converts all letters to lowercase
- replaces one or more whitespace characters with a single underscore
Example:
const { toSnakeCase } = require("@untitledq/string-toolkit");
toSnakeCase("JavaScript Utility Library");
// "javascript_utility_library"toKebabCase(str)
Converts a string into kebab-case.
Behavior:
- trims leading and trailing whitespace
- converts all letters to lowercase
- replaces one or more whitespace characters with a single hyphen
Example:
const { toKebabCase } = require("@untitledq/string-toolkit");
toKebabCase("JavaScript Utility Library");
// "javascript-utility-library"Development
Run the test suite with:
npm testCurrent test coverage includes:
- converting words separated by spaces to snake_case
- converting words separated by spaces to kebab-case
Contribution
Contributions are welcome. See CONTRIBUTING.md for contribution guidelines.
Security
See SECURITY.md for vulnerability reporting and security policy details.
License
This project is licensed under the MIT License.
