Skip to content

Commit

Permalink
refactor(guards)!: require value parameter
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Jan 31, 2023
1 parent d6158df commit 2e38928
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/guards/is-app-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import AppEnv from '#src/enums/app-env'

/**
* Checks if `value` is an {@link AppEnv}.
* Checks if the given `value` is a valid app environment.
*
* @param {any} [value] - Value to check
* @return {boolean} `true` if `value` is valid app environment
* @param {unknown} value - Value to evaluate
* @return {value is AppEnv} `true` if `value` is {@linkcode AppEnv}
*/
const isAppEnv = (value?: any): value is AppEnv => {
const isAppEnv = (value: unknown): value is AppEnv => {
return Object.values(AppEnv).includes(value as AppEnv)
}

Expand Down
8 changes: 4 additions & 4 deletions src/guards/is-booleanish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import type { Booleanish } from '#src/types'

/**
* Checks if `value` is {@link Booleanish}.
* Checks if the given `value` is a boolean, `'false'`, or `'true'`.
*
* @param {any} [value] - Value to check
* @return {boolean} `true` if `value` is a `boolean`, `'false'`, or `'true'`
* @param {unknown} value - Value to evaluate
* @return {value is Booleanish} `true` if `value` is {@linkcode Booleanish}
*/
const isBooleanish = (value?: any): value is Booleanish => {
const isBooleanish = (value: unknown): value is Booleanish => {
return typeof value === 'boolean' || value === 'false' || value === 'true'
}

Expand Down
8 changes: 4 additions & 4 deletions src/guards/is-empty-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import type { EmptyString } from '#src/types'

/**
* Checks if `value` is an empty string.
* Checks if the given `value` is an empty string.
*
* @param {any} [value] - Value to check
* @return {boolean} `true` if `value` is an empty string
* @param {unknown} value - Value to evaluate
* @return {value is EmptyString} `true` if `value` is empty string
*/
const isEmptyString = (value?: any): value is EmptyString => {
const isEmptyString = (value: unknown): value is EmptyString => {
return typeof value !== 'string' ? false : value.trim() === ''
}

Expand Down
8 changes: 4 additions & 4 deletions src/guards/is-empty-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import isEmptyString from './is-empty-string'
import isNIL from './is-nil'

/**
* Checks if `value` is an empty string or `NIL`.
* Checks if the given `value` is an empty string, `null`, or `undefined`.
*
* @param {any} [value] - Value to check
* @return {boolean} `true` if `value` is empty string, `null`, or `undefined`
* @param {unknown} value - Value to evaluate
* @return {value is EmptyValue} `true` if `value` is empty
*/
const isEmptyValue = (value?: any): value is EmptyValue => {
const isEmptyValue = (value: unknown): value is EmptyValue => {
return isEmptyString(value) || isNIL(value)
}

Expand Down
8 changes: 4 additions & 4 deletions src/guards/is-jwt-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import JwtType from '#src/enums/jwt-type'

/**
* Checks if `value` is a {@link JwtType}.
* Checks if the given `value` is a valid JSON web token type.
*
* @param {any} [value] - Value to check
* @return {boolean} `true` if `value` is valid jwt type
* @param {unknown} value - Value to evaluate
* @return {value is JwtType} `true` if `value` is {@linkcode JwtType}
*/
const isJwtType = (value?: any): value is JwtType => {
const isJwtType = (value: unknown): value is JwtType => {
return Object.values(JwtType).includes(value as JwtType)
}

Expand Down
8 changes: 4 additions & 4 deletions src/guards/is-nil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import type { NIL } from '#src/types'

/**
* Checks if `value` is a {@link NIL}.
* Checks if the given `value` is `null` or `undefined`.
*
* @param {any} [value] - Value to check
* @return {boolean} `true` if `value` is `null` or `undefined`
* @param {unknown} value - Value to evaluate
* @return {value is NIL} `true` if `value` is {@linkcode NIL}
*/
const isNIL = (value?: any): value is NIL => {
const isNIL = (value: unknown): value is NIL => {
return value === null || value === undefined
}

Expand Down
8 changes: 4 additions & 4 deletions src/guards/is-node-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import NodeEnv from '#src/enums/node-env'

/**
* Checks if `value` is a {@link NodeEnv}.
* Checks if the given `value` is a valid node environment.
*
* @param {any} [value=process.env.NODE_ENV] - Value to check
* @return {boolean} `true` if `value` is valid node environment
* @param {unknown} [value=process.env.NODE_ENV] - Value to evaluate
* @return {value is NodeEnv} `true` if `value` is {@linkcode NodeEnv}
*/
const isNodeEnv = (value: any = process.env.NODE_ENV): value is NodeEnv => {
const isNodeEnv = (value: unknown = process.env.NODE_ENV): value is NodeEnv => {
return Object.values(NodeEnv).includes(value as NodeEnv)
}

Expand Down
10 changes: 5 additions & 5 deletions src/guards/is-unix-timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import type { TimestampUnix } from '#src/types'

/**
* Checks if `timestamp` is a valid [unix timestamp][1].
* Checks if the given `value` is a valid [unix timestamp][1].
*
* [1]: https://unixtimestamp.com
*
* @param {any} [timestamp] - Value to check
* @return {boolean} `true` if `timestamp` is valid unix timestamp
* @param {unknown} value - Value to evaluate
* @return {value is TimestampUnix} `true` if `value` is valid unix timestamp
*/
const isUnixTimestamp = (timestamp?: any): timestamp is TimestampUnix => {
return typeof timestamp === 'number' && new Date(timestamp).getTime() > 0
const isUnixTimestamp = (value: unknown): value is TimestampUnix => {
return typeof value === 'number' && new Date(value).getTime() > 0
}

export default isUnixTimestamp

0 comments on commit 2e38928

Please sign in to comment.