bb26 4.0.0 → 5.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.
@@ -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 { toBb26, toDecimal } from './index.js';
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 { toDecimal, increment } from './index.js';
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
  */
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a decimal number to a bijective base-26 string.
3
+ *
4
+ * @param number
5
+ */
6
+ export default function toBb26(number: number): string;
@@ -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) {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Converts a bijective base-26 string to a decimal number.
3
+ *
4
+ * @param string
5
+ */
6
+ export default function toDecimal(string: string): 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
- if (!/[A-Z]/.test(string)) {
21
- throw new Error('String must contain only upper-case characters');
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": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Utilities for working with bijective base-26 numerals",
5
5
  "keywords": [
6
6
  "base 26",
@@ -11,39 +11,42 @@
11
11
  "spreadsheet column letters",
12
12
  "license plate serials"
13
13
  ],
14
- "homepage": "https://github.com/patrik-csak/BB26#readme",
15
- "bugs": {
16
- "url": "https://github.com/patrik-csak/BB26/issues"
17
- },
14
+ "repository": "github:patrik-csak/BB26",
15
+ "funding": "https://buymeacoffee.com/patrikcsak",
18
16
  "license": "MIT",
19
- "author": "Patrik Csak <p@trikcsak.com>",
17
+ "author": "Patrik Csak <p@trikcsak.com> (https://patrikcsak.com)",
18
+ "type": "module",
19
+ "exports": {
20
+ "types": "./distribution/source/index.d.ts",
21
+ "default": "./distribution/source/index.js"
22
+ },
20
23
  "files": [
21
- "dist"
24
+ "distribution/source"
22
25
  ],
23
- "repository": "github:patrik-csak/BB26",
24
26
  "scripts": {
25
- "build": "del-cli dist && tsc",
26
- "format": "xo --fix",
27
+ "build": "del-cli distribution && tsc",
28
+ "format": "eslint --fix && prettier --write . && sort-package-json",
27
29
  "prepare": "npm run build",
28
- "test": "xo && ava",
29
- "test:coverage": "del-cli coverage && xo && c8 ava",
30
- "test:coverage:lcov": "del-cli coverage && xo && c8 --reporter=lcovonly ava"
30
+ "test": "eslint && prettier --check . && sort-package-json --check && ava",
31
+ "test:coverage": "del-cli coverage && eslint && prettier --check . && sort-package-json --check && c8 ava"
31
32
  },
32
33
  "dependencies": {
33
- "random-item": "^4.0.1"
34
+ "ow": "^2.0.0",
35
+ "random-int": "^3.0.0"
34
36
  },
35
37
  "devDependencies": {
36
- "@sindresorhus/tsconfig": "^3.0.1",
37
- "ava": "^5.2.0",
38
- "c8": "^7.10.0",
39
- "del-cli": "^5.0.0",
40
- "ts-node": "^10.4.0",
38
+ "@ava/typescript": "^6.0.0",
39
+ "@sindresorhus/tsconfig": "^7.0.0",
40
+ "ava": "^6.4.1",
41
+ "c8": "^10.1.3",
42
+ "del-cli": "^6.0.0",
43
+ "eslint": "^9.32.0",
44
+ "prettier": "^3.6.2",
45
+ "sort-package-json": "^3.0.0",
41
46
  "typescript": "^5.0.2",
42
- "xo": "^0.54.1"
47
+ "xo": "^1.2.1"
43
48
  },
44
49
  "engines": {
45
- "node": ">=16 <=19"
46
- },
47
- "exports": "./dist/index.js",
48
- "type": "module"
50
+ "node": ">=20 <=24"
51
+ }
49
52
  }
package/readme.md CHANGED
@@ -1,9 +1,6 @@
1
1
  # BB26
2
2
 
3
- [![Badge indicating number of weekly downloads of BB26 from npm package registry](https://badgen.net/npm/dw/bb26)](https://www.npmjs.com/package/bb26)
4
- [![Badge indicating percent test coverage of BB26](https://badgen.net/codeclimate/coverage/patrik-csak/BB26?label=test+coverage)](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 | ... | 24 | 25 | 26 | 27 | 28 | 29 | ...
16
- BB26: | A | B | C | ... | X | Y | Z | AA | AB | AC | ...
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
- > **Note**
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
- ```ts
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
- ```js
40
- import { increment } from "bb26";
32
+ ```javascript
33
+ import {increment} from 'bb26';
41
34
 
42
- increment("A"); // 'B'
43
- increment("Z"); // 'AA'
44
- increment("AA"); // 'AB'
35
+ increment('A'); // 'B'
36
+ increment('Z'); // 'AA'
37
+ increment('AA'); // 'AB'
45
38
  ```
46
39
 
47
40
  ### `random()`
48
41
 
49
- ```ts
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
- ```js
57
- import { random } from "bb26";
49
+ ```javascript
50
+ import {random} from 'bb26';
58
51
 
59
- random("AAA"); // 'NE'
60
- random("AAA", "AAAA"); // 'KXZ'
52
+ random('AAA'); // 'NE'
53
+ random('AAA', 'AAAA'); // 'KXZ'
61
54
  ```
62
55
 
63
56
  ### `range()`
64
57
 
65
- ```ts
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
- ```js
73
- import { range } from "bb26";
65
+ ```javascript
66
+ import {range} from 'bb26';
74
67
 
75
- range("B"); // ['A']
76
- range("C"); // ['A', 'B']
77
- range("B", "C"); // ['B']
78
- range("B", "D"); // ['B', 'C']
79
- range("Z", "AC"); // ['Z', 'AA', 'AB']
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
- ```ts
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
- ```js
91
- import { toBb26 } from "bb26";
83
+ ```javascript
84
+ import {toBb26} from 'bb26';
92
85
 
93
- toBb26(1); // 'A'
94
- toBb26(2); // 'B'
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
- ```ts
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
- ```js
109
- import { toDecimal } from "bb26";
101
+ ```javascript
102
+ import {toDecimal} from 'bb26';
110
103
 
111
- toDecimal("A"); // 1
112
- toDecimal("B"); // 2
113
- toDecimal("Z"); // 26
114
- toDecimal("AA"); // 27
115
- toDecimal("AB"); // 28
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;
@@ -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