metatext/Extensions/URL+Extensions.swift

28 lines
727 B
Swift
Raw Normal View History

2020-09-12 02:50:42 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import Foundation
extension URL {
var isHTTPURL: Bool {
guard let scheme = scheme else { return false }
return scheme == "http" || scheme == "https"
}
2021-02-27 21:29:30 +00:00
init?(stringEscapingPath: String) {
guard let pathEscaped = stringEscapingPath.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)
else { return nil }
let httpsColonUnescaped = pathEscaped.replacingOccurrences(
of: "https%3A",
with: "https:",
range: pathEscaped.range(of: "https%3A"))
self.init(string: httpsColonUnescaped)
}
}
2020-09-12 02:50:42 +00:00
extension URL: Identifiable {
public var id: String { absoluteString }
}