Profile Answers State Utility (lib/profile-answers.ts)

rekey · apps/panel/src/lib/profile-answers.ts · typescript · MIT
database, ui, lang:typescript, tag:profile, tag:validation

Frontend helper functions to read and validate end-user profile form answers and options. Reuse when building user settings or profile management panels.

// Source: https://github.com/rekey-dev/rekey | License: MIT | Copyright 2026 Rekey
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Reading and editing one end user's profile answers in the panel.
 */

import type { ProfileField } from '@rekey.dev/shared-types';

type Answers = Record<string, string | number | boolean>;

/**
 * Whether the user answered `key`. An own property only: `{}` has a
 * `constructor` through its prototype, and that is not an answer.
 */
export function isAnswered(answers: Answers | undefined, key: string): boolean {
  return answers !== undefined && Object.hasOwn(answers, key);
}

/** A select answer that is not among the field's options any more. */
export function isRetiredOption(field: ProfileField, value: string | number | boolean | und

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key