# stable-position

> Generate unique position that can be used to order items without renumbering them.

Latest version **2.0.1** (published 2026-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install stable-position
pnpm add stable-position
yarn add stable-position
bun add stable-position
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-07-23 |
| First published | 2015-10-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Author | Damian Krzeminski |
| Maintainers | pirxpilot |
| Keywords | stable-position, order, position, renumber |

## Links

- npm: https://www.npmjs.com/package/stable-position
- Repository: https://github.com/pirxpilot/stable-position
- Homepage: https://github.com/pirxpilot/stable-position#readme
- Issues: https://github.com/pirxpilot/stable-position/issues
- npm.io page: https://npm.io/package/stable-position

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2026-07-23
- 2.0.0 — 2026-06-02
- 1.0.1 — 2025-07-07
- 1.0.0 — 2019-04-12
- 0.1.1 — 2017-02-20
- 0.1.0 — 2015-11-19
- 0.0.0 — 2015-10-31

## README

[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]

# stable-position

Generate unique position that can be used to order items without renumbering them.

## Description

The `stable-position` module generates unique, comparable position values by employing an algorithm analogous to decimal fraction notation. Each position is represented as a string of characters where each character corresponds to a level of granularity in a fraction. This representation allows direct comparison and ordering without the need to renumber items.

Because this approach relies on increasing the precision of the fractional part, it guarantees that a new position can always be found between any two existing valid positions, no matter how close they are.

## Install

```sh
$ npm install --save stable-position
```

## Usage

```js
import { first, after, between } from 'stable-position';
import * as assert from 'assert';

const a = first();
const z = after(a);
const x = between(a, z);

assert(a < x && x < z);
```

## API

### `first()`

returns a position value that can be used as a position of first element

### `before(p)`

returns a position value that is smaller than the position represented by p

### `after(p)`

returns a position value that is bigger than the position represented by p

### `between(p ,q)`

return position value that is between p and q

## License

MIT © [Damian Krzeminski](https://pirxpilot.me)

[npm-image]: https://img.shields.io/npm/v/stable-position
[npm-url]: https://npmjs.org/package/stable-position

[build-url]: https://github.com/pirxpilot/stable-position/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/stable-position/check.yaml?branch=main

[deps-image]: https://img.shields.io/librariesio/release/npm/stable-position
[deps-url]: https://libraries.io/npm/stable-position

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