Merge pull request #697 from Raghuboi/docs/utils-jsdoc
docs: add JSDoc documentation to utility functions
This commit is contained in:
commit
7a32c3db92
2 changed files with 20 additions and 0 deletions
|
|
@ -63,12 +63,22 @@ export type DataType =
|
||||||
| "array"
|
| "array"
|
||||||
| "null";
|
| "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 {
|
export function getDataType(value: JsonValue): DataType {
|
||||||
if (Array.isArray(value)) return "array";
|
if (Array.isArray(value)) return "array";
|
||||||
if (value === null) return "null";
|
if (value === null) return "null";
|
||||||
return typeof value;
|
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): {
|
export function tryParseJson(str: string): {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data: JsonValue;
|
data: JsonValue;
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ type CallbackParams =
|
||||||
error_uri: string | null;
|
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 => {
|
export const parseOAuthCallbackParams = (location: string): CallbackParams => {
|
||||||
const params = new URLSearchParams(location);
|
const params = new URLSearchParams(location);
|
||||||
|
|
||||||
|
|
@ -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 = (
|
export const generateOAuthErrorDescription = (
|
||||||
params: Extract<CallbackParams, { successful: false }>,
|
params: Extract<CallbackParams, { successful: false }>,
|
||||||
): string => {
|
): string => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue