Registry / database / postgres-array

postgres-array

JSON →
library3.0.4jsnpmunverified

Parse PostgreSQL array column strings into JavaScript arrays. Current stable version is 3.0.4 (Node >=12). Released infrequently; latest version focused on ESM modernization. Key differentiator: minimal dependency, lightweight parser with optional transform function for type coercion. Alternative to manual parsing or using full pg driver within specific contexts.

npm install postgres-array
INSTALL
IMPORT
SIG · POSTGRES-ARRAY
P
postgres-array
databasejavascriptv3.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'postgres-array'
const postgresArray = require('postgres-array')
ESM-only since v3; named export. The default export was removed.
parse
const { parse } = require('postgres-array')
const parse = require('postgres-array').parse
CommonJS require is available for Node <12 or legacy projects, but v3 encourages ESM.
Type (e.g., ParseFunction)
import type { ParseFunction } from 'postgres-array'
import { ParseFunction } from 'postgres-array'
TypeScript types are included; use type-only import for types.
parse
import { parse } from 'postgres-array'
import { default } from 'postgres-array'
No default export in v3.

Parse a PostgreSQL array string with a transform function to convert string values to numbers.

import { parse } from 'postgres-array'; const result = parse('{1,2,3}', (value) => parseInt(value, 10)); console.log(result); // [1, 2, 3]
Debug
Known issues
breakingv3 removed CommonJS default export; CJS users must switch to named destructuring.
fix
Change `const postgresArray = require('postgres-array')` to `const { parse } = require('postgres-array')`.
affects: >=3.0.0
gotchaTransform function is called for every non-null element; nulls are preserved as `null`.
fix
To handle nulls differently, check the value inside the transform and return your desired default.
affects: >=0.0.0
gotchaInput must be a properly formatted PostgreSQL array string; invalid input may cause unexpected behavior.
fix
Ensure the input string starts with '{' and ends with '}'. For nested arrays, see the parser's limitations.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: postgresArray.parse is not a function
Using CommonJS default import instead of named import.
fix
Use `const { parse } = require('postgres-array')`
SyntaxError: Unexpected token 'export'
Using CommonJS `require` on an ESM-only package (v3+).
fix
Either use ESM (`import`) or upgrade to Node >=12 and use `import`.
Upgrade
Version history
3.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
postgres-array — npm install postgres-array · libregistry