export function stringToInt()

in source/lambda/util/utility-functions.ts [25:45]


export function stringToInt(strToParse: string, minValue?: number): number {
    if (!strToParse || strToParse.trim() === '') {
        throw new Error('A value was not supplied for this string');
    }

    const output = parseInt(strToParse.trim(), 10);

    if (!Number.isInteger(output)) {
        throw new Error('String must be an integer');
    }

    if (strToParse.trim() !== `${output}`) {
        throw new Error(`String was not parsed as expected. An integer value is expected. Value (${strToParse}) was parsed into integer: ${output}`);
    }

    if (minValue !== undefined && output < minValue) {
        throw new Error(`String must be an integer equal to or higher than ${minValue}`);
    }

    return output;
}