Registry / database / pg-parse-float

pg-parse-float

JSON →
library0.0.1jsnpmunverified

Small utility to restore JavaScript parseFloat behavior to node-postgres (pg), converting float4, float8, and numeric columns to JavaScript floats. Version 0.0.1 is stable, with no active development. It serves as a reference for building custom type parsers. Differentiates itself as a minimal, dependency-free patch for node-postgres users who want floats instead of strings for numeric types.

npm install pg-parse-float
INSTALL
IMPORT
SIG · PG-PARSE-FLOAT
P
pg-parse-float
databasejavascriptv0.0.1
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.

pgParseFloat
const pgParseFloat = require('pg-parse-float'); pgParseFloat(pg);
import pgParseFloat from 'pg-parse-float';
The library is CommonJS only and should be called as a function with the pg module as argument.

Shows how to require and invoke pg-parse-float to patch node-postgres, then query a float column and receive a JavaScript number.

const pg = require('pg'); const pgParseFloat = require('pg-parse-float'); pgParseFloat(pg); const client = new pg.Client({ host: 'localhost', database: 'test' }); client.connect(); client.query('SELECT 1.5::float4 AS f', (err, result) => { if (err) throw err; console.log(result.rows[0].f); // 1.5 (number) client.end(); });
Debug
Known issues
gotchaMust pass the same pg module instance that you use for queries. If you require pg separately inside other modules, those will not be patched.
fix
Ensure pg is required once and pgParseFloat(pg) is called before creating any clients.
affects: *
gotchaThis overrides the default parser for float4, float8, and numeric types. If you rely on string representations (e.g., for precise numeric handling), floats may lose precision.
fix
Do not use this library if you need exact numeric representation; use a library like pg-types or handle parsing manually.
affects: *
deprecatedThe package has not been updated since 2014 and is not compatible with modern node-postgres versions that use ES modules or TypeScript.
fix
Consider using native node-postgres type parsers or write your own conversion using pg-types.
affects: >=0.0.1
Errors
Common errors & fixes
require('pg-parse-float')(pg) does nothing
The pg module is called before being passed to the function, or a different instance is used.
fix
Ensure you require pg-parse-float and pass the pg reference correctly: const pg = require('pg'); require('pg-parse-float')(pg);
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
pg-parse-float — npm install pg-parse-float · libregistry