···11-import increment from './increment'
11+import increment from './increment';
2233describe('increment', () => {
44- it('Should increment A to B', () => {
55- expect(increment('A')).toBe('B')
66- })
44+ it('Should increment A to B', () => {
55+ expect(increment('A')).toBe('B');
66+ });
7788- it('Should increment Z to AA', () => {
99- expect(increment('Z')).toBe('AA')
1010- })
88+ it('Should increment Z to AA', () => {
99+ expect(increment('Z')).toBe('AA');
1010+ });
11111212- it('Should increment ZZ to AAA', () => {
1313- expect(increment('ZZ')).toBe('AAA')
1414- })
1212+ it('Should increment ZZ to AAA', () => {
1313+ expect(increment('ZZ')).toBe('AAA');
1414+ });
15151616- it('Should increment AA to AB', () => {
1717- expect(increment('AA')).toBe('AB')
1818- })
1616+ it('Should increment AA to AB', () => {
1717+ expect(increment('AA')).toBe('AB');
1818+ });
19192020- it('Should increment AB to AC', () => {
2121- expect(increment('AB')).toBe('AC')
2222- })
2020+ it('Should increment AB to AC', () => {
2121+ expect(increment('AB')).toBe('AC');
2222+ });
23232424- it('Should increment AAA to AAB', () => {
2525- expect(increment('AAA')).toBe('AAB')
2626- })
2424+ it('Should increment AAA to AAB', () => {
2525+ expect(increment('AAA')).toBe('AAB');
2626+ });
27272828- it('Should increment AAB to AAC', () => {
2929- expect(increment('AAB')).toBe('AAC')
3030- })
2828+ it('Should increment AAB to AAC', () => {
2929+ expect(increment('AAB')).toBe('AAC');
3030+ });
31313232- it('Should throw if passed non-bijective base-26 string', () => {
3333- expect(() => increment('abc123')).toThrow()
3434- })
3535-})
3232+ it('Should throw if passed non-bijective base-26 string', () => {
3333+ expect(() => increment('abc123')).toThrow();
3434+ });
3535+});
+4-4
source/increment.ts
···11-import toBb26 from './to-bb26'
22-import toDecimal from './to-decimal'
11+import toBb26 from './to-bb26';
22+import toDecimal from './to-decimal';
3344/**
55 * Increments a bijective base-26 string by one numeral.
···1515 * @param string - String to increment
1616 * @return Incremented string
1717 */
1818-export default function increment (string: string): string {
1919- return toBb26(toDecimal(string) + 1)
1818+export default function increment(string: string): string {
1919+ return toBb26(toDecimal(string) + 1);
2020}
+6-6
source/index.ts
···11-import increment from './increment'
22-import random from './random'
33-import range from './range'
44-import toDecimal from './to-decimal'
55-import toBb26 from './to-bb26'
11+import increment from './increment';
22+import random from './random';
33+import range from './range';
44+import toBb26 from './to-bb26';
55+import toDecimal from './to-decimal';
6677-export { increment, random, range, toDecimal, toBb26 }
77+export {increment, random, range, toBb26, toDecimal};
+18-18
source/random.test.ts
···11-import { random, range } from './index'
11+import {random, range} from './index';
2233describe('random', () => {
44- describe('Given an upper bound', () => {
55- test('Should return a valid random string', () => {
66- const validLetters = range('AAA')
77- const results = []
44+ describe('Given an upper bound', () => {
55+ test('Should return a valid random string', () => {
66+ const validLetters = range('AAA');
77+ const results = [];
8899- for (let i = 0; i < 1000; ++i) results.push(random('ZZ'))
99+ for (let i = 0; i < 1000; ++i) results.push(random('ZZ'));
10101111- for (const result of results) expect(validLetters).toContain(result)
1212- })
1313- })
1111+ for (const result of results) expect(validLetters).toContain(result);
1212+ });
1313+ });
14141515- describe('Given an upper and lower bound', () => {
1616- test('Should return a valid random string', () => {
1717- const validLetters = range('AA', 'AAA')
1818- const results = []
1515+ describe('Given an upper and lower bound', () => {
1616+ test('Should return a valid random string', () => {
1717+ const validLetters = range('AA', 'AAA');
1818+ const results = [];
19192020- for (let i = 0; i < 1000; ++i) results.push(random('AA', 'ZZ'))
2020+ for (let i = 0; i < 1000; ++i) results.push(random('AA', 'ZZ'));
21212222- for (const result of results) expect(validLetters).toContain(result)
2323- })
2424- })
2525-})
2222+ for (const result of results) expect(validLetters).toContain(result);
2323+ });
2424+ });
2525+});
+6-11
source/random.ts
···11-import range from './range'
22-import sample from './sample'
33-44-function random (upper: string): string
55-function random (lower: string, upper: string): string
11+import range from './range';
22+import sample from './sample';
6374/**
85 * Produces a random string between the inclusive `lower` and `upper` bounds. If
···2017 * @param upper
2118 * @returns Random string
2219 */
2323-function random (lower: string, upper?: string): string {
2424- const start = upper ? lower : 'A'
2525- const end = upper || lower
2020+export default function random(lower: string, upper?: string): string {
2121+ const start = upper ? lower : 'A';
2222+ const end = upper ?? lower;
26232727- return sample(range(start, end))
2424+ return sample(range(start, end));
2825}
2929-3030-export default random
+16-16
source/range.test.ts
···11-import range from './range'
11+import range from './range';
2233describe('range', () => {
44- test('Should work with end', () => {
55- expect(range('A')).toEqual([])
66- expect(range('B')).toEqual(['A'])
77- expect(range('C')).toEqual(['A', 'B'])
88- expect(range('AB')).toContain('AA')
99- })
44+ test('Should work with end', () => {
55+ expect(range('A')).toEqual([]);
66+ expect(range('B')).toEqual(['A']);
77+ expect(range('C')).toEqual(['A', 'B']);
88+ expect(range('AB')).toContain('AA');
99+ });
10101111- test('Should work with start and end', () => {
1212- expect(range('B', 'C')).toEqual(['B'])
1313- expect(range('B', 'D')).toEqual(['B', 'C'])
1414- expect(range('ZZ', 'AAC')).toEqual(['ZZ', 'AAA', 'AAB'])
1515- })
1111+ test('Should work with start and end', () => {
1212+ expect(range('B', 'C')).toEqual(['B']);
1313+ expect(range('B', 'D')).toEqual(['B', 'C']);
1414+ expect(range('ZZ', 'AAC')).toEqual(['ZZ', 'AAA', 'AAB']);
1515+ });
16161717- test('Should throw if given a string with a non-upper-case letter', () => {
1818- expect(() => range('a')).toThrow()
1919- })
2020-})
1717+ test('Should throw if given a string with a non-upper-case letter', () => {
1818+ expect(() => range('a')).toThrow();
1919+ });
2020+});
+10-15
source/range.ts
···11-import toDecimal from './to-decimal'
22-import increment from './increment'
33-44-function range (end: string): string[]
55-function range (start: string, end: string): string[]
11+import toDecimal from './to-decimal';
22+import increment from './increment';
6374/**
85 * Creates an array of bijective base-26 numerals progressing from `start` up
···2320 * @param start - The start of the range
2421 * @param end - The end of the range
2522 */
2626-function range (start: string, end?: string): string[] {
2727- const range: string[] = []
2828- const _end = end || start
2929- const _start = end ? start : 'A'
2323+export default function range(start: string, end?: string): string[] {
2424+ const _range: string[] = [];
2525+ const _end = end ?? start;
2626+ const _start = end ? start : 'A';
30273131- for (let i = _start; toDecimal(i) < toDecimal(_end); i = increment(i)) {
3232- range.push(i)
3333- }
2828+ for (let i = _start; toDecimal(i) < toDecimal(_end); i = increment(i)) {
2929+ _range.push(i);
3030+ }
34313535- return range
3232+ return _range;
3633}
3737-3838-export default range
+1-1
source/sample.ts
···11export default function sample<T>(array: T[]): T {
22- return array[Math.floor(Math.random() * array.length)];
22+ return array[Math.floor(Math.random() * array.length)];
33}