@storyous/common-utils
Advanced tools
Comparing version 1.2.5 to 1.2.6
@@ -453,2 +453,35 @@ 'use strict'; | ||
} | ||
}, | ||
/** | ||
* | ||
* @param {*} value | ||
* @param {string} fieldName | ||
* @param {*|null} [defaultValue] | ||
* @returns {Array|null} Or `defaultValue` | ||
*/ | ||
commaList (value, fieldName, defaultValue) { | ||
if (typeof value === 'string') { | ||
// split the string | ||
value = value.split(','); | ||
} | ||
if (typeof value === 'object' && value instanceof Array) { | ||
value = value.map(el => (el.replace(/[^a-z0-9_-]+/ig, ''))); | ||
} else if (value) { | ||
throw AppError.badRequest(`Bad field list: ${fieldName}`); | ||
} else { | ||
if (typeof defaultValue === 'undefined') { | ||
defaultValue = null; | ||
} | ||
value = defaultValue; | ||
} | ||
return value; | ||
} | ||
@@ -455,0 +488,0 @@ }; |
{ | ||
"name": "@storyous/common-utils", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"description": "Common utils for storyous microservices", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
47408
1485