<commit_before>import Foundation
import UIKit

/// A class that provides colors to the formatter in TextKit.
/// By default only the standard html colors are provided, but new color can be added by using the `add(namedColors:)` method.
public class ColorProvider {


    private init() {

    }

    public static var shared = ColorProvider()

    private lazy var htmlColors: [String: UIColor] = {
        guard let colorDataURL = Bundle.aztecBundle.url(forResource: "html_colors", withExtension: "json"),
            let data = try? Data(contentsOf: colorDataURL),
            let object = try? JSONSerialization.jsonObject(with: data, options: .allowFragments),
            let colorDict = object as? [String: String] else {
                return [String:UIColor]()
        }

        return colorDict.compactMapValues { (value) -> UIColor? in
            return UIColor.init(hexString: value)
        }
    }()

    private var extraColors = [String:UIColor]()

    /// Adds extra named colors to be used by the `color(named:)` method.
    ///  If the there is a name collision the value on the added dictionary will overwrite the current color.
    /// - Parameter namedColors: a dictionary of colors keyed by name
    public func add(namedColors: [String: UIColor]) {
        extraColors.merge(namedColors) { (base, other) -> UIColor in
            return other
        }
    }

    /// Returns a color designated by name if available.
    ///  By default the the color available are the one defined in the HTML specification: https://www.w3schools.com/colors/colors_names.asp
    /// - Parameter name: the name of the color, or nil if the name is not available
    public func color(named name: String) -> UIColor? {
        if let color = htmlColors[name] {
            return color
        }

        return extraColors[name]
    }

    public lazy var codeBackgroungColor: UIColor = {
        if #available(iOS 13.0, *) {
            return UIColor.secondarySystemBackground
        } else {
            return UIColor.lightGray
        }
    }()
}<commit_msg>Lowecase the name passed to make it more flexible.<commit_after>import Foundation
import UIKit

/// A class that provides colors to the formatter in TextKit.
/// By default only the standard html colors are provided, but new color can be added by using the `add(namedColors:)` method.
public class ColorProvider {


    private init() {

    }

    public static var shared = ColorProvider()

    private lazy var htmlColors: [String: UIColor] = {
        guard let colorDataURL = Bundle.aztecBundle.url(forResource: "html_colors", withExtension: "json"),
            let data = try? Data(contentsOf: colorDataURL),
            let object = try? JSONSerialization.jsonObject(with: data, options: .allowFragments),
            let colorDict = object as? [String: String] else {
                return [String:UIColor]()
        }

        return colorDict.compactMapValues { (value) -> UIColor? in
            return UIColor.init(hexString: value)
        }
    }()

    private var extraColors = [String:UIColor]()

    /// Adds extra named colors to be used by the `color(named:)` method.
    ///  If the there is a name collision the value on the added dictionary will overwrite the current color.
    /// - Parameter namedColors: a dictionary of colors keyed by name
    public func add(namedColors: [String: UIColor]) {
        extraColors.merge(namedColors) { (base, other) -> UIColor in
            return other
        }
    }

    /// Returns a color designated by name if available.
    ///  By default the the color available are the one defined in the HTML specification: https://www.w3schools.com/colors/colors_names.asp
    /// - Parameter name: the name of the color, or nil if the name is not available
    public func color(named name: String) -> UIColor? {
        if let color = htmlColors[name.lowercased()] {
            return color
        }

        return extraColors[name]
    }

    public lazy var codeBackgroungColor: UIColor = {
        if #available(iOS 13.0, *) {
            return UIColor.secondarySystemBackground
        } else {
            return UIColor.lightGray
        }
    }()
}
{'fraction_non_alphanumeric': 0.0892175572519084, 'fraction_numerical': 0.0019083969465648854, 'mean_word_length': 2.485453034081463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6332441', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1120, 'n_words': 418}