Skip to content

Commit

Permalink
Merge pull request #118 from gohypergiant/refactor/117-cleaner-todos
Browse files Browse the repository at this point in the history
refactor: clean up of some todos
  • Loading branch information
kalisjoshua authored Dec 3, 2024
2 parents 6c23f31 + a2b915e commit 702bc47
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
8 changes: 3 additions & 5 deletions packages/predicates/src/is-latitude/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

import { isFiniteNumber } from '../is-number';

const MIN_LATITUDE = -90;
const MAX_LATITUDE = 90;
const MAX_ABSOLUTE_VALUE = 90;

/**
* Determines if given value is a valid latitude range.
Expand All @@ -32,8 +31,7 @@ export function isLatitude(val: unknown) {
return false;
}

// TODO: is there a better way to tell TS this is a number now based on isFiniteNumeber?
const ensuredValue = val as number;
const abs = Math.abs(val);

return ensuredValue >= MIN_LATITUDE && ensuredValue <= MAX_LATITUDE;
return abs >= 0 && abs <= MAX_ABSOLUTE_VALUE;
}
8 changes: 3 additions & 5 deletions packages/predicates/src/is-longitude/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

import { isFiniteNumber } from '../is-number';

const MIN_LONGITUDE = -180;
const MAX_LONGITUDE = 180;
const MAX_ABSOLUTE_VALUE = 180;

/**
* Determines if given value is a valid longitude range.
Expand All @@ -32,8 +31,7 @@ export function isLongitude(val: unknown) {
return false;
}

// TODO: is there a better way to tell TS this is a number now based on isFiniteNumeber?
const ensuredValue = val as number;
const abs = Math.abs(val);

return ensuredValue >= MIN_LONGITUDE && ensuredValue <= MAX_LONGITUDE;
return abs >= 0 && abs <= MAX_ABSOLUTE_VALUE;
}
8 changes: 4 additions & 4 deletions packages/predicates/src/is-number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { isString } from '../is-string';
* isNumber(NaN) // true
* isNumber('1.23') // false
*/
export function isNumber(val: unknown) {
export function isNumber(val: unknown): val is number {
return typeof val === 'number' || val instanceof Number;
}

Expand All @@ -38,7 +38,7 @@ export function isNumber(val: unknown) {
* isFiniteNumber(NaN) // false
* isFiniteNumber('1.23') // false
*/
export function isFiniteNumber(val: unknown) {
export function isFiniteNumber(val: unknown): val is number {
return Number.isFinite(val);
}

Expand All @@ -54,7 +54,7 @@ export function isFiniteNumber(val: unknown) {
* isFiniteNumeric('1.23') // true
* isFiniteNumeric('hi') // false
*/
export function isFiniteNumeric(val: unknown) {
export function isFiniteNumeric(val: unknown): val is number {
const parsed = isString(val) ? Number.parseFloat(val as string) : val;

return !Number.isNaN(parsed) && isFiniteNumber(parsed);
Expand All @@ -72,7 +72,7 @@ export function isFiniteNumeric(val: unknown) {
* isNumeric('1.23') // true
* isNumeric('hi') // false
*/
export function isNumeric(val: unknown) {
export function isNumeric(val: unknown): val is number {
if (isString(val)) {
return (
val === 'Infinity' ||
Expand Down

0 comments on commit 702bc47

Please sign in to comment.