splitwise
Version:
A TypeScript SDK for the Splitwise API.
53 lines • 2.27 kB
TypeScript
/**
* Parameter conversion utilities for the Splitwise API.
*
* The SDK accepts camelCase params (idiomatic JS) and converts them to the
* snake_case + double-underscore-flattened format the Splitwise API expects.
*/
/**
* Converts a camelCase or PascalCase string to snake_case.
* Already-snake_case strings pass through unchanged.
*/
export declare function toSnakeCase(str: string): string;
/**
* Converts a snake_case string to camelCase.
* Already-camelCase strings pass through unchanged.
*/
export declare function toCamelCase(str: string): string;
/**
* Recursively converts all object keys from camelCase to snake_case.
* Plain objects and arrays are walked; everything else (primitives,
* Date, Blob, URL, Map, Set, custom classes, etc.) passes through
* untouched so the caller / JSON.stringify can handle them.
*/
export declare function keysToSnakeCase(obj: unknown): unknown;
/**
* Recursively converts all object keys from snake_case to camelCase.
* Plain objects and arrays are walked; everything else passes through.
*/
export declare function keysToCamelCase(obj: unknown): unknown;
/**
* Result entry from flattening — most values become a primitive plus their
* key. Blobs are kept as-is because they need to ride a multipart payload
* (the caller is responsible for building the FormData).
*/
export type FlatValue = string | number | boolean | Blob;
/**
* Flattens nested objects/arrays into Splitwise's double-underscore notation
* and converts booleans to 0/1 integers. All keys are converted to snake_case.
*
* Notable conversions:
* - Date → ISO string (otherwise Date has no enumerable own properties and
* would silently disappear)
* - Blob/File → preserved as-is so multipart construction can pick them up
* (the caller must check for Blob values before form-urlencoding)
* - URL → string form
* - Anything else non-plain-object that has a sensible `toString()` is
* stringified rather than silently dropped
*
* Example:
* { users: [{ userId: 1, paidShare: "10" }] }
* → { "users__0__user_id": 1, "users__0__paid_share": "10" }
*/
export declare function flattenParams(obj: Record<string, unknown>): Record<string, FlatValue>;
//# sourceMappingURL=params.d.ts.map