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

refactor: use switch expressions #74

Merged
merged 1 commit into from
Dec 3, 2024
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
4 changes: 2 additions & 2 deletions Sources/Models/Converters/JSONYAMLConversionMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ extension JSONYAMLConversionMode: CaseIterable {}
extension JSONYAMLConversionMode: CustomStringConvertible {
var description: String {
switch self {
case .yamlToJSON: return "YAML to JSON"
case .jsonToYAML: return "JSON to YAML"
case .yamlToJSON: "YAML to JSON"
case .jsonToYAML: "JSON to YAML"
}
}
}
24 changes: 12 additions & 12 deletions Sources/Models/Converters/NumberType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ enum NumberType: String {

var radix: Int {
switch self {
case .hexadecimal: return 16
case .decimal: return 10
case .octal: return 8
case .binary: return 2
case .hexadecimal: 16
case .decimal: 10
case .octal: 8
case .binary: 2
}
}

var digitsInGroup: Int {
switch self {
case .hexadecimal: return 4
case .decimal: return 3
case .octal: return 3
case .binary: return 4
case .hexadecimal: 4
case .decimal: 3
case .octal: 3
case .binary: 4
}
}

var separator: String {
switch self {
case .hexadecimal: return " "
case .decimal: return ","
case .octal: return " "
case .binary: return " "
case .hexadecimal: " "
case .decimal: ","
case .octal: " "
case .binary: " "
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions Sources/Models/Formatters/JSONFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ struct JSONFormatter {

func format(_ input: String) -> String {
switch self.indentation {
case .twoSpaces:
return SwiftJSONFormatter.beautify(input, indent: " ")
case .fourSpaces:
return SwiftJSONFormatter.beautify(input, indent: " ")
case .oneTab:
return SwiftJSONFormatter.beautify(input, indent: "\t")
case .minified:
return SwiftJSONFormatter.minify(input)
case .twoSpaces: SwiftJSONFormatter.beautify(input, indent: " ")
case .fourSpaces: SwiftJSONFormatter.beautify(input, indent: " ")
case .oneTab: SwiftJSONFormatter.beautify(input, indent: "\t")
case .minified: SwiftJSONFormatter.minify(input)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Models/Formatters/JSONIndentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ enum JSONIndentation {
extension JSONIndentation: CustomStringConvertible {
var description: String {
switch self {
case .twoSpaces: return "2 spaces"
case .fourSpaces: return "4 spaces"
case .oneTab: return "1 tab"
case .minified: return "Minified"
case .twoSpaces: "2 spaces"
case .fourSpaces: "4 spaces"
case .oneTab: "1 tab"
case .minified: "Minified"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Models/Generators/UUIDVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ enum UUIDVersion {
extension UUIDVersion: CustomStringConvertible {
var description: String {
switch self {
case .v1: return "1"
case .v4: return "4 (GUID)"
case .v1: "1"
case .v4: "4 (GUID)"
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Pages/Converters/NumberBaseConverterViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ final class NumberBaseConverterViewState {

var input: String {
switch self.inputType {
case .hexadecimal: return self.hexadecimal
case .decimal: return self.decimal
case .octal: return self.octal
case .binary: return self.binary
case .hexadecimal: self.hexadecimal
case .decimal: self.decimal
case .octal: self.octal
case .binary: self.binary
}
}

Expand Down
26 changes: 13 additions & 13 deletions Sources/Tool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,79 +58,79 @@ enum Tool: String {
var strings: Strings {
switch self {
case .allTools:
return .init(
.init(
shortTitle: "All tools",
longTitle: "All tools",
description: ""
)
case .base64Coder:
return .init(
.init(
shortTitle: "Base 64",
longTitle: "Base 64 Encoder / Decoder",
description: "Encode and decode Base64 data"
)
case .hashGenerator:
return .init(
.init(
shortTitle: "Hash",
longTitle: "Hash Generator",
description: "Calculate MD5, SHA1, SHA256 and SHA512 hash from text data"
)
case .htmlCoder:
return .init(
.init(
shortTitle: "HTML",
longTitle: "HTML Encoder / Decoder",
description: "Encode or decode all the applicable characters to their corresponding HTML entities"
)
case .jsonFormatter:
return .init(
.init(
shortTitle: "JSON",
longTitle: "JSON Formatter",
description: "Indent or minify JSON data"
)
case .jsonYAMLConverter:
return .init(
.init(
shortTitle: "JSON <> YAML",
longTitle: "JSON <> YAML Converter",
description: "Convert JSON data to YAML and vice versa"
)
case .jwtDecoder:
return .init(
.init(
shortTitle: "JWT Decoder",
longTitle: "JWT Decoder",
description: "Decode a JWT header, payload and signature"
)
case .loremIpsumGenerator:
return .init(
.init(
shortTitle: "Lorem Ipsum",
longTitle: "Lorem Ipsum Generator",
description: "Generate Lorem Ipsum placeholder text"
)
case .markdownPreview:
return .init(
.init(
shortTitle: "Markdown Preview",
longTitle: "Markdown Preview",
description: "Preview a Markdown document"
)
case .numberBaseConverter:
return .init(
.init(
shortTitle: "Number Base",
longTitle: "Number Base Converter",
description: "Convert numbers from one base to another"
)
case .timestampConverter:
return .init(
.init(
shortTitle: "Timestamp",
longTitle: "Unix Timestamp Converter",
description: "Convert timestamp to human-readable date and vice versa"
)
case .urlCoder:
return .init(
.init(
shortTitle: "URL",
longTitle: "URL Encoder / Decoder",
description: "Encode or decode all the applicable characters to their corresponding URL entities"
)
case .uuidGenerator:
return .init(
.init(
shortTitle: "UUID",
longTitle: "UUID Generator",
description: "Generate UUIDs version 1 and 4"
Expand Down