A Node.js implementation of PostgreSQL's format() function for safely creating dynamic SQL queries. Version 1.0.4, stable and minimal, with no dependencies. It escapes SQL identifiers (%I), literals (%L), and simple strings (%s) to help prevent SQL injection. Supports Node buffers, arrays, and objects, including nested arrays for bulk inserts. Unlike other SQL escaping libraries, it mimics PostgreSQL's built-in format() exactly, making it ideal for building queries in Node.js that mirror PL/pgSQL logic. Released under MIT license, maintained on GitHub.
npm install pg-formatNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to safely build a SELECT query with identifier, literal, and string placeholders.
Use %L or %s for arrays/objects, or iterate manually.
Call format.config() with no arguments to restore defaults, or use a fresh require if isolation is needed.
Use a dynamic import() with createRequire or switch to an ESM-compatible alternative like 'pg-escape'.
Check for null/undefined before passing to %I, or use %L or %s accordingly.
Use CommonJS require: `const format = require('pg-format')`Use %L or %s for arrays/objects, or convert to string first.
Ensure only supported types are passed; convert complex types to string beforehand.
No dependency data recorded yet.