mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-12-18 20:04:17 +01:00
27 lines
766 B
TypeScript
27 lines
766 B
TypeScript
import Joi from "@stirling-tools/joi";
|
|
|
|
export default Joi.extend((joi) => {
|
|
return {
|
|
// e.g. "'1', '2', '3', '10', '100', 'hello'"
|
|
type: 'comma_array',
|
|
base: joi.array(),
|
|
messages: {
|
|
'comma_array.base': '{{#label}} must be a comma seperated list',
|
|
},
|
|
coerce: {
|
|
from: 'string',
|
|
method(value, helpers) {
|
|
|
|
if (typeof value !== 'string' || !/(\d+)(,\s*\d+)*/.test(value)) { // is string and in format "[number], [number]"
|
|
return;
|
|
}
|
|
|
|
try {
|
|
return { value: value.split(",").map(v => v.trim()) };
|
|
}
|
|
catch (ignoreErr) { }
|
|
}
|
|
}
|
|
|
|
}
|
|
}); |