bb26 2.2.1 → 3.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/increment.js CHANGED
@@ -1,10 +1,4 @@
1
- "use strict";
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 (0, to_bb26_1.default)((0, to_decimal_1.default)(string) + 1);
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
- import increment from './increment';
2
- import random from './random';
3
- import range from './range';
4
- import toBb26 from './to-bb26';
5
- import toDecimal from './to-decimal';
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
- "use strict";
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
- 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
- "use strict";
2
- /* eslint-disable @typescript-eslint/unified-signatures, no-redeclare */
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 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 !== null && upper !== void 0 ? upper : lower;
28
- return (0, random_item_1.default)((0, range_1.default)(start, end));
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
- "use strict";
2
- /* eslint-disable @typescript-eslint/unified-signatures, no-redeclare */
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 !== null && end !== void 0 ? end : start;
24
+ const _end = end ?? start;
31
25
  const _start = end ? start : 'A';
32
- for (let i = _start; (0, to_decimal_1.default)(i) < (0, to_decimal_1.default)(_end); i = (0, increment_1.default)(i)) {
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.fromCharCode('A'.charCodeAt(0) - 1 + number);
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;
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  function charToDecimal(letter) {
4
- return letter.charCodeAt(0) - 'A'.charCodeAt(0) + 1;
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 += Math.pow(26, i) * charToDecimal(char);
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) 2021 Patrik Csak
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": "2.2.1",
3
+ "version": "3.0.1",
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": "del-cli dist && npm run build",
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": "^3.1.0"
33
+ "random-item": "^4.0.1"
35
34
  },
36
35
  "devDependencies": {
37
- "@tsconfig/recommended": "^1.0.1",
38
- "ava": "^3.15.0",
36
+ "@sindresorhus/tsconfig": "^3.0.1",
37
+ "ava": "^5.2.0",
39
38
  "c8": "^7.10.0",
40
- "del-cli": "^4.0.1",
39
+ "del-cli": "^5.0.0",
41
40
  "ts-node": "^10.4.0",
42
- "typescript": "^4.0.5",
43
- "xo": "^0.39.1"
41
+ "typescript": "^5.0.2",
42
+ "xo": "^0.53.1"
44
43
  },
45
- "types": "dist"
44
+ "engines": {
45
+ "node": ">=14 <=19"
46
+ },
47
+ "exports": "./dist/index.js",
48
+ "type": "module"
46
49
  }
package/readme.md CHANGED
@@ -1,111 +1,115 @@
1
1
  # BB26
2
2
 
3
- [![BB26 minified and gzipped size](https://badgen.net/bundlephobia/minzip/bb26)](https://bundlephobia.com/result?p=bb26) [![BB26 downloads per month on npm](https://badgen.net/npm/dw/bb26)](https://www.npmjs.com/package/bb26) [![Test Coverage](https://api.codeclimate.com/v1/badges/c56701b3968f3de65188/test_coverage)](https://codeclimate.com/github/ptrkcsk/BB26/test_coverage)
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)
4
5
 
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
6
7
 
7
8
  ## What is bijective base-26 numeration?
8
9
 
9
- You're probably familiar with BB26 numeration. It's used for spreadsheet columns, license plate serials, and (probably?) more.
10
+ Youre probably familiar with BB26 numeration. Its used for spreadsheet columns, license plate serials, and (probably?) more.
10
11
 
11
- 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
+ Heres an example of decimal (base-10) numbers (the numbers you use every day to count things) compared to their corresponding BB26 numbers:
12
13
 
13
14
  ```
14
15
  Decimal: | 1 | 2 | 3 | ... | 24 | 25 | 26 | 27 | 28 | 29 | ...
15
16
  BB26: | A | B | C | ... | X | Y | Z | AA | AB | AC | ...
16
17
  ```
17
18
 
18
- ## Installation
19
+ ## Install
20
+
21
+ > **Note**
22
+ > 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)
19
23
 
20
24
  ```sh
21
25
  npm install bb26
22
26
  ```
23
27
 
24
- ## Usage
28
+ ## API
25
29
 
26
- ### Increment
30
+ ### `increment()`
27
31
 
