bb26 2.2.1 → 3.0.0
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/increment.js +3 -10
- package/dist/index.d.ts +5 -6
- package/dist/index.js +5 -16
- package/dist/random.js +6 -12
- package/dist/range.js +5 -12
- package/dist/to-bb26.js +2 -5
- package/dist/to-decimal.js +3 -6
- package/license.txt +1 -1
- package/package.json +14 -11
- package/readme.md +12 -10
package/dist/increment.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const to_bb26_1 = __importDefault(require("./to-bb26"));
|
|
7
|
-
const to_decimal_1 = __importDefault(require("./to-decimal"));
|
|
1
|
+
import { toBb26, toDecimal } from './index.js';
|
|
8
2
|
/**
|
|
9
3
|
* Increments a bijective base-26 string by one numeral.
|
|
10
4
|
*
|
|
@@ -19,7 +13,6 @@ const to_decimal_1 = __importDefault(require("./to-decimal"));
|
|
|
19
13
|
* @param string - String to increment
|
|
20
14
|
* @return Incremented string
|
|
21
15
|
*/
|
|
22
|
-
function increment(string) {
|
|
23
|
-
return (
|
|
16
|
+
export default function increment(string) {
|
|
17
|
+
return toBb26(toDecimal(string) + 1);
|
|
24
18
|
}
|
|
25
|
-
exports.default = increment;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export { increment, random, range, toBb26, toDecimal };
|
|
1
|
+
export { default as increment } from './increment.js';
|
|
2
|
+
export { default as range } from './range.js';
|
|
3
|
+
export { default as random } from './random.js';
|
|
4
|
+
export { default as toBb26 } from './to-bb26.js';
|
|
5
|
+
export { default as toDecimal } from './to-decimal.js';
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.toDecimal = exports.toBb26 = exports.range = exports.random = exports.increment = void 0;
|
|
7
|
-
const increment_1 = __importDefault(require("./increment"));
|
|
8
|
-
exports.increment = increment_1.default;
|
|
9
|
-
const random_1 = __importDefault(require("./random"));
|
|
10
|
-
exports.random = random_1.default;
|
|
11
|
-
const range_1 = __importDefault(require("./range"));
|
|
12
|
-
exports.range = range_1.default;
|
|
13
|
-
const to_bb26_1 = __importDefault(require("./to-bb26"));
|
|
14
|
-
exports.toBb26 = to_bb26_1.default;
|
|
15
|
-
const to_decimal_1 = __importDefault(require("./to-decimal"));
|
|
16
|
-
exports.toDecimal = to_decimal_1.default;
|
|
1
|
+
export { default as increment } from './increment.js';
|
|
2
|
+
export { default as range } from './range.js';
|
|
3
|
+
export { default as random } from './random.js';
|
|
4
|
+
export { default as toBb26 } from './to-bb26.js';
|
|
5
|
+
export { default as toDecimal } from './to-decimal.js';
|
package/dist/random.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const random_item_1 = __importDefault(require("random-item"));
|
|
8
|
-
const range_1 = __importDefault(require("./range"));
|
|
1
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
2
|
+
import randomItem from 'random-item';
|
|
3
|
+
import { range } from './index.js';
|
|
9
4
|
/**
|
|
10
5
|
* Produces a random string between the inclusive `lower` and `upper` bounds. If
|
|
11
6
|
* only one argument is provided, a string between `'A'` and the given string is
|
|
@@ -22,9 +17,8 @@ const range_1 = __importDefault(require("./range"));
|
|
|
22
17
|
* @param upper
|
|
23
18
|
* @returns Random string
|
|
24
19
|
*/
|
|
25
|
-
function random(lower, upper) {
|
|
20
|
+
export default function random(lower, upper) {
|
|
26
21
|
const start = upper ? lower : 'A';
|
|
27
|
-
const end = upper
|
|
28
|
-
return (
|
|
22
|
+
const end = upper ?? lower;
|
|
23
|
+
return randomItem(range(start, end));
|
|
29
24
|
}
|
|
30
|
-
exports.default = random;
|
package/dist/range.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const to_decimal_1 = __importDefault(require("./to-decimal"));
|
|
8
|
-
const increment_1 = __importDefault(require("./increment"));
|
|
1
|
+
/* eslint-disable @typescript-eslint/unified-signatures */
|
|
2
|
+
import { toDecimal, increment } from './index.js';
|
|
9
3
|
/**
|
|
10
4
|
* Creates an array of bijective base-26 numerals progressing from `start` up
|
|
11
5
|
* to, but not including, `end`.
|
|
@@ -25,13 +19,12 @@ const increment_1 = __importDefault(require("./increment"));
|
|
|
25
19
|
* @param start - The start of the range
|
|
26
20
|
* @param end - The end of the range
|
|
27
21
|
*/
|
|
28
|
-
function range(start, end) {
|
|
22
|
+
export default function range(start, end) {
|
|
29
23
|
const _range = [];
|
|
30
|
-
const _end = end
|
|
24
|
+
const _end = end ?? start;
|
|
31
25
|
const _start = end ? start : 'A';
|
|
32
|
-
for (let i = _start; (
|
|
26
|
+
for (let i = _start; toDecimal(i) < toDecimal(_end); i = increment(i)) {
|
|
33
27
|
_range.push(i);
|
|
34
28
|
}
|
|
35
29
|
return _range;
|
|
36
30
|
}
|
|
37
|
-
exports.default = range;
|
package/dist/to-bb26.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
function toChar(number) {
|
|
4
|
-
return String.
|
|
2
|
+
return String.fromCodePoint('A'.codePointAt(0) - 1 + number);
|
|
5
3
|
}
|
|
6
4
|
/**
|
|
7
5
|
* Converts a decimal number to a bijective base-26 string.
|
|
@@ -18,7 +16,7 @@ function toChar(number) {
|
|
|
18
16
|
*
|
|
19
17
|
* @param number
|
|
20
18
|
*/
|
|
21
|
-
function toBb26(number) {
|
|
19
|
+
export default function toBb26(number) {
|
|
22
20
|
let string = '';
|
|
23
21
|
let _number = number;
|
|
24
22
|
while (_number > 0) {
|
|
@@ -27,4 +25,3 @@ function toBb26(number) {
|
|
|
27
25
|
}
|
|
28
26
|
return string;
|
|
29
27
|
}
|
|
30
|
-
exports.default = toBb26;
|
package/dist/to-decimal.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
function charToDecimal(letter) {
|
|
4
|
-
return letter.
|
|
2
|
+
return letter.codePointAt(0) - 'A'.codePointAt(0) + 1;
|
|
5
3
|
}
|
|
6
4
|
/**
|
|
7
5
|
* Converts a bijective base-26 string to a decimal number.
|
|
@@ -18,15 +16,14 @@ function charToDecimal(letter) {
|
|
|
18
16
|
*
|
|
19
17
|
* @param string
|
|
20
18
|
*/
|
|
21
|
-
function toDecimal(string) {
|
|
19
|
+
export default function toDecimal(string) {
|
|
22
20
|
if (!/[A-Z]/.test(string)) {
|
|
23
21
|
throw new Error('String must contain only upper-case characters');
|
|
24
22
|
}
|
|
25
23
|
let number = 0;
|
|
26
24
|
for (let i = 0; i < string.length; i++) {
|
|
27
25
|
const char = string[string.length - i - 1];
|
|
28
|
-
number +=
|
|
26
|
+
number += 26 ** i * charToDecimal(char);
|
|
29
27
|
}
|
|
30
28
|
return number;
|
|
31
29
|
}
|
|
32
|
-
exports.default = toDecimal;
|
package/license.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) Patrik Csak <p@trikcsak.com> (https://patrikcsak.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bb26",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Utilities for working with bijective base-26 numerals",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"base 26",
|
|
@@ -20,27 +20,30 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
|
-
"main": "dist",
|
|
24
23
|
"repository": "github:ptrkcsk/BB26",
|
|
25
24
|
"scripts": {
|
|
26
|
-
"build": "tsc",
|
|
25
|
+
"build": "del-cli dist && tsc",
|
|
27
26
|
"format": "xo --fix",
|
|
28
|
-
"prepare": "
|
|
27
|
+
"prepare": "npm run build",
|
|
29
28
|
"test": "xo && ava",
|
|
30
29
|
"test:coverage": "del-cli coverage && xo && c8 ava",
|
|
31
30
|
"test:coverage:lcov": "del-cli coverage && xo && c8 --reporter=lcovonly ava"
|
|
32
31
|
},
|
|
33
32
|
"dependencies": {
|
|
34
|
-
"random-item": "^
|
|
33
|
+
"random-item": "^4.0.1"
|
|
35
34
|
},
|
|
36
35
|
"devDependencies": {
|
|
37
|
-
"@tsconfig
|
|
38
|
-
"ava": "^
|
|
36
|
+
"@sindresorhus/tsconfig": "^3.0.1",
|
|
37
|
+
"ava": "^5.2.0",
|
|
39
38
|
"c8": "^7.10.0",
|
|
40
|
-
"del-cli": "^
|
|
39
|
+
"del-cli": "^5.0.0",
|
|
41
40
|
"ts-node": "^10.4.0",
|
|
42
|
-
"typescript": "^
|
|
43
|
-
"xo": "^0.
|
|
41
|
+
"typescript": "^5.0.2",
|
|
42
|
+
"xo": "^0.53.1"
|
|
44
43
|
},
|
|
45
|
-
"
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=14 <=19"
|
|
46
|
+
},
|
|
47
|
+
"exports": "./dist/index.js",
|
|
48
|
+
"type": "module"
|
|
46
49
|
}
|
package/readme.md
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
# BB26
|
|
2
2
|
|
|
3
|
-
[](https://bundlephobia.com/result?p=bb26)
|
|
4
|
+
[](https://www.npmjs.com/package/bb26)
|
|
5
|
+
[](https://codeclimate.com/github/patrik-csak/BB26/test_coverage)
|
|
4
6
|
|
|
5
7
|
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
|
|
6
8
|
|
|
7
9
|
## What is bijective base-26 numeration?
|
|
8
10
|
|
|
9
|
-
You
|
|
11
|
+
You’re probably familiar with BB26 numeration. It’s used for spreadsheet columns, license plate serials, and (probably?) more.
|
|
10
12
|
|
|
11
|
-
Here
|
|
13
|
+
Here’s an example of decimal (base-10) numbers (the numbers you use every day to count things) compared to their corresponding BB26 numbers:
|
|
12
14
|
|
|
13
15
|
```
|
|
14
16
|
Decimal: | 1 | 2 | 3 | ... | 24 | 25 | 26 | 27 | 28 | 29 | ...
|
|
15
17
|
BB26: | A | B | C | ... | X | Y | Z | AA | AB | AC | ...
|
|
16
18
|
```
|
|
17
19
|
|
|
18
|
-
##
|
|
20
|
+
## Install
|
|
19
21
|
|
|
20
22
|
```sh
|
|
21
23
|
npm install bb26
|
|
22
24
|
```
|
|
23
25
|
|
|
24
|
-
##
|
|
26
|
+
## API
|
|
25
27
|
|
|
26
|
-
###
|
|
28
|
+
### `increment()`
|
|
27
29
|
|
|
28
30
|
```
|
|
29
31
|
increment(string: string): string
|
|
@@ -39,7 +41,7 @@ increment('Z') // 'AA'
|
|
|
39
41
|
increment('AA') // 'AB'
|
|
40
42
|
```
|
|
41
43
|
|
|
42
|
-
###
|
|
44
|
+
### `random()`
|
|
43
45
|
|
|
44
46
|
```
|
|
45
47
|
random(upper: string): string
|
|
@@ -55,7 +57,7 @@ random('AAA') // 'NE'
|
|
|
55
57
|
random('AAA', 'AAAA') // 'KXZ'
|
|
56
58
|
```
|
|
57
59
|
|
|
58
|
-
###
|
|
60
|
+
### `range()`
|
|
59
61
|
|
|
60
62
|
```
|
|
61
63
|
range(end: string): string[]
|
|
@@ -74,7 +76,7 @@ range('B', 'D') // ['B', 'C']
|
|
|
74
76
|
range('Z', 'AC') // ['Z', 'AA', 'AB']
|
|
75
77
|
```
|
|
76
78
|
|
|
77
|
-
###
|
|
79
|
+
### `toBb26()`
|
|
78
80
|
|
|
79
81
|
```
|
|
80
82
|
toBb26(number: number): string
|
|
@@ -92,7 +94,7 @@ toBb26(27) // 'AA'
|
|
|
92
94
|
toBb26(28) // 'AB'
|
|
93
95
|
```
|
|
94
96
|
|
|
95
|
-
###
|
|
97
|
+
### `toDecimal()`
|
|
96
98
|
|
|
97
99
|
```
|
|
98
100
|
toDecimal(string: string): number
|