toSlug property
String?
toSlug
Returns the String
to slug case.
Example
String foo = 'sLuG Case';
String fooSlug = foo.toSlug; // returns 'sLuG_Case'
Implementation
String? get toSlug {
if (this.isBlank) {
return this;
}
var words = this!.trim().split(RegExp(r'(\s+)'));
var slugWord = '';
if (this!.length == 1) {
return this;
}
for (var i = 0; i <= words.length - 1; i++) {
if (i == words.length - 1) {
slugWord += words[i];
} else {
slugWord += words[i] + '_';
}
}
return slugWord;
}