Skip to content

docs: add JSDoc documentation to utility functions #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/src/utils/jsonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,22 @@ export type DataType =
| "array"
| "null";

/**
* Determines the specific data type of a JSON value
* @param value The JSON value to analyze
* @returns The specific data type including "array" and "null" as distinct types
*/
export function getDataType(value: JsonValue): DataType {
if (Array.isArray(value)) return "array";
if (value === null) return "null";
return typeof value;
}

/**
* Attempts to parse a string as JSON, only for objects and arrays
* @param str The string to parse
* @returns Object with success boolean and either parsed data or original string
*/
export function tryParseJson(str: string): {
success: boolean;
data: JsonValue;
Expand Down
10 changes: 10 additions & 0 deletions client/src/utils/oauthUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type CallbackParams =
error_uri: string | null;
};

/**
* Parses OAuth 2.1 callback parameters from a URL search string
* @param location The URL search string (e.g., "?code=abc123" or "?error=access_denied")
* @returns Parsed callback parameters with success/error information
*/
export const parseOAuthCallbackParams = (location: string): CallbackParams => {
const params = new URLSearchParams(location);

Expand Down Expand Up @@ -62,6 +67,11 @@ export const generateOAuthState = () => {
);
};

/**
* Generates a human-readable error description from OAuth callback error parameters
* @param params OAuth error callback parameters containing error details
* @returns Formatted multiline error message with error code, description, and optional URI
*/
export const generateOAuthErrorDescription = (
params: Extract<CallbackParams, { successful: false }>,
): string => {
Expand Down