28
- ```
29
- increment(string: string): string
32
+ ```ts
33
+ function increment(string: string): string;
30
34
  ```
31
35
 
32
36
  Increments a bijective base-26 string by one numeral.
33
37
 
34
38
  ```js
35
- import { increment } from 'bb26'
39
+ import { increment } from "bb26";
36
40
 
37
- increment('A') // 'B'
38
- increment('Z') // 'AA'
39
- increment('AA') // 'AB'
41
+ increment("A"); // 'B'
42
+ increment("Z"); // 'AA'
43
+ increment("AA"); // 'AB'
40
44
  ```
41
45
 
42
- ### Random
46
+ ### `random()`
43
47
 
44
- ```
45
- random(upper: string): string
46
- random(lower: string, upper: string): string
48
+ ```ts
49
+ function random(upper: string): string
50
+ function random(lower: string, upper: string): string
47
51
  ```
48
52
 
49
53
  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.
50
54
 
51
55
  ```js
52
- import { random } from 'bb26'
56
+ import { random } from "bb26";
53
57
 
54
- random('AAA') // 'NE'
55
- random('AAA', 'AAAA') // 'KXZ'
58
+ random("AAA"); // 'NE'
59
+ random("AAA", "AAAA"); // 'KXZ'
56
60
  ```
57
61
 
58
- ### Range
62
+ ### `range()`
59
63
 
60
- ```
61
- range(end: string): string[]
62
- range(start: string, end: string): string[]
64
+ ```ts
65
+ function range(end: string): string[]
66
+ function range(start: string, end: string): string[]
63
67
  ```
64
68
 
65
69
  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'`.
66
70
 
67
71
  ```js
68
- import { range } from 'bb26'
72
+ import { range } from "bb26";
69
73
 
70
- range('B') // ['A']
71
- range('C') // ['A', 'B']
72
- range('B', 'C') // ['B']
73
- range('B', 'D') // ['B', 'C']
74
- range('Z', 'AC') // ['Z', 'AA', 'AB']
74
+ range("B"); // ['A']
75
+ range("C"); // ['A', 'B']
76
+ range("B", "C"); // ['B']
77
+ range("B", "D"); // ['B', 'C']
78
+ range("Z", "AC"); // ['Z', 'AA', 'AB']
75
79
  ```
76
80
 
77
- ### Convert from decimal to BB26
81
+ ### `toBb26()`
78
82
 
79
- ```
80
- toBb26(number: number): string
83
+ ```ts
84
+ function toBb26(number: number): string;
81
85
  ```
82
86
 
83
87
  Converts a decimal number to a bijective base-26 string.
84
88
 
85
89
  ```js
86
- import { toBb26 } from 'bb26'
90
+ import { toBb26 } from "bb26";
87
91
 
88
- toBb26(1) // 'A'
89
- toBb26(2) // 'B'
90
- toBb26(26) // 'Z'
91
- toBb26(27) // 'AA'
92
- toBb26(28) // 'AB'
92
+ toBb26(1); // 'A'
93
+ toBb26(2); // 'B'
94
+ toBb26(26); // 'Z'
95
+ toBb26(27); // 'AA'
96
+ toBb26(28); // 'AB'
93
97
  ```
94
98
 
95
- ### Convert from BB26 to decimal
99
+ ### `toDecimal()`
96
100
 
97
- ```
98
- toDecimal(string: string): number
101
+ ```ts
102
+ function toDecimal(string: string): number;
99
103
  ```
100
104
 
101
105
  Converts a bijective base-26 string to a decimal number.
102
106
 
103
107
  ```js
104
- import { toDecimal } from 'bb26'
108
+ import { toDecimal } from "bb26";
105
109
 
106
- toDecimal('A') // 1
107
- toDecimal('B') // 2
108
- toDecimal('Z') // 26
109
- toDecimal('AA') // 27
110
- toDecimal('AB') // 28
110
+ toDecimal("A"); // 1
111
+ toDecimal("B"); // 2
112
+ toDecimal("Z"); // 26
113
+ toDecimal("AA"); // 27
114
+ toDecimal("AB"); // 28
111
115
  ```