this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve argument validation

+41 -4
+10
source/to-bb26.ts
··· 4 4 * @param number 5 5 */ 6 6 export default function toBb26(number: number): string { 7 + if (typeof number !== 'number') { 8 + throw new TypeError(`Expected number, got \`${String(number)}\``); 9 + } 10 + 11 + if (!Number.isInteger(number) || number < 1) { 12 + throw new RangeError( 13 + `Expected number to be a positive integer, got \`${number}\``, 14 + ); 15 + } 16 + 7 17 let string = ''; 8 18 9 19 while (number > 0) {
+6 -2
source/to-decimal.ts
··· 10 10 * @param string 11 11 */ 12 12 export default function toDecimal(string: string): number { 13 - if (typeof string !== 'string' || !allowedStringPattern.test(string)) { 14 - throw new TypeError( 13 + if (typeof string !== 'string') { 14 + throw new TypeError(`Expected string, got \`${String(string)}\``); 15 + } 16 + 17 + if (!allowedStringPattern.test(string)) { 18 + throw new RangeError( 15 19 `Expected string to only contain upper-case letters, got \`${string}\``, 16 20 ); 17 21 }
+14
test/to-bb26.ts
··· 21 21 expect(toBb26(from)).toBe(to); 22 22 }); 23 23 } 24 + 25 + test('throws TypeError for non-number input', () => { 26 + expect(() => { 27 + // @ts-expect-error test 28 + toBb26('1'); 29 + }).toThrow(TypeError); 30 + }); 31 + 32 + test('throws RangeError for invalid numbers', () => { 33 + expect(() => toBb26(-1)).toThrow(RangeError); 34 + expect(() => toBb26(0)).toThrow(RangeError); 35 + expect(() => toBb26(Number.NaN)).toThrow(RangeError); 36 + expect(() => toBb26(1.5)).toThrow(RangeError); 37 + });
+11 -2
test/to-decimal.ts
··· 22 22 }); 23 23 } 24 24 25 - test('throws for non-upper-case character', () => { 26 - expect(() => toDecimal('a')).toThrow(); 25 + test('throws TypeError for non-string input', () => { 26 + expect(() => { 27 + // @ts-expect-error test 28 + toDecimal(1); 29 + }).toThrow(TypeError); 30 + }); 31 + 32 + test('throws RangeError for invalid bijective base-26 strings', () => { 33 + expect(() => toDecimal('')).toThrow(RangeError); 34 + expect(() => toDecimal('a')).toThrow(RangeError); 35 + expect(() => toDecimal('A1')).toThrow(RangeError); 27 36 });