# postgres-range

> Range data type parser and serializer for PostgreSQL

Latest version **1.1.4** (published 2024-01-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install postgres-range
pnpm add postgres-range
yarn add postgres-range
bun add postgres-range
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2024-01-29 |
| First published | 2021-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | Abbas Mashayekh |
| Maintainers | martianboy |

## Links

- npm: https://www.npmjs.com/package/postgres-range
- Repository: https://github.com/martianboy/postgres-range
- Homepage: https://github.com/martianboy/postgres-range#readme
- Issues: https://github.com/martianboy/postgres-range/issues
- npm.io page: https://npm.io/package/postgres-range

## Recent versions

- 1.1.4 (latest) — 2024-01-29
- 1.1.3 — 2022-08-29
- 1.1.2 — 2022-06-14
- 1.1.1 — 2022-01-01
- 1.1.0 — 2021-12-31
- 1.0.3 — 2021-06-08
- 1.0.2 — 2021-03-24
- 1.0.1 — 2021-03-18
- 1.0.0 — 2021-03-11

## README

# postgres-range [![tests](https://github.com/martianboy/postgres-range/workflows/tests/badge.svg)](https://github.com/martianboy/postgres-range/actions?query=workflow%3Atests)

> Parse postgres range columns


## Install

```
npm install --save postgres-range
```


## Usage

```js
const range = require('postgres-range')

const rng = range.parse('[0,5)', (value) => parseInt(value, 10))
rng.isBounded()
// => true
rng.isLowerBoundClosed()
// => true
rng.isUpperBoundClosed()
// => false
rng.hasLowerBound()
// => true
rng.hasUpperBound()
// => true

rng.containsPoint(4)
// => true
rng.containsRange(range.parse('[1,2]', x => parseInt(x)))
// => true

range.parse('empty').isEmpty()
// => true

range.serialize(new range.Range(0, 5))
// => '(0,5)'
range.serialize(new range.Range(0, 5, range.RANGE_LB_INC | RANGE_UB_INC))
// => '[0,5]'
```

## API

#### `parse(input, [transform])` -> `Range`

##### input

*Required*  
Type: `string`

A Postgres range string.

##### transform

Type: `function`  
Default: `identity`

A function that transforms non-null bounds of the range.


#### `serialize(range, [format])` -> `string`

##### range

*Required*  
Type: `Range`

A `Range` object.

##### format

Type: `function`  
Default: `identity`

A function that formats non-null bounds of the range.


## License

MIT © [Abbas Mashayekh](http://github.com/martianboy)

---
_Source: https://npm.io/package/postgres-range · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
