How to use the slugify function from underscore.string
Find comprehensive JavaScript underscore.string.slugify code examples handpicked from public code repositorys.
underscore.string.slugify is a function in the Underscore.string library that converts a string to a URL-friendly slug by replacing spaces and special characters with dashes.
23 24 25 26 27 28 29 30 31 32
filter: x => normalizeUrl(x) }]); const template = { appName: props.appName, slugifiedAppName: _s.slugify(props.appName), classifiedAppName: _s.classify(props.appName), githubUsername: props.githubUsername, repoUrl: `https://github.com/${props.githubUsername}/${props.slugifiedAppName}`, name: this.user.git.name(),
65
715
0
57 58 59 60 61 62 63 64 65 66
if (this.appName && Path.basename(oldRoot) !== this.appName) { this.destinationRoot(Path.join(oldRoot, this.appName)); //Reset the defaults Util.setDefaults(this); } this.slugAppName = _.slugify(this.appName); }, writing: { app: function () { var self = this;
34
70
12
How does underscore.string.slugify work?
The underscore.string.slugify
function is used to convert a string into a valid slug by removing special characters, replacing spaces with hyphens, and converting all characters to lower case.
GitHub: sumaolin/generator-kmapp
38 39 40 41 42 43 44 45 46
); }, bower: function() { var bowerJson = { name: _s.slugify(this.appname), private: true, dependencies: {} };
2
5
0
125 126 127 128 129 130 131 132 133 134
cli.prompt([ { type: 'input', name: 'id', message: 'Choose an ID for this configuration', default: _s.slugify(answers.issuerName), value: flags['id'] || flags.i } ], function (issId) { request({
11
3
14
Ai Example
1 2 3 4 5 6 7
const _ = require("underscore.string"); const originalString = "This is a sample string!"; const slugifiedString = _.slugify(originalString); console.log(slugifiedString); // Output: this-is-a-sample-string
124 125 126 127 128 129 130 131 132 133
cli.prompt([ { type: 'input', name: 'id', message: 'Choose an ID for this configuration', default: _s.slugify(answers.name), value: flags['id'] || flags.i, filter: function (input) { return input && _s.slugify(input) },
11
3
14
183 184 185 186 187 188 189 190 191 192
} if (type == null) { type = 'meetup' } if (post.type === 'academy') post.slug = _s.slugify(post.what.split(':')[0]) else post.slug = _s.slugify(post.what) if (!event_id) { const slugs = await Events.query((qb) => qb.where('slug', 'LIKE', `${post.slug}%`)
5
3
8
+ 121 other calls in file
54 55 56 57 58 59 60 61 62 63
this.deployDirectory = this.answers.deployDirectory; } else { this.appname = this.options.name; this.appslug = _s.slugify(this.options.name); this.stash = ''; this.deployDirectory = this.options.deployDir; }
6
2
7
19 20 21 22 23 24 25 26 27 28 29 30
// If appName is not given, use the current directory if (appName === undefined) { appName = getBaseDir() } return _.slugify(_.humanize(appName)) } /** * kintone API へのリクエストメソッドをラップして以下の挙動を追加する
0
2
3
+ 94 other calls in file
22 23 24 25 26 27 28 29 30 31
init() { return this.prompt([{ name: 'repoName', message: 'What do you want to name your module?', default: this.appname.replace(/\s/g, '-'), filter: x => _s.slugify(x) }, { name: 'moduleDescription', message: 'What is your module description?', default: `My ${superb()} module`
0
2
1
+ 8 other calls in file
10 11 12 13 14 15 16 17 18 19 20
module.exports = { getDefaultAppName: (appName) => { if (appName == undefined) { appName = path.basename(process.cwd()); } return _.slugify(_.humanize(appName)); }, updatePackageConfig: (options, next) => { const fileName = path.resolve(options.appName, './package.json');
0
1
1
+ 33 other calls in file
31 32 33 34 35 36 37 38 39 40
} init() { return this.prompt([{ name: 'moduleName', message: 'What do you want to name your module?', default: _s.slugify(this.appname), filter: x => utils.slugifyPackageName(x) }, { name: 'moduleDescription', message: 'What is your module description?',
0
1
0
+ 4 other calls in file
188 189 190 191 192 193 194 195 196 197
this.templatePath('gitattributes'), this.destinationPath('.gitattributes')); }, bower: function() { var bowerJson = { name: _s.slugify(this.appName), version: this.appVersion, license: this.appLicense, private: true, dependencies: {}
0
1
2
+ 2 other calls in file
200 201 202 203 204 205 206 207 208 209 210
* @param {String} path * @return {String} */ let getComponentStyleName = (path) => { let fileName = path.split('/').pop().toLowerCase(); return _.slugify(_.humanize(fileName)) + '-component'; }; /** * Get a js friendly application name
0
1
0
30 31 32 33 34 35 36 37 38 39 40
message: 'Name to deploy as:', default: this.appname }]; this.prompt(prompts, function (props) { this.deployedName = s.slugify(props.deployedName).split('-').join(''); done(); }.bind(this)); };
0
0
1
80 81 82 83 84 85 86 87 88 89
default: false }]; this.prompt(prompts, function(props) { this.componentNameRaw = props.componentName.trim(); this.componentName = str.slugify(this.componentNameRaw); this.componentClassName = str.classify(this.componentNameRaw); this.description = props.description.trim(); this.license = props.license; this.contrib = props.contrib;
0
0
0
12 13 14 15 16 17 18 19 20 21 22
try { this.appname = require(path.join(process.cwd(), 'bower.json')).name; } catch (e) { this.appname = path.basename(process.cwd()); } this.appname = s.slugify(this.appname); this.filters = this.config.get('filters') || {}; }; util.inherits(Generator, yeoman.generators.NamedBase);
0
0
0
underscore.string.slugify is the most popular function in underscore.string (323 examples)