Skip to content

Commit

Permalink
Update util
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Jan 17, 2025
1 parent 76a637c commit ac08c8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/js/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ export const valueToJsonString = (
*/
export const roundToPrecision = (value: number, bit: number = 0): number => {
if (!Number.isFinite(value)) {
throw new TypeError(`${value} is not a number.`);
throw new TypeError(`${value} is not a finite number.`);
}
if (!Number.isFinite(bit)) {
throw new TypeError(`${bit} is not a number.`);
throw new TypeError(`${bit} is not a finite number.`);
} else if (bit < 0 || bit > HEX) {
throw new RangeError(`${bit} is not between 0 and ${HEX}.`);
}
Expand Down Expand Up @@ -126,10 +126,10 @@ export const interpolateHue = (
arc: string = 'shorter'
): Array<number> => {
if (!Number.isFinite(hueA)) {
throw new TypeError(`${hueA} is not a number.`);
throw new TypeError(`${hueA} is not a finite number.`);
}
if (!Number.isFinite(hueB)) {
throw new TypeError(`${hueB} is not a number.`);
throw new TypeError(`${hueB} is not a finite number.`);
}
switch (arc) {
case 'decreasing': {
Expand Down
20 changes: 16 additions & 4 deletions test/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,22 @@ describe('round to specified precision', () => {
const func = util.roundToPrecision;

it('should throw', () => {
assert.throws(() => func(), TypeError, 'undefined is not a number.');
assert.throws(() => func(), TypeError, 'undefined is not a finite number.');
});

it('should throw', () => {
assert.throws(
() => func(Infinity),
TypeError,
'Infinity is not a finite number.'
);
});

it('should throw', () => {
assert.throws(
() => func(1.23456789, 'foo'),
TypeError,
'foo is not a number.'
'foo is not a finite number.'
);
});

Expand Down Expand Up @@ -269,11 +277,15 @@ describe('interpolate hue', () => {
const func = util.interpolateHue;

it('should throw', () => {
assert.throws(() => func(), TypeError, 'undefined is not a number.');
assert.throws(() => func(), TypeError, 'undefined is not a finite number.');
});

it('should throw', () => {
assert.throws(() => func(90), TypeError, 'undefined is not a number.');
assert.throws(
() => func(90),
TypeError,
'undefined is not a finite number.'
);
});

it('should get value', () => {
Expand Down

0 comments on commit ac08c8c

Please sign in to comment.