This library provides parsing and serialization capabilities for PostgreSQL's native range data types. It allows developers to convert PostgreSQL range strings (e.g., `[0,5)`) into a rich `Range` object with methods for querying properties like boundedness and inclusivity, and for performing operations such as point and range containment checks. The current stable version is 1.1.4. Releases appear to be driven by feature additions and bug fixes rather than a strict time-based cadence, as indicated by the recent v1.1.4 update addressing type definitions and adding a `toPostgres` method. Its key differentiator is its focused utility on PostgreSQL's specific range string format, providing a dedicated `Range` object API rather than a general-purpose interval library.
npm install postgres-rangeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing various PostgreSQL range strings, checking their properties and contents, and serializing a `Range` object back into a string, including custom boundary types.
Always provide a `transform` function to `parse()` that converts the bound values to the desired type, e.g., `(value) => parseInt(value, 10)` or `(value) => new Date(value)`.
When creating a `Range` object manually with `new Range(lower, upper, flags)`, ensure `flags` are set correctly using `RANGE_LB_INC` and `RANGE_UB_INC` bitmasks if you intend for `serialize` to produce the expected output.
Update to `postgres-range@1.1.4` or newer to get accurate and complete TypeScript definitions, especially if using the `toPostgres` method or relying on method return types for type safety.
Ensure the input to `parse` is a string and provide a `transform` function: `parse('[1,5]', (value) => parseInt(value, 10))`.Ensure the range object is created using `parse()` or `new Range()` from the `postgres-range` library before calling its methods.
For CommonJS environments, use `const { parse } = require('postgres-range');`. For ES module environments, ensure your `package.json` has `"type": "module"` and use `import { parse } from 'postgres-range';`.No dependency data recorded yet.