Skip to content

Commit

Permalink
refactor: use switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
kkebo committed Dec 2, 2024
1 parent 5c8fa70 commit cb303b4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 45 deletions.
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

0 comments on commit cb303b4

Please sign in to comment.