Skip to content

Commit

Permalink
fix: the slugify function got fixed so it doesn't remove dashes anymo…
Browse files Browse the repository at this point in the history
…re, closes #14
  • Loading branch information
kevinrenskers committed Aug 17, 2021
1 parent d5f7e45 commit 1114647
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Example/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"object": {
"pins": [
{
"package": "cmark-gfm",
"package": "cmark",
"repositoryURL": "https://github.com/brokenhandsio/cmark-gfm.git",
"state": {
"branch": null,
Expand Down Expand Up @@ -65,7 +65,7 @@
}
},
{
"package": "Swim",
"package": "HTML",
"repositoryURL": "https://github.com/robb/Swim",
"state": {
"branch": null,
Expand Down
8 changes: 5 additions & 3 deletions Sources/Saga/String+Slugify.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Foundation

private let allowedCharacters = CharacterSet(charactersIn: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_")

public extension CustomStringConvertible {
var slugified: String {
return self.description
.components(separatedBy: CharacterSet.alphanumerics.union(.whitespaces).inverted)
.joined(separator: "")
.replacingOccurrences(of: " ", with: "-")
.components(separatedBy: allowedCharacters.inverted)
.filter { $0 != "" }
.joined(separator: "-")
.lowercased()
}
}
3 changes: 3 additions & 0 deletions Tests/SagaTests/SagaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ final class SagaTests: XCTestCase {
XCTAssertEqual("one two".slugified, "one-two")
XCTAssertEqual("One Two".slugified, "one-two")
XCTAssertEqual("One! .Two@".slugified, "one-two")
XCTAssertEqual("one-two".slugified, "one-two")
XCTAssertEqual("one_two".slugified, "one_two")
XCTAssertEqual("ONE-TWO".slugified, "one-two")
}

static var allTests = [
Expand Down

0 comments on commit 1114647

Please sign in to comment.