From 6c14128fa454a5a3fc84d4512ea50863b5a3e993 Mon Sep 17 00:00:00 2001 From: Kevin Renskers Date: Thu, 23 Mar 2023 13:59:04 +0100 Subject: [PATCH] feat: Improved the slugified function --- Sources/Saga/String+Slugify.swift | 1 + Tests/SagaTests/SagaTests.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/Saga/String+Slugify.swift b/Sources/Saga/String+Slugify.swift index e45403c..044a6c9 100644 --- a/Sources/Saga/String+Slugify.swift +++ b/Sources/Saga/String+Slugify.swift @@ -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: "-") diff --git a/Tests/SagaTests/SagaTests.swift b/Tests/SagaTests/SagaTests.swift index 9a15296..a0258a6 100644 --- a/Tests/SagaTests/SagaTests.swift +++ b/Tests/SagaTests/SagaTests.swift @@ -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")