postgres-array
Advanced tools
Comparing version
29
index.js
@@ -23,2 +23,10 @@ 'use strict' | ||
return function parseArray (str) { | ||
const rbraceIndex = str.length - 1 | ||
if (rbraceIndex === 1) { | ||
return [] | ||
} | ||
if (str[rbraceIndex] !== RBRACE) { | ||
throw new Error('Invalid array text - must end with }') | ||
} | ||
// If starts with `[`, it is specifying the index boundas. Skip past first `=`. | ||
@@ -33,6 +41,2 @@ let position = 0 | ||
} | ||
const rbraceIndex = str.length - 1 | ||
if (str[rbraceIndex] !== RBRACE) { | ||
throw new Error('Invalid array text - must end with }') | ||
} | ||
const output = [] | ||
@@ -43,4 +47,3 @@ let current = output | ||
let currentStringStart = position | ||
const currentStringParts = [] | ||
let hasStringParts = false | ||
let currentString = '' | ||
let expectValue = true | ||
@@ -62,4 +65,3 @@ | ||
const part = str.slice(currentStringStart, position) | ||
currentStringParts.push(part) | ||
hasStringParts = true | ||
currentString += part | ||
currentStringStart = ++position | ||
@@ -75,10 +77,5 @@ if (dquot === position++) { | ||
const part = str.slice(currentStringStart, position) | ||
if (hasStringParts) { | ||
const final = currentStringParts.join('') + part | ||
current.push(haveTransform ? transform(final) : final) | ||
currentStringParts.length = 0 | ||
hasStringParts = false | ||
} else { | ||
current.push(haveTransform ? transform(part) : part) | ||
} | ||
currentString += part | ||
current.push(haveTransform ? transform(currentString) : currentString) | ||
currentString = '' | ||
expectValue = false | ||
@@ -85,0 +82,0 @@ } else if (char === LBRACE) { |
{ | ||
"name": "postgres-array", | ||
"main": "index.js", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Parse postgres array columns", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
6425
-3.12%113
-3.42%