Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue 611: added the method Kebaberize #617

Merged
merged 2 commits into from
Apr 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
}