How to use the dasherize function from inflection

Find comprehensive JavaScript inflection.dasherize code examples handpicked from public code repositorys.

inflection.dasherize is a function that converts underscored or camel-cased words into dash-separated words.

108
109
110
111
112
113
114
115
116
117
118
119
  return deferred.promise;
}


function getName(name) {
  name = name.toLowerCase();
  name = inflection.dasherize(name).replace(/-/g, '_');
  name = inflection.camelize(name, true);


  return name;
}
fork icon0
star icon0
watch icon1

108
109
110
111
112
113
114
115
116
117
118
119
  }
}


function getName (name) {
  name = name.toLowerCase()
  name = inflection.dasherize(name).replace(/-/g, '_')
  name = inflection.camelize(name, true)


  return name
}
fork icon0
star icon0
watch icon1

How does inflection.dasherize work?

inflection.dasherize is a function in the Inflection library for JavaScript that converts a string to kebab case by replacing spaces and underscores with dashes.

2
3
4
5
6
7
8
9
10
11
12
13
14
const inflection = require('inflection');


let typeDefs = [];
let knownClassNames = [];


const anchorName = (link) => inflection.dasherize(inflection.underscore(link.replace(/#/g, '-')));


const resolveInlineLinks = (str) => inline.replaceInlineTags(str, {
  link: (string, { completeTag, text }) => string.replace(completeTag, `[${text}](#${anchorName(text)})`),
}).newString;
fork icon0
star icon0
watch icon0

Ai Example

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

const myString = "my_variable_name";
const dashedString = inflection.dasherize(myString);

console.log(dashedString); // Output: "my-variable-name"