Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Kebab Cased and Slug Cased (#13)
Browse files Browse the repository at this point in the history
* Replaced slug-cased name with kebab-cased implementation

* Comment changes

* Updated Docs
  • Loading branch information
ArtSabintsev authored Mar 17, 2017
1 parent f37c079 commit b509428
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 122 deletions.
28 changes: 6 additions & 22 deletions GuitarExample/GuitarExampleTests/GuitarCaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ class GuitarCaseTests: XCTestCase {
}

func testKebabCased() {
XCTAssertEqual("Hello World".kebabCased(), "-hello-world-")
XCTAssertEqual("Hello_World".kebabCased(), "-hello-world-")
XCTAssertEqual("HelloWorld".kebabCased(), "-hello-world-")
XCTAssertEqual("-HeLL0_W0rld-".kebabCased(), "-he-l-l-0-w-0rld-")
XCTAssertEqual("Hello World".kebabCased(), "hello-world")
XCTAssertEqual("Hello_World".kebabCased(), "hello-world")
XCTAssertEqual("HelloWorld".kebabCased(), "hello-world")
}

func testPascalCased() {
Expand All @@ -42,12 +41,6 @@ class GuitarCaseTests: XCTestCase {
XCTAssertEqual("Hell0W0rld".pascalCased(), "Hell0W0rld")
}

func testSlugCased() {
XCTAssertEqual("Hello World".slugCased(), "hello-world")
XCTAssertEqual("Hello_World".slugCased(), "hello-world")
XCTAssertEqual("HelloWorld".slugCased(), "hello-world")
}

func testSnakeCased() {
XCTAssertEqual("Hello World".snakeCased(), "hello_world")
XCTAssertEqual("hello world".snakeCased(), "hello_world")
Expand All @@ -65,30 +58,21 @@ class GuitarCaseTests: XCTestCase {
func testCaseMorphing() {
let string = "Hello World"

XCTAssertEqual(string.camelCased().kebabCased(), "-hello-world-")
XCTAssertEqual(string.camelCased().kebabCased(), "hello-world")
XCTAssertEqual(string.camelCased().pascalCased(), "HelloWorld")
XCTAssertEqual(string.camelCased().slugCased(), "hello-world")
XCTAssertEqual(string.camelCased().snakeCased(), "hello_world")

XCTAssertEqual(string.kebabCased().camelCased(), "helloWorld")
XCTAssertEqual(string.kebabCased().pascalCased(), "HelloWorld")
XCTAssertEqual(string.kebabCased().slugCased(), "hello-world")
XCTAssertEqual(string.kebabCased().snakeCased(), "hello_world")

XCTAssertEqual(string.pascalCased().camelCased(), "helloWorld")
XCTAssertEqual(string.pascalCased().kebabCased(), "-hello-world-")
XCTAssertEqual(string.pascalCased().slugCased(), "hello-world")
XCTAssertEqual(string.pascalCased().kebabCased(), "hello-world")
XCTAssertEqual(string.pascalCased().snakeCased(), "hello_world")

XCTAssertEqual(string.slugCased().camelCased(), "helloWorld")
XCTAssertEqual(string.slugCased().kebabCased(), "-hello-world-")
XCTAssertEqual(string.slugCased().pascalCased(), "HelloWorld")
XCTAssertEqual(string.slugCased().snakeCased(), "hello_world")

XCTAssertEqual(string.snakeCased().camelCased(), "helloWorld")
XCTAssertEqual(string.snakeCased().kebabCased(), "-hello-world-")
XCTAssertEqual(string.snakeCased().kebabCased(), "hello-world")
XCTAssertEqual(string.snakeCased().pascalCased(), "HelloWorld")
XCTAssertEqual(string.snakeCased().slugCased(), "hello-world")
}

}
20 changes: 4 additions & 16 deletions Sources/GuitarCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ public extension String {
return newString
}

/// Returns the kebab cased version of the string.
/// Returns the kebab cased (a.k.a. slug) version of the string.
///
/// let string = "Hello World"
/// print(string.kebabCased())
/// // Prints "-hello-world-"
/// // Prints "hello-world"
///
/// - Returns: The kebab cased copy of the string.
/// - Returns: The kebabg cased copy of the string.
@discardableResult
func kebabCased() -> String {
return "-" + Guitar.sanitze(string: self).splitWordsByCase().slugCased() + "-"
return Guitar.sanitze(string: self).splitWordsByCase().replacingOccurrences(of: " ", with: "-").lowercased()
}

/// Returns a pascal cased version of the string.
Expand All @@ -91,18 +91,6 @@ public extension String {
return Guitar.sanitze(string: self).splitWordsByCase().capitalized().components(separatedBy: .whitespaces).joined()
}

/// Returns the slug cased version of the string.
///
/// let string = "Hello World"
/// print(string.slugCased())
/// // Prints "hello-world"
///
/// - Returns: The slug cased copy of the string.
@discardableResult
func slugCased() -> String {
return Guitar.sanitze(string: self).splitWordsByCase().replacingOccurrences(of: " ", with: "-").lowercased()
}

/// Returns the snake cased version of the string.
///
/// let string = "Hello World"
Expand Down
43 changes: 3 additions & 40 deletions docs/Extensions/String.html
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ <h4>Return Value</h4>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Returns the kebab cased version of the string.</p>
<p>Returns the kebab cased (a.k.a. slug) version of the string.</p>

<pre class="highlight plaintext"><code>let string = "Hello World"
print(string.kebabCased())
// Prints "-hello-world-"
// Prints "hello-world"
</code></pre>

</div>
Expand All @@ -444,7 +444,7 @@ <h4>Declaration</h4>
</div>
<div>
<h4>Return Value</h4>
<p>The kebab cased copy of the string.</p>
<p>The kebabg cased copy of the string.</p>

</div>
</section>
Expand Down Expand Up @@ -487,43 +487,6 @@ <h4>Return Value</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:FE6GuitarSS9slugCasedFT_SS"></a>
<a name="//apple_ref/swift/Method/slugCased()" class="dashAnchor"></a>
<a class="token" href="#/s:FE6GuitarSS9slugCasedFT_SS">slugCased()</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Returns the slug cased version of the string.</p>

<pre class="highlight plaintext"><code>let string = "Hello World"
print(string.slugCased())
// Prints "hello-world"
</code></pre>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">func</span> <span class="nf">slugCased</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">String</span></code></pre>

</div>
</div>
<div>
<h4>Return Value</h4>
<p>The slug cased copy of the string.</p>

</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ <h4>Return Value</h4>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Returns the kebab cased version of the string.</p>
<p>Returns the kebab cased (a.k.a. slug) version of the string.</p>

<pre class="highlight plaintext"><code>let string = "Hello World"
print(string.kebabCased())
// Prints "-hello-world-"
// Prints "hello-world"
</code></pre>

</div>
Expand All @@ -444,7 +444,7 @@ <h4>Declaration</h4>
</div>
<div>
<h4>Return Value</h4>
<p>The kebab cased copy of the string.</p>
<p>The kebabg cased copy of the string.</p>

</div>
</section>
Expand Down Expand Up @@ -487,43 +487,6 @@ <h4>Return Value</h4>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:FE6GuitarSS9slugCasedFT_SS"></a>
<a name="//apple_ref/swift/Method/slugCased()" class="dashAnchor"></a>
<a class="token" href="#/s:FE6GuitarSS9slugCasedFT_SS">slugCased()</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Returns the slug cased version of the string.</p>

<pre class="highlight plaintext"><code>let string = "Hello World"
print(string.slugCased())
// Prints "hello-world"
</code></pre>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">func</span> <span class="nf">slugCased</span><span class="p">()</span> <span class="o">-&gt;</span> <span class="kt">String</span></code></pre>

</div>
</div>
<div>
<h4>Return Value</h4>
<p>The slug cased copy of the string.</p>

</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"warnings": [

],
"source_directory": "/Users/sabintseva/Documents/oss/guitar/GuitarExample"
"source_directory": "/Users/Arthur/Documents/oss/guitar/GuitarExample"
}
Binary file modified docs/docsets/Guitar.docset/Contents/Resources/docSet.dsidx
Binary file not shown.
Binary file modified docs/docsets/Guitar.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/undocumented.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"warnings": [

],
"source_directory": "/Users/sabintseva/Documents/oss/guitar/GuitarExample"
"source_directory": "/Users/Arthur/Documents/oss/guitar/GuitarExample"
}

0 comments on commit b509428

Please sign in to comment.