function sanitizeString(value) {
    if (typeof value !== 'string') return ''
    return value.replace(/[<>\\]/g, '').replace(/^\s+|\s+$/g, '')
}

function sanitizePayload(payload) {
    const source = payload || {}
    const result = {}

    for (const key in source) {
        if (!Object.prototype.hasOwnProperty.call(source, key)) continue
        result[key] = typeof source[key] === 'string' ? sanitizeString(source[key]) : source[key]
    }

    return result
}

module.exports = {
    sanitizeString,
    sanitizePayload,
}
