Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
The dashify npm package is a utility that converts a string with spaces or camelCase into a dash-separated string. This is particularly useful for creating URL slugs, CSS class names, or other identifiers that require a specific format.
Convert camelCase to dash-case
This feature allows you to convert a camelCase string into a dash-separated string. This is useful for transforming variable names or other identifiers into a format suitable for URLs or CSS class names.
const dashify = require('dashify');
const result = dashify('camelCaseString');
console.log(result); // Output: camel-case-string
Convert space-separated string to dash-case
This feature allows you to convert a space-separated string into a dash-separated string. This is useful for creating URL slugs or other identifiers from user input or other sources.
const dashify = require('dashify');
const result = dashify('space separated string');
console.log(result); // Output: space-separated-string
Convert mixed case and space-separated string to dash-case
This feature allows you to convert a string that contains both camelCase and spaces into a dash-separated string. This is useful for normalizing various types of input into a consistent format.
const dashify = require('dashify');
const result = dashify('MixedCase and space separated');
console.log(result); // Output: mixed-case-and-space-separated
The slugify package converts strings into URL-friendly slugs. It offers more customization options compared to dashify, such as handling special characters and providing options for different separator characters.
The kebab-case package converts camelCase or space-separated strings into kebab-case (dash-separated) strings. It is similar to dashify but focuses specifically on converting to kebab-case.
The lodash.kebabcase function from the lodash library converts strings to kebab-case. It is part of the larger lodash utility library, which offers a wide range of functions for manipulating and working with data.
Convert a camelcase or space-separated string to a dash-separated string.
I'm using this for converting object keys to dash-case. Most slugify libs are too heavy for this, so I made this as a fast and light alternative.
npm i dashify --save
var dashify = require('dashify');
dashify('fooBar');
//=> 'foo-bar'
dashify('fooBarBaz');
//=> 'foo-bar-baz'
dashify('foo bar');
//=> 'foo-bar'
dashify('foo barBaz');
//=> 'foo-bar-baz'
dashify('foo barBaz quux');
//=> 'foo-bar-baz-quux'
Install dev dependencies:
npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Jon Schlinkert
Copyright (c) 2015 Jon Schlinkert
Released under the MIT license
This file was generated by verb on February 12, 2015.
FAQs
Convert a camelcase or space-separated string to a dash-separated string. ~12 sloc, fast, supports diacritics.
We found that dashify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.