Skip to content

Commit

Permalink
Merge pull request #617 from klaus78/Issue611
Browse files Browse the repository at this point in the history
issue 611: added the method Kebaberize
  • Loading branch information
Oren Novotny authored Apr 18, 2017
2 parents 4b0ae7a + de8eab3 commit d3bb686
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Humanizer meets all your .NET needs for manipulating and displaying strings, enu
- [Camelize](#camelize)
- [Underscore](#underscore)
- [Dasherize & Hyphenate](#dasherize--hyphenate)
- [Kebaberize](#kebaberize)
- [Fluent date](#fluent-date)
- [Number to Numbers](#number-to-numbers)
- [Number to words](#number-to-words)
Expand Down Expand Up @@ -644,6 +645,13 @@ Obviously this only applies to some cultures. For others passing gender in or no
"some_title".Hyphenate() => "some-title"
```

#### <a id="kebaberize">Kebaberize</a>
`Kebaberize` separates the input words with hyphens and all words are converted to lowercase

```C#
"SomeText".Kebaberize() => "some-text"
```

### <a id="fluent-date">Fluent Date</a>
Humanizer provides a fluent API to deal with `DateTime` and `TimeSpan` as follows:

Expand Down
14 changes: 14 additions & 0 deletions src/Humanizer.Tests.Shared/InflectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,24 @@ public void Camelize(string input, string expectedOutput)
[InlineData("some title", "some_title")]
[InlineData("some title that will be underscored", "some_title_that_will_be_underscored")]
[InlineData("SomeTitleThatWillBeUnderscored", "some_title_that_will_be_underscored")]
[InlineData("SomeForeignWordsLikeÄgyptenÑu", "some_foreign_words_like_ägypten_ñu")]
[InlineData("Some wordsTo be Underscored", "some_words_to_be_underscored")]
public void Underscore(string input, string expectedOuput)
{
Assert.Equal(expectedOuput, input.Underscore());
}

// transform words into lowercase and separate with a -
[Theory]
[InlineData("SomeWords", "some-words")]
[InlineData("SOME words TOGETHER", "some-words-together")]
[InlineData("A spanish word EL niño", "a-spanish-word-el-niño")]
[InlineData("SomeForeignWords ÆgÑuÄgypten", "some-foreign-words-æg-ñu-ägypten")]
[InlineData("A VeryShortSENTENCE", "a-very-short-sentence")]
public void Kebaberize(string input, string expectedOutput)
{
Assert.Equal(expectedOutput, input.Kebaberize());
}
}

class PluralTestSource : IEnumerable<object[]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ namespace Humanizer
public static string Camelize(this string input) { }
public static string Dasherize(this string underscoredWord) { }
public static string Hyphenate(this string underscoredWord) { }
public static string Kebaberize(this string input) { }
public static string Pascalize(this string input) { }
public static string Pluralize(this string word, bool inputIsKnownToBeSingular = True) { }
public static string Singularize(this string word, bool inputIsKnownToBePlural = True) { }
Expand Down
12 changes: 11 additions & 1 deletion src/Humanizer/InflectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static string Underscore(this string input)
{
return Regex.Replace(
Regex.Replace(
Regex.Replace(input, @"([A-Z]+)([A-Z][a-z])", "$1_$2"), @"([a-z\d])([A-Z])", "$1_$2"), @"[-\s]", "_").ToLower();
Regex.Replace(input, @"([\p{Lu}]+)([\p{Lu}][\p{Ll}])", "$1_$2"), @"([\p{Ll}\d])([\p{Lu}])", "$1_$2"), @"[-\s]", "_").ToLower();
}

/// <summary>
Expand All @@ -116,5 +116,15 @@ public static string Hyphenate(this string underscoredWord)
{
return Dasherize(underscoredWord);
}

/// <summary>
/// Separates the input words with hyphens and all the words are converted to lowercase
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static string Kebaberize(this string input)
{
return Underscore(input).Dasherize();
}
}
}

0 comments on commit d3bb686

Please sign in to comment.