TASKS-1823 WebManager module
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import vine from '@vinejs/vine'
|
||||
|
||||
function isValidJsonValue(value: any): boolean {
|
||||
if (value === null) return true
|
||||
if (['string', 'number', 'boolean'].includes(typeof value)) return true
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.every(isValidJsonValue)
|
||||
}
|
||||
|
||||
if (typeof value === 'object' && Object.prototype.toString.call(value) === '[object Object]') {
|
||||
return Object.values(value).every(isValidJsonValue)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
export const anyJsonRule = vine.createRule((value, _options, field) => {
|
||||
if (value === undefined || value === null) {
|
||||
return
|
||||
}
|
||||
|
||||
if (!isValidJsonValue(value)) {
|
||||
field.report('Not valid JSON in {{ field }}', 'anyJson', field)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user