Skip to content

Commit

Permalink
feat: Improved the slugified function
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinrenskers committed Mar 23, 2023
1 parent c3af5a6 commit 6c14128
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/Saga/String+Slugify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public extension CustomStringConvertible {
/// Returns a slugified version of the `String`: only letters, numbers, dash and underscore are allowed; everything else is replaced with a dash. The returned string is lowercased.
var slugified: String {
return self.description
.replacingOccurrences(of: " - ", with: "-")
.components(separatedBy: allowedCharacters.inverted)
.filter { $0 != "" }
.joined(separator: "-")
Expand Down
1 change: 1 addition & 0 deletions Tests/SagaTests/SagaTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ final class SagaTests: XCTestCase {

func testSlugified() throws {
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")
Expand Down

0 comments on commit 6c14128

Please sign in to comment.