Node.js implementation of PostgreSQL's format() to safely create dynamic SQL queries. This version 1.0.5 is a minor fix to the archived original pg-format (last version 1.0.4) which contained a bug when the global absolute path is rewritten. It supports escaped SQL identifiers (%I), literals (%L), and simple strings (%s), as well as argument positioning, buffers, arrays, and objects. Useful for building SQL queries safely against SQL injection. Note: the original pg-format is archived and this fork fixes a specific path rewriting bug. Release cadence is low (last update 2022). Differentiator: lightweight, no dependencies, mimics PostgreSQL's format function exactly.
npm install pg-format-fixNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic formatting, array handling, argument positioning, Node.js Buffers, and bulk inserts with nested arrays.
Use pg-format-fix (v1.0.5) or another actively maintained alternative.
Monitor the fork's repository for any changes; consider pinning the version.
Ensure identifiers are always defined strings; use %L or %s for null handling.
Pass only plain objects or use %s for custom serialization.
For single-row inserts, pass a flat array; for multiple rows, use nested arrays as shown in quickstart.
Use default import: import format from 'pg-format' in ESM; or const format = require('pg-format') in CommonJS.Access ident as a property of the default import: format.ident.
Escape literal % as %% in format string, e.g. '100%% complete'.
No dependency data recorded yet.