MCPcopy Create free account
hub / github.com/porsager/postgres / arraySerializer

Function arraySerializer

cf/src/types.js:242–267  ·  view source on GitHub ↗
(xs, serializer, options, typarray)

Source from the content-addressed store, hash-verified

240}
241
242export const arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
243 if (Array.isArray(xs) === false)
244 return xs
245
246 if (!xs.length)
247 return '{}'
248
249 const first = xs[0]
250 // Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
251 const delimiter = typarray === 1020 ? ';' : ','
252
253 if (Array.isArray(first) && !first.type)
254 return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}'
255
256 return '{' + xs.map(x => {
257 if (x === undefined) {
258 x = options.transform.undefined
259 if (x === undefined)
260 throw Errors.generic('UNDEFINED_VALUE', 'Undefined values are not allowed')
261 }
262
263 return x === null
264 ? 'null'
265 : '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"'
266 }).join(delimiter) + '}'
267}
268
269const arrayParserState = {
270 i: 0,

Callers 3

addArrayTypeFunction · 0.90
types.jsFile · 0.50
addArrayTypeFunction · 0.50

Calls 1

arrayEscapeFunction · 0.70

Tested by

no test coverage detected