How to use the kebabCase function from lodash

Find comprehensive JavaScript lodash.kebabCase code examples handpicked from public code repositorys.

lodash.kebabCase converts a string to kebab case.

120
121
122
123
124
125
126
127
128
129

  this.writeFile(projectPath, 'package.json', `${JSON.stringify(pkg, null, 2)}\n`);
}

static tableToFilename(table) {
  return _.kebabCase(table);
}

static getDatabaseUrl(config) {
  let connectionString;
fork icon114
star icon0
watch icon40

+ 3 other calls in file

230
231
232
233
234
235
236
237
238
239
module.exports.iterateUntil        = _.iterateUntil;
module.exports.iteratee            = _.iteratee;
module.exports.iterators           = _.iterators;
module.exports.join                = _.join;
module.exports.juxt                = _.juxt;
module.exports.kebabCase           = _.kebabCase;
module.exports.keep                = _.keep;
module.exports.keepIndexed         = _.keepIndexed;
module.exports.keyBy               = _.keyBy;
module.exports.keys                = _.keys;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

How does lodash.kebabCase work?

lodash.kebabCase is a function that takes a string as input and converts it to kebab case, meaning it replaces any non-alphanumeric characters with hyphens and lowercases the string.

197
198
199
200
201
202
203
204
205
206
}

writeRoute(dbDialect, modelName) {
  const routesPath = `routes/${ForestExpress.tableToFilename(modelName)}.js`;

  const modelNameDasherized = _.kebabCase(modelName);
  const readableModelName = _.startCase(modelName);

  this.copyHandleBarsTemplate('routes/route.hbs', routesPath, {
    modelName: ForestExpress.getModelNameFromTableName(modelName),
fork icon2
star icon51
watch icon12

+ 27 other calls in file

802
803
804
805
806
807
808
809
810
811
812
813
814
console.log(escape); // => 'fred, barney, & pebbles'


const escapeRegExp = _.escapeRegExp('[lodash](https://lodash.com/)');
console.log(escapeRegExp); // => '\[lodash\]\(https://lodash\.com/\)'


const kebabCase = _.kebabCase('Foo Bar');
console.log(kebabCase); // => 'foo-bar'


const lowerCase = _.lowerCase('--Foo-Bar--');
console.log(lowerCase); // => 'foo bar'
fork icon0
star icon4
watch icon0

+ 15 other calls in file

Ai Example

1
2
3
4
5
6
const _ = require("lodash");

const myString = "Hello, World! This is an example of kebab case.";

console.log(_.kebabCase(myString));
// Output: 'hello-world-this-is-an-example-of-kebab-case'

In this example, we require lodash, define a string, and use the _.kebabCase method to convert the string to kebab case, which replaces spaces and underscores with hyphens and converts all characters to lowercase.

160
161
162
163
164
165
166
167
168
169
  { data.mdx.frontmatter.title }
</h1>
<div className={styles.authorContainer}>
  <div className={styles.authorInformation}>
    <img src={`images/${authorBlog.image}`} alt="" className={styles.authorImage} />
    <Link className={classnames(styles.authorName, "text__paragraph__bold__black")} to={`/authors/${ _.kebabCase(authorBlog.author) }`}>{ authorBlog.displayName }</Link>
  </div>
  <div className={styles.blogInfoContainer}>
    <label className={classnames(styles.postDate, "text__label__bold__grayTwo")} >{data.mdx.frontmatter.date}</label>
    <ClockIcon className={styles.clockIcon} />
fork icon2
star icon2
watch icon0

150
151
152
153
154
155
156
157
158
159
   draft: true
   # cspell:ignore 
   ---\n`;

if (assets) {
	const dirname = lodash.kebabCase(title);
	const dirpath = path.join(POSTS_DIR, dirname);
	fs.mkdirSync(dirpath);
	fs.writeFileSync(path.join(dirpath, 'index.md'), content);
	console.log(
fork icon0
star icon1
watch icon0

+ 5 other calls in file

20
21
22
23
24
25
26
27
28
29
})

for (const session of data.sessions) {
  api.loadSource(store => {
    const collection = store.addCollection('Session')
    var speaker = _.kebabCase(session.speaker)
    var title = _.kebabCase(session.title)
    var path = `/${speaker}/${title}`

    collection.addNode({
fork icon0
star icon0
watch icon1

+ 3 other calls in file

55
56
57
58
59
60
61
62
63
64
message: 'Enter a title for the post:',
validate: function (value) {
    if (value.trim() === '') {
        return 'Please provide a title.';
    }
    let filename = lodash.kebabCase(value) + '.md';
    if (fileExists(filename)) {
        return Chalk.red(`File already exists: `) + Chalk.underline(filename);
    }
    return true;
fork icon0
star icon0
watch icon1

+ 9 other calls in file

306
307
308
309
310
311
312
313
314
315
parsedYaml: (arg) => yaml.load(arg),
lowerCase: (arg) => arg.toLowerCase(),
upperCase: (arg) => arg.toUpperCase(),
camelCase: (arg) => _.camelCase(arg),
snakeCase: (arg) => _.snakeCase(arg),
kebabCase: (arg) => _.kebabCase(arg),
startCase: (arg) => _.startCase(arg),
formatted: (format) => (insert) => format.replace(/(?<!\\)%s/g, insert),
first: (arg) => arg[0],
last: (arg) => arg[arg.length - 1],
fork icon0
star icon0
watch icon1

+ 2 other calls in file

152
153
154
155
156
157
158
159
160
161
 * @returns {string}
 */
const getContentTypeRoutePrefix = (contentType) => {
  return isSingleType(contentType)
    ? _.kebabCase(contentType.info.singularName)
    : _.kebabCase(contentType.info.pluralName);
};

module.exports = {
  isScalarAttribute,
fork icon0
star icon0
watch icon658

+ 3 other calls in file

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)