Mari's guided journal software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
mari-guided-journal/src/datatypes/GuidedEmpathy.ts

51 lines
2.4 KiB

import {isPopulatedArray} from "../utils/Arrays.js";
import {
Persona,
personaName,
personaPronoun,
personaPronounObject,
personaPronounPossessive,
personaVerb
} from "./Persona.js";
import chalk from "chalk";
import capitalize from "capitalize";
import {
ArraySerializer,
ObjectSerializer,
OptionalArrayStringSerializer,
OptionalSerializer
} from "../schemata/Serialization.js";
export interface GuidedEmpathy {
readonly feelings?: readonly string[]
readonly needs?: readonly string[]
readonly events?: readonly string[]
readonly requests?: readonly string[]
}
export const GuidedEmpathySerializer = new ObjectSerializer<GuidedEmpathy, GuidedEmpathy, keyof GuidedEmpathy>({
feelings: OptionalArrayStringSerializer,
needs: OptionalArrayStringSerializer,
events: OptionalArrayStringSerializer,
requests: OptionalArrayStringSerializer,
}, ["feelings", "needs", "events", "requests"])
export const ArrayGuidedEmpathySerializer = new ArraySerializer(GuidedEmpathySerializer)
export const OptionalArrayGuidedEmpathySerializer = new OptionalSerializer(ArrayGuidedEmpathySerializer)
export function isPopulatedGuidedEmpathy(empathy: GuidedEmpathy | undefined): boolean {
return !!empathy && (isPopulatedArray(empathy.feelings)
|| isPopulatedArray(empathy.needs)
|| isPopulatedArray(empathy.events)
|| isPopulatedArray(empathy.requests))
}
export function guidedEmpathyToString(empathy: GuidedEmpathy, persona: Persona | undefined): string {
return (`${(capitalize(personaName(persona), true))} ${personaVerb(persona, "feel", "feels")}: ${empathy.feelings?.join(", ") || chalk.dim("(???)")}...\n`
+ `Because ${personaPronoun(persona)} ${personaVerb(persona, "need", "needs")}: ${empathy.needs?.join(", ") || chalk.dim("(???)")}...\n`
+ `And ${personaPronounPossessive(persona)} needs were affected when: ${empathy.events?.join("; ") || chalk.dim("(???)")}...\n`
+ `So to get good outcomes for ${personaPronounObject(persona)} in the future, can we try: ${empathy.requests?.join("; ") || chalk.dim("(???)")}?`)
}
export function guidedEmpathyToStringShort(empathy: GuidedEmpathy): string {
return `Feeling ${empathy.feelings?.join(", ") || chalk.dim("(none)")} // Because ${empathy.needs?.join(", ") || chalk.dim("(none)")} // When ${empathy.events?.join("; ") || chalk.dim("(none)")} // So ${empathy.requests?.join("; ") || chalk.dim("(none)")}`
}