https://github.com/patrik-csak/bb26
🔠Convert between numbers and base-26 spreadsheet column letters
https://github.com/patrik-csak/bb26
base-26 bijective-base-26 hexavigesimal spreadsheet
Last synced: 10 months ago
JSON representation
🔠Convert between numbers and base-26 spreadsheet column letters
- Host: GitHub
- URL: https://github.com/patrik-csak/bb26
- Owner: patrik-csak
- License: mit
- Created: 2019-06-16T17:00:40.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2025-07-26T23:59:21.000Z (11 months ago)
- Last Synced: 2025-08-09T02:26:01.436Z (10 months ago)
- Topics: base-26, bijective-base-26, hexavigesimal, spreadsheet
- Language: TypeScript
- Homepage: https://npmjs.com/bb26
- Size: 1.3 MB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Funding: .github/funding.yml
- License: license.txt
Awesome Lists containing this project
README
# BB26
BB26 is a JavaScript library for working with [bijective base-26](https://en.wikipedia.org/wiki/Bijective_numeration#The_bijective_base-26_system) (BB26) numbers.
## What is bijective base-26 numeration?
You’re probably familiar with BB26 numeration. It’s used for spreadsheet columns, license plate serials, and (probably?) more.
Here’s an example of decimal (base-10) numbers (the numbers you use every day to count things) compared to their corresponding BB26 numbers:
```
Decimal: | 1 | 2 | 3 | … | 24 | 25 | 26 | 27 | 28 | 29 | …
BB26: | A | B | C | … | X | Y | Z | AA | AB | AC | …
```
## Install
```shell
npm install bb26
```
## API
### `increment()`
```typescript
function increment(string: string): string;
```
Increments a bijective base-26 string by one numeral.
```javascript
import {increment} from 'bb26';
increment('A'); // 'B'
increment('Z'); // 'AA'
increment('AA'); // 'AB'
```
### `random()`
```typescript
function random(upper: string): string;
function random(lower: string, upper: string): string;
```
Produces a random string between the inclusive `lower` and `upper` bounds. If only one argument is provided, a string between `'A'` and the given string is returned.
```javascript
import {random} from 'bb26';
random('AAA'); // 'NE'
random('AAA', 'AAAA'); // 'KXZ'
```
### `range()`
```typescript
function range(end: string): string[];
function range(start: string, end: string): string[];
```
Creates an array of bijective base-26 numerals progressing from `start` up to, but not including, `end`. If `end` is not specified, it's set to `start` with `start` then set to `'A'`.
```javascript
import {range} from 'bb26';
range('B'); // ['A']
range('C'); // ['A', 'B']
range('B', 'C'); // ['B']
range('B', 'D'); // ['B', 'C']
range('Z', 'AC'); // ['Z', 'AA', 'AB']
```
### `toBb26()`
```typescript
function toBb26(number: number): string;
```
Converts a decimal number to a bijective base-26 string.
```javascript
import {toBb26} from 'bb26';
toBb26(1); // 'A'
toBb26(2); // 'B'
toBb26(26); // 'Z'
toBb26(27); // 'AA'
toBb26(28); // 'AB'
```
### `toDecimal()`
```typescript
function toDecimal(string: string): number;
```
Converts a bijective base-26 string to a decimal number.
```javascript
import {toDecimal} from 'bb26';
toDecimal('A'); // 1
toDecimal('B'); // 2
toDecimal('Z'); // 26
toDecimal('AA'); // 27
toDecimal('AB'); // 28
```