Cotton code
75 lines · 2.4 KB · SwiftRaw
// GENERATED by `cotton-gen` from `cotton-core — rules/emotions.rs` — do not edit by hand.// Run `pnpm gen:design`; `gen:design:check` guards drift in CI.//// The emotion vocabulary — 31 words, alphabetical.//// Read from `crates/cotton-core/src/rules/emotions.rs`, which is where a word// is declared; a word is NEVER added here.//// A mood is a MOMENT: what the person said about how they are going, and the// emotions named in it. The slug IS the display word, so a chip, a filter and a// tool all say the same string and nothing has to map between a key and a// label.//// The order is alphabetical on purpose. A list running from bad to good would// rebuild the 1-to-5 scale this vocabulary replaced, and `awful`, `low`,// `okay`, `good` and `great` are in it only because the five faces the app used// to draw had exactly those words — migration 18 converts an old score into one// of them.//// English-only, by decision ([english-only-no-translations]): there is no// catalogue lookup here and there is not going to be one.import Foundationpublic enum Emotions {    /// Every emotion a moment may name, alphabetical.    public static let all: [String] = [        "afraid",        "angry",        "anxious",        "ashamed",        "awful",        "bored",        "calm",        "content",        "energised",        "excited",        "focused",        "frustrated",        "good",        "grateful",        "great",        "guilty",        "happy",        "hopeful",        "hurt",        "lonely",        "loved",        "low",        "numb",        "okay",        "overwhelmed",        "proud",        "relieved",        "restless",        "sad",        "stressed",        "tired",    ]    /// Is this exactly one of the declared words? Exact, like the Rust half:    /// a chip that matched loosely would highlight a word the server will    /// refuse.    public static func isEmotion(_ word: String) -> Bool {        all.contains(word)    }    /// The declared word a caller meant, or nil — trimmed and lowercased,    /// because a word typed into the composer and a chip tapped beside it    /// arrive differently and mean the same thing.    public static func normalise(_ word: String) -> String? {        let wanted = word.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()        return all.first { $0 == wanted }    }}