@accounter/server
Version:
Accounter GraphQL server
77 lines (76 loc) • 3.11 kB
TypeScript
/**
* Utility functions for handling monetary amounts in SHAAM uniform format
*/
/**
* Converts a number to SHAAM monetary format string
* Format: [+/-][12 zero-padded digits][2 decimal digits] (total 15 characters)
*
* @param value - The numeric value to convert
* @returns A 15-character string in SHAAM monetary format
*
* @example
* formatMonetaryAmount(12.4) // returns "+00000000001240"
* formatMonetaryAmount(-12.4) // returns "-00000000001240"
* formatMonetaryAmount(0) // returns "+00000000000000"
* formatMonetaryAmount(1234567890.99) // returns "+12345678909900"
*/
export declare function formatMonetaryAmount(value: number): string;
/**
* Parses a SHAAM monetary format string back to a number
*
* @param monetaryString - The 15-character SHAAM monetary format string
* @returns The numeric value
*
* @example
* parseMonetaryAmount("+00000000001240") // returns 12.4
* parseMonetaryAmount("-00000000001240") // returns -12.4
* parseMonetaryAmount("+00000000000000") // returns 0
*/
export declare function parseMonetaryAmount(monetaryString: string): number;
/**
* Converts a number to SHAAM monetary format, allowing empty values
*
* @param value - The numeric value to convert (can be undefined/null)
* @returns A 15-character string in SHAAM monetary format, or empty string if value is undefined/null
*/
export declare function formatOptionalMonetaryAmount(value: number | undefined | null): string;
/**
* Parses a SHAAM monetary format string back to a number, handling empty values
*
* @param monetaryString - The SHAAM monetary format string (can be empty)
* @returns The numeric value, or undefined if the string is empty
*/
export declare function parseOptionalMonetaryAmount(monetaryString: string): number | undefined;
/**
* Converts a number to SHAAM quantity format string
* Format: [+/-][9 zero-padded digits][2 decimal digits] (total 12 characters)
* This is used for quantity fields with format X9(9)V99
*
* @param value - The numeric value to convert
* @returns A 12-character string in SHAAM quantity format
*
* @example
* formatQuantityAmount(12.4) // returns "+00000001240"
* formatQuantityAmount(-12.4) // returns "-00000001240"
* formatQuantityAmount(0) // returns "+00000000000"
*/
export declare function formatQuantityAmount(value: number): string;
/**
* Parses a SHAAM quantity format string back to a number
*
* @param quantityString - The 12-character SHAAM quantity format string
* @returns The numeric value
*
* @example
* parseQuantityAmount("+00000001240") // returns 12.4
* parseQuantityAmount("-00000001240") // returns -12.4
* parseQuantityAmount("+00000000000") // returns 0
*/
export declare function parseQuantityAmount(quantityString: string): number;
/**
* Converts a number to SHAAM quantity format, allowing empty values
*
* @param value - The numeric value to convert (can be undefined/null)
* @returns A 12-character string in SHAAM quantity format, or empty string if value is undefined/null
*/
export declare function formatOptionalQuantityAmount(value: number | undefined | null): string;