This commit is contained in:
@@ -1,10 +1,32 @@
|
||||
/**
|
||||
* Validation schemas - pure functions for consistent input validation.
|
||||
* Validation and sanitization utilities - pure functions for consistent input validation and cleaning.
|
||||
*/
|
||||
|
||||
import { sanitizeString, sanitizeIdentifier, sanitizeLabel } from './sanitize.js'
|
||||
import { MAX_IDENTIFIER_LENGTH, MAX_STRING_LENGTH } from './constants.js'
|
||||
import { DEVICE_TYPES, SOURCE_TYPES } from './deviceUtils.js'
|
||||
import { POI_ICON_TYPES } from './poiConstants.js'
|
||||
|
||||
// Constants
|
||||
export const POI_ICON_TYPES = Object.freeze(['pin', 'flag', 'waypoint'])
|
||||
|
||||
// Sanitization functions
|
||||
const IDENTIFIER_REGEX = /^\w+$/
|
||||
|
||||
export function sanitizeString(str, maxLength = MAX_STRING_LENGTH) {
|
||||
if (typeof str !== 'string') return ''
|
||||
const trimmed = str.trim()
|
||||
return trimmed.length > maxLength ? trimmed.slice(0, maxLength) : trimmed
|
||||
}
|
||||
|
||||
export function sanitizeIdentifier(str) {
|
||||
if (typeof str !== 'string') return ''
|
||||
const trimmed = str.trim()
|
||||
if (trimmed.length === 0 || trimmed.length > MAX_IDENTIFIER_LENGTH) return ''
|
||||
return IDENTIFIER_REGEX.test(trimmed) ? trimmed : ''
|
||||
}
|
||||
|
||||
export function sanitizeLabel(str, maxLength = MAX_STRING_LENGTH) {
|
||||
return sanitizeString(str, maxLength)
|
||||
}
|
||||
|
||||
const ROLES = ['admin', 'leader', 'member']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user