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

Function arraySerializer

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

Source from the content-addressed store, hash-verified

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

Callers 1

addArrayTypeFunction · 0.90

Calls 1

arrayEscapeFunction · 0.70

Tested by

no test coverage detected