bb26 4.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist → distribution/source}/increment.d.ts +0 -9
- package/{dist → distribution/source}/increment.js +2 -10
- package/distribution/source/random.js +18 -0
- package/{dist → distribution/source}/range.js +2 -11
- package/distribution/source/to-bb26.d.ts +6 -0
- package/{dist → distribution/source}/to-bb26.js +0 -10
- package/distribution/source/to-decimal.d.ts +6 -0
- package/{dist → distribution/source}/to-decimal.js +4 -13
- package/package.json +32 -23
- package/readme.md +36 -43
- package/dist/random.js +0 -23
- package/dist/to-bb26.d.ts +0 -16
- package/dist/to-decimal.d.ts +0 -16
- /package/{dist → distribution/source}/index.d.ts +0 -0
- /package/{dist → distribution/source}/index.js +0 -0
- /package/{dist → distribution/source}/random.d.ts +0 -0
- /package/{dist → distribution/source}/range.d.ts +0 -0
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Increments a bijective base-26 string by one numeral.
|
|
3
|
-
*
|
|
4
|
-
* ```
|
|
5
|
-
* import { increment } from 'bb26'
|
|
6
|
-
*
|
|
7
|
-
* increment('A') // 'B'
|
|
8
|
-
* increment('Z') // 'AA'
|
|
9
|
-
* increment('AA') // 'AB'
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
3
|
* @param string - String to increment
|
|
13
4
|
* @return Incremented string
|
|
14
5
|
*/
|
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import toBb26 from './to-bb26.js';
|
|
2
|
+
import toDecimal from './to-decimal.js';
|
|
2
3
|
/**
|
|
3
4
|
* Increments a bijective base-26 string by one numeral.
|
|
4
|
-
*
|
|
5
|
-
* ```
|
|
6
|
-
* import { increment } from 'bb26'
|
|
7
|
-
*
|
|
8
|
-
* increment('A') // 'B'
|
|
9
|
-
* increment('Z') // 'AA'
|
|
10
|
-
* increment('AA') // 'AB'
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
5
|
* @param string - String to increment
|
|
14
6
|
* @return Incremented string
|
|
15
7
|
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import randomInteger from 'random-int';
|
|
2
|
+
import toBb26 from './to-bb26.js';
|
|
3
|
+
import toDecimal from './to-decimal.js';
|
|
4
|
+
/**
|
|
5
|
+
* Produces a random string between the inclusive `lower` and `upper` bounds. If
|
|
6
|
+
* only one argument is provided, a string between `'A'` and the given string is
|
|
7
|
+
* returned.
|
|
8
|
+
*
|
|
9
|
+
* @param lower
|
|
10
|
+
* @param upper
|
|
11
|
+
* @returns Random string
|
|
12
|
+
*/
|
|
13
|
+
export default function random(lower, upper) {
|
|
14
|
+
const lowerDecimal = upper === undefined ? 1 : toDecimal(lower);
|
|
15
|
+
const upperDecimal = upper === undefined ? toDecimal(lower) : toDecimal(upper);
|
|
16
|
+
const integer = randomInteger(lowerDecimal, upperDecimal);
|
|
17
|
+
return toBb26(integer);
|
|
18
|
+
}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import increment from './increment.js';
|
|
2
|
+
import toDecimal from './to-decimal.js';
|
|
2
3
|
/**
|
|
3
4
|
* Creates an array of bijective base-26 numerals progressing from `start` up
|
|
4
5
|
* to, but not including, `end`.
|
|
5
6
|
*
|
|
6
7
|
* If `end` is not specified, it's set to `start` with `start` then set to `'A'`.
|
|
7
8
|
*
|
|
8
|
-
* ```
|
|
9
|
-
* import { range } from 'bb26'
|
|
10
|
-
*
|
|
11
|
-
* range('B') // ['A']
|
|
12
|
-
* range('C') // ['A', 'B']
|
|
13
|
-
* range('B', 'C') // ['B']
|
|
14
|
-
* range('B', 'D') // ['B', 'C']
|
|
15
|
-
* range('Z', 'AC') // ['Z', 'AA', 'AB']
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
9
|
* @param start - The start of the range
|
|
19
10
|
* @param end - The end of the range
|
|
20
11
|
*/
|
|
@@ -4,16 +4,6 @@ function toChar(number) {
|
|
|
4
4
|
/**
|
|
5
5
|
* Converts a decimal number to a bijective base-26 string.
|
|
6
6
|
*
|
|
7
|
-
* ```
|
|
8
|
-
* import { toBb26 } from 'bb26'
|
|
9
|
-
*
|
|
10
|
-
* toBb26(1) // 'A'
|
|
11
|
-
* toBb26(2) // 'B'
|
|
12
|
-
* toBb26(26) // 'Z'
|
|
13
|
-
* toBb26(27) // 'AA'
|
|
14
|
-
* toBb26(28) // 'AB'
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
7
|
* @param number
|
|
18
8
|
*/
|
|
19
9
|
export default function toBb26(number) {
|
|
@@ -1,25 +1,16 @@
|
|
|
1
|
+
import ow from 'ow';
|
|
1
2
|
function charToDecimal(letter) {
|
|
2
3
|
return letter.codePointAt(0) - 'A'.codePointAt(0) + 1;
|
|
3
4
|
}
|
|
4
5
|
/**
|
|
5
6
|
* Converts a bijective base-26 string to a decimal number.
|
|
6
7
|
*
|
|
7
|
-
* ```
|
|
8
|
-
* import { toDecimal } from 'bb26'
|
|
9
|
-
*
|
|
10
|
-
* toDecimal('A') // 1
|
|
11
|
-
* toDecimal('B') // 2
|
|
12
|
-
* toDecimal('Z') // 26
|
|
13
|
-
* toDecimal('AA') // 27
|
|
14
|
-
* toDecimal('AB') // 28
|
|
15
|
-
* ```
|
|
16
|
-
*
|
|
17
8
|
* @param string
|
|
18
9
|
*/
|
|
19
10
|
export default function toDecimal(string) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
ow(string, ow.string
|
|
12
|
+
.matches(/^[A-Z]+$/)
|
|
13
|
+
.message(`Expected string to only contain upper-case letters, got \`${string}\``));
|
|
23
14
|
let number = 0;
|
|
24
15
|
for (let i = 0; i < string.length; i++) {
|
|
25
16
|
const char = string[string.length - i - 1];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bb26",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Utilities for working with bijective base-26 numerals",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"base 26",
|
|
@@ -11,39 +11,48 @@
|
|
|
11
11
|
"spreadsheet column letters",
|
|
12
12
|
"license plate serials"
|
|
13
13
|
],
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
"url": "https://github.com/patrik-csak/BB26
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/patrik-csak/BB26"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"author": "Patrik Csak <p@trikcsak.com>",
|
|
19
|
+
"author": "Patrik Csak <p@trikcsak.com> (https://patrikcsak.com)",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./distribution/source/index.d.ts",
|
|
24
|
+
"default": "./distribution/source/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
20
27
|
"files": [
|
|
21
|
-
"
|
|
28
|
+
"distribution/source"
|
|
22
29
|
],
|
|
23
|
-
"repository": "github:patrik-csak/BB26",
|
|
24
30
|
"scripts": {
|
|
25
|
-
"build": "del-cli
|
|
26
|
-
"format": "
|
|
31
|
+
"build": "del-cli distribution && tsc",
|
|
32
|
+
"format": "eslint --fix && npm run prettier -- --write",
|
|
27
33
|
"prepare": "npm run build",
|
|
28
|
-
"
|
|
29
|
-
"test
|
|
30
|
-
"test:coverage
|
|
34
|
+
"prettier": "prettier .",
|
|
35
|
+
"test": "eslint && npm run prettier -- --check && ava",
|
|
36
|
+
"test:coverage": "del-cli coverage && eslint && npm run prettier -- --check && c8 ava"
|
|
31
37
|
},
|
|
32
38
|
"dependencies": {
|
|
33
|
-
"
|
|
39
|
+
"ow": "^3.1.1",
|
|
40
|
+
"random-int": "^3.0.0"
|
|
34
41
|
},
|
|
35
42
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
43
|
+
"@ava/typescript": "^6.0.0",
|
|
44
|
+
"@sindresorhus/tsconfig": "^8.1.0",
|
|
45
|
+
"ava": "^6.4.1",
|
|
46
|
+
"c8": "^10.1.3",
|
|
47
|
+
"del-cli": "^7.0.0",
|
|
48
|
+
"eslint": "^9.32.0",
|
|
49
|
+
"eslint-plugin-package-json": "^0.83.0",
|
|
50
|
+
"prettier": "^3.6.2",
|
|
51
|
+
"prettier-plugin-packagejson": "^2.5.19",
|
|
41
52
|
"typescript": "^5.0.2",
|
|
42
|
-
"xo": "^
|
|
53
|
+
"xo": "^1.2.1"
|
|
43
54
|
},
|
|
44
55
|
"engines": {
|
|
45
|
-
"node": ">=
|
|
46
|
-
}
|
|
47
|
-
"exports": "./dist/index.js",
|
|
48
|
-
"type": "module"
|
|
56
|
+
"node": ">=20 <=24"
|
|
57
|
+
}
|
|
49
58
|
}
|
package/readme.md
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
# BB26
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://codeclimate.com/github/patrik-csak/BB26/test_coverage)
|
|
5
|
-
|
|
6
|
-
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
|
|
3
|
+
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.
|
|
7
4
|
|
|
8
5
|
## What is bijective base-26 numeration?
|
|
9
6
|
|
|
@@ -12,17 +9,13 @@ You’re probably familiar with BB26 numeration. It’s used for spreadsheet col
|
|
|
12
9
|
Here’s an example of decimal (base-10) numbers (the numbers you use every day to count things) compared to their corresponding BB26 numbers:
|
|
13
10
|
|
|
14
11
|
```
|
|
15
|
-
Decimal: | 1 | 2 | 3 |
|
|
16
|
-
BB26: | A | B | C |
|
|
12
|
+
Decimal: | 1 | 2 | 3 | … | 24 | 25 | 26 | 27 | 28 | 29 | …
|
|
13
|
+
BB26: | A | B | C | … | X | Y | Z | AA | AB | AC | …
|
|
17
14
|
```
|
|
18
15
|
|
|
19
16
|
## Install
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
>
|
|
23
|
-
> This package is a native ECMAScript Module (ESM). If your project is not ESM, read [Sindre Sorhus’s Pure ESM package article](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
|
24
|
-
|
|
25
|
-
```sh
|
|
18
|
+
```shell
|
|
26
19
|
npm install bb26
|
|
27
20
|
```
|
|
28
21
|
|
|
@@ -30,68 +23,68 @@ npm install bb26
|
|
|
30
23
|
|
|
31
24
|
### `increment()`
|
|
32
25
|
|
|
33
|
-
```
|
|
26
|
+
```typescript
|
|
34
27
|
function increment(string: string): string;
|
|
35
28
|
```
|
|
36
29
|
|
|
37
30
|
Increments a bijective base-26 string by one numeral.
|
|
38
31
|
|
|
39
|
-
```
|
|
40
|
-
import {
|
|
32
|
+
```javascript
|
|
33
|
+
import {increment} from 'bb26';
|
|
41
34
|
|
|
42
|
-
increment(
|
|
43
|
-
increment(
|
|
44
|
-
increment(
|
|
35
|
+
increment('A'); // 'B'
|
|
36
|
+
increment('Z'); // 'AA'
|
|
37
|
+
increment('AA'); // 'AB'
|
|
45
38
|
```
|
|
46
39
|
|
|
47
40
|
### `random()`
|
|
48
41
|
|
|
49
|
-
```
|
|
42
|
+
```typescript
|
|
50
43
|
function random(upper: string): string;
|
|
51
44
|
function random(lower: string, upper: string): string;
|
|
52
45
|
```
|
|
53
46
|
|
|
54
47
|
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.
|
|
55
48
|
|
|
56
|
-
```
|
|
57
|
-
import {
|
|
49
|
+
```javascript
|
|
50
|
+
import {random} from 'bb26';
|
|
58
51
|
|
|
59
|
-
random(
|
|
60
|
-
random(
|
|
52
|
+
random('AAA'); // 'NE'
|
|
53
|
+
random('AAA', 'AAAA'); // 'KXZ'
|
|
61
54
|
```
|
|
62
55
|
|
|
63
56
|
### `range()`
|
|
64
57
|
|
|
65
|
-
```
|
|
58
|
+
```typescript
|
|
66
59
|
function range(end: string): string[];
|
|
67
60
|
function range(start: string, end: string): string[];
|
|
68
61
|
```
|
|
69
62
|
|
|
70
63
|
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'`.
|
|
71
64
|
|
|
72
|
-
```
|
|
73
|
-
import {
|
|
65
|
+
```javascript
|
|
66
|
+
import {range} from 'bb26';
|
|
74
67
|
|
|
75
|
-
range(
|
|
76
|
-
range(
|
|
77
|
-
range(
|
|
78
|
-
range(
|
|
79
|
-
range(
|
|
68
|
+
range('B'); // ['A']
|
|
69
|
+
range('C'); // ['A', 'B']
|
|
70
|
+
range('B', 'C'); // ['B']
|
|
71
|
+
range('B', 'D'); // ['B', 'C']
|
|
72
|
+
range('Z', 'AC'); // ['Z', 'AA', 'AB']
|
|
80
73
|
```
|
|
81
74
|
|
|
82
75
|
### `toBb26()`
|
|
83
76
|
|
|
84
|
-
```
|
|
77
|
+
```typescript
|
|
85
78
|
function toBb26(number: number): string;
|
|
86
79
|
```
|
|
87
80
|
|
|
88
81
|
Converts a decimal number to a bijective base-26 string.
|
|
89
82
|
|
|
90
|
-
```
|
|
91
|
-
import {
|
|
83
|
+
```javascript
|
|
84
|
+
import {toBb26} from 'bb26';
|
|
92
85
|
|
|
93
|
-
toBb26(1);
|
|
94
|
-
toBb26(2);
|
|
86
|
+
toBb26(1); // 'A'
|
|
87
|
+
toBb26(2); // 'B'
|
|
95
88
|
toBb26(26); // 'Z'
|
|
96
89
|
toBb26(27); // 'AA'
|
|
97
90
|
toBb26(28); // 'AB'
|
|
@@ -99,18 +92,18 @@ toBb26(28); // 'AB'
|
|
|
99
92
|
|
|
100
93
|
### `toDecimal()`
|
|
101
94
|
|
|
102
|
-
```
|
|
95
|
+
```typescript
|
|
103
96
|
function toDecimal(string: string): number;
|
|
104
97
|
```
|
|
105
98
|
|
|
106
99
|
Converts a bijective base-26 string to a decimal number.
|
|
107
100
|
|
|
108
|
-
```
|
|
109
|
-
import {
|
|
101
|
+
```javascript
|
|
102
|
+
import {toDecimal} from 'bb26';
|
|
110
103
|
|
|
111
|
-
toDecimal(
|
|
112
|
-
toDecimal(
|
|
113
|
-
toDecimal(
|
|
114
|
-
toDecimal(
|
|
115
|
-
toDecimal(
|
|
104
|
+
toDecimal('A'); // 1
|
|
105
|
+
toDecimal('B'); // 2
|
|
106
|
+
toDecimal('Z'); // 26
|
|
107
|
+
toDecimal('AA'); // 27
|
|
108
|
+
toDecimal('AB'); // 28
|
|
116
109
|
```
|
package/dist/random.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import randomItem from 'random-item';
|
|
2
|
-
import { range } from './index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Produces a random string between the inclusive `lower` and `upper` bounds. If
|
|
5
|
-
* only one argument is provided, a string between `'A'` and the given string is
|
|
6
|
-
* returned.
|
|
7
|
-
*
|
|
8
|
-
* ```
|
|
9
|
-
* import { random } from 'bb26'
|
|
10
|
-
*
|
|
11
|
-
* random('AAA') // 'NE'
|
|
12
|
-
* random('AAA', 'AAAA') // 'KXZ'
|
|
13
|
-
* ```
|
|
14
|
-
*
|
|
15
|
-
* @param lower
|
|
16
|
-
* @param upper
|
|
17
|
-
* @returns Random string
|
|
18
|
-
*/
|
|
19
|
-
export default function random(lower, upper) {
|
|
20
|
-
const start = upper ? lower : 'A';
|
|
21
|
-
const end = upper ?? lower;
|
|
22
|
-
return randomItem(range(start, end));
|
|
23
|
-
}
|
package/dist/to-bb26.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a decimal number to a bijective base-26 string.
|
|
3
|
-
*
|
|
4
|
-
* ```
|
|
5
|
-
* import { toBb26 } from 'bb26'
|
|
6
|
-
*
|
|
7
|
-
* toBb26(1) // 'A'
|
|
8
|
-
* toBb26(2) // 'B'
|
|
9
|
-
* toBb26(26) // 'Z'
|
|
10
|
-
* toBb26(27) // 'AA'
|
|
11
|
-
* toBb26(28) // 'AB'
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @param number
|
|
15
|
-
*/
|
|
16
|
-
export default function toBb26(number: number): string;
|
package/dist/to-decimal.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a bijective base-26 string to a decimal number.
|
|
3
|
-
*
|
|
4
|
-
* ```
|
|
5
|
-
* import { toDecimal } from 'bb26'
|
|
6
|
-
*
|
|
7
|
-
* toDecimal('A') // 1
|
|
8
|
-
* toDecimal('B') // 2
|
|
9
|
-
* toDecimal('Z') // 26
|
|
10
|
-
* toDecimal('AA') // 27
|
|
11
|
-
* toDecimal('AB') // 28
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* @param string
|
|
15
|
-
*/
|
|
16
|
-
export default function toDecimal(string: string): number;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|