Skip to content

Commit

Permalink
fix: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed Oct 26, 2023
1 parent f40b3f9 commit 142ca00
Show file tree
Hide file tree
Showing 35 changed files with 89 additions and 78 deletions.
2 changes: 1 addition & 1 deletion src/getType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Returns the object type of the given payload
*
* @param {*} payload
* @param {any} payload
* @returns {string}
*/
export function getType(payload: any): string {
Expand Down
5 changes: 3 additions & 2 deletions src/isAnyObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { getType } from './getType.js'
import { PlainObject } from './isPlainObject.js'

/**
* Returns whether the payload is an any kind of object (including special classes or objects with different prototypes)
* Returns whether the payload is an any kind of object (including special classes or objects with
* different prototypes)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is PlainObject}
*/
export function isAnyObject(payload: any): payload is PlainObject {
Expand Down
2 changes: 1 addition & 1 deletion src/isBlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a Blob
*
* @param {*} payload
* @param {any} payload
* @returns {payload is Blob}
*/
export function isBlob(payload: any): payload is Blob {
Expand Down
2 changes: 1 addition & 1 deletion src/isBoolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a boolean
*
* @param {*} payload
* @param {any} payload
* @returns {payload is boolean}
*/
export function isBoolean(payload: any): payload is boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/isDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a Date, and that the date is valid
*
* @param {*} payload
* @param {any} payload
* @returns {payload is Date}
*/
export function isDate(payload: any): payload is Date {
Expand Down
2 changes: 1 addition & 1 deletion src/isEmptyArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isArray } from './isArray.js'
/**
* Returns whether the payload is a an empty array
*
* @param {*} payload
* @param {any} payload
* @returns {payload is []}
*/
export function isEmptyArray(payload: any): payload is [] {
Expand Down
5 changes: 3 additions & 2 deletions src/isEmptyObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { isPlainObject } from './isPlainObject.js'

/**
* Returns whether the payload is a an empty object (excluding special classes or objects with other prototypes)
* Returns whether the payload is a an empty object (excluding special classes or objects with other
* prototypes)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is { [K in any]: never }}
*/
export function isEmptyObject(payload: any): payload is { [K in any]: never } {
Expand Down
2 changes: 1 addition & 1 deletion src/isEmptyString.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Returns whether the payload is ''
*
* @param {*} payload
* @param {any} payload
* @returns {payload is string}
*/
export function isEmptyString(payload: any): payload is string {
Expand Down
2 changes: 1 addition & 1 deletion src/isError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is an Error
*
* @param {*} payload
* @param {any} payload
* @returns {payload is Error}
*/
export function isError(payload: any): payload is Error {
Expand Down
2 changes: 1 addition & 1 deletion src/isFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a File
*
* @param {*} payload
* @param {any} payload
* @returns {payload is File}
*/
export function isFile(payload: any): payload is File {
Expand Down
2 changes: 1 addition & 1 deletion src/isFullArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isArray } from './isArray.js'
/**
* Returns whether the payload is a an array with at least 1 item
*
* @param {*} payload
* @param {any} payload
* @returns {payload is any[]}
*/
export function isFullArray(payload: any): payload is any[] {
Expand Down
2 changes: 1 addition & 1 deletion src/isFullString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isString } from './isString.js'
/**
* Returns whether the payload is a string, BUT returns false for ''
*
* @param {*} payload
* @param {any} payload
* @returns {payload is string}
*/
export function isFullString(payload: any): payload is string {
Expand Down
2 changes: 1 addition & 1 deletion src/isFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type AnyFunction = (...args: any[]) => any
/**
* Returns whether the payload is a function (regular or async)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is AnyFunction}
*/
export function isFunction(payload: any): payload is AnyFunction {
Expand Down
17 changes: 8 additions & 9 deletions src/isInstanceOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@ type GlobalClassName = {
}[keyof typeof globalThis]

/**
* Checks if a value is an instance of a class or a class name. Useful when you
* want to check if a value is an instance of a class that may not be defined in
* the current scope. For example, if you want to check if a value is an
* `OffscreenCanvas` instance, you might not want to do the song and dance of
* using `typeof OffscreenCanvas !== 'undefined'` and then shimming
* `OffscreenCanvas` if the types aren't around.
* Checks if a value is an instance of a class or a class name. Useful when you want to check if a
* value is an instance of a class that may not be defined in the current scope. For example, if you
* want to check if a value is an `OffscreenCanvas` instance, you might not want to do the song and
* dance of using `typeof OffscreenCanvas !== 'undefined'` and then shimming `OffscreenCanvas` if
* the types aren't around.
*
* @example
* if (isInstanceOf(value, 'OffscreenCanvas')) {
* // value is an OffscreenCanvas
* }
* if (isInstanceOf(value, 'OffscreenCanvas')) {
* // value is an OffscreenCanvas
* }
*
* @param value The value to recursively check
* @param class_ A string or class that the value should be an instance of
Expand Down
2 changes: 1 addition & 1 deletion src/isMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a Map
*
* @param {*} payload
* @param {any} payload
* @returns {payload is Map<any, any>}
*/
export function isMap(payload: any): payload is Map<any, any> {
Expand Down
2 changes: 1 addition & 1 deletion src/isNaNValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is typeof NaN}
*/
export function isNaNValue(payload: any): payload is typeof NaN {
Expand Down
2 changes: 1 addition & 1 deletion src/isNegativeNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isNumber } from './isNumber.js'
/**
* Returns whether the payload is a negative number (but not 0)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is number}
*/
export function isNegativeNumber(payload: any): payload is number {
Expand Down
2 changes: 1 addition & 1 deletion src/isNull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is null
*
* @param {*} payload
* @param {any} payload
* @returns {payload is null}
*/
export function isNull(payload: any): payload is null {
Expand Down
4 changes: 2 additions & 2 deletions src/isNullOrUndefined.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isNull } from './isNull.js'
import { isOneOf } from './isOneOf.js'
import { /* tree-shaking no-side-effects-when-called */ isOneOf } from './isOneOf.js'
import { isUndefined } from './isUndefined.js'

/**
* Returns true whether the payload is null or undefined
*
* @param {*} payload
* @param {any} payload
* @returns {(payload is null | undefined)}
*/
export const isNullOrUndefined = isOneOf(isNull, isUndefined)
2 changes: 1 addition & 1 deletion src/isNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getType } from './getType.js'
*
* This will return `false` for `NaN`!!
*
* @param {*} payload
* @param {any} payload
* @returns {payload is number}
*/
export function isNumber(payload: any): payload is number {
Expand Down
5 changes: 3 additions & 2 deletions src/isObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { PlainObject, isPlainObject } from './isPlainObject.js'

/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects
* with other prototypes)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is PlainObject}
*/
export function isObject(payload: any): payload is PlainObject {
Expand Down
4 changes: 2 additions & 2 deletions src/isObjectLike.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { PlainObject } from './isPlainObject.js'
*
* Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
*
* @template T this must be passed in < >
* @param {*} payload
* @template T This must be passed in < >
* @param {any} payload
* @returns {payload is T}
*/
export function isObjectLike<T extends PlainObject>(payload: any): payload is T {
Expand Down
57 changes: 32 additions & 25 deletions src/isOneOf.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
import { AnyFunction } from './isFunction'

type TypeGuard<A, B extends A> = (payload: A) => payload is B

/**
* A factory function that creates a function to check if the payload is one of the given types.
*
* @example
* import { isOneOf, isNull, isUndefined } from 'is-what'
* import { isOneOf, isNull, isUndefined } from 'is-what'
*
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
*
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
*/
export function isOneOf<A, B extends A, C extends A>(
a: TypeGuard<A, B>,
b: TypeGuard<A, C>
): TypeGuard<A, B | C>
/**
* A factory function that creates a function to check if the payload is one of the given types.
*
* @example
* import { isOneOf, isNull, isUndefined } from 'is-what'
* import { isOneOf, isNull, isUndefined } from 'is-what'
*
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
*
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
*/
export function isOneOf<A, B extends A, C extends A, D extends A>(
a: TypeGuard<A, B>,
Expand All @@ -33,14 +37,15 @@ export function isOneOf<A, B extends A, C extends A, D extends A>(
): TypeGuard<A, B | C | D>
/**
* A factory function that creates a function to check if the payload is one of the given types.
*
* @example
* import { isOneOf, isNull, isUndefined } from 'is-what'
* import { isOneOf, isNull, isUndefined } from 'is-what'
*
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
*
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
*/
export function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(
a: TypeGuard<A, B>,
Expand All @@ -50,14 +55,15 @@ export function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(
): TypeGuard<A, B | C | D | E>
/**
* A factory function that creates a function to check if the payload is one of the given types.
*
* @example
* import { isOneOf, isNull, isUndefined } from 'is-what'
* import { isOneOf, isNull, isUndefined } from 'is-what'
*
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
*
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
*/
export function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(
a: TypeGuard<A, B>,
Expand All @@ -68,14 +74,15 @@ export function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F
): TypeGuard<A, B | C | D | E | F>
/**
* A factory function that creates a function to check if the payload is one of the given types.
*
* @example
* import { isOneOf, isNull, isUndefined } from 'is-what'
* import { isOneOf, isNull, isUndefined } from 'is-what'
*
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
* const isNullOrUndefined = isOneOf(isNull, isUndefined)
*
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
* isNullOrUndefined(null) // true
* isNullOrUndefined(undefined) // true
* isNullOrUndefined(123) // false
*/
export function isOneOf(
a: AnyFunction,
Expand Down
5 changes: 3 additions & 2 deletions src/isPlainObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { getType } from './getType.js'
export type PlainObject = Record<string | number | symbol, any>

/**
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects with other prototypes)
* Returns whether the payload is a plain JavaScript object (excluding special classes or objects
* with other prototypes)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is PlainObject}
*/
export function isPlainObject(payload: any): payload is PlainObject {
Expand Down
2 changes: 1 addition & 1 deletion src/isPositiveNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isNumber } from './isNumber.js'
/**
* Returns whether the payload is a positive number (but not 0)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is number}
*/
export function isPositiveNumber(payload: any): payload is number {
Expand Down
5 changes: 3 additions & 2 deletions src/isPrimitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { isSymbol } from './isSymbol.js'
import { isUndefined } from './isUndefined.js'

/**
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String | Symbol)
* Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String
* | Symbol)
*
* @param {*} payload
* @param {any} payload
* @returns {(payload is boolean | null | undefined | number | string | symbol)}
*/
export function isPrimitive(
Expand Down
2 changes: 1 addition & 1 deletion src/isPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a Promise
*
* @param {*} payload
* @param {any} payload
* @returns {payload is Promise<any>}
*/
export function isPromise(payload: any): payload is Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion src/isRegExp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getType } from './getType.js'
/**
* Returns whether the payload is a regular expression (RegExp)
*
* @param {*} payload
* @param {any} payload
* @returns {payload is RegExp}
*/
export function isRegExp(payload: any): payload is RegExp {
Expand Down
Loading

0 comments on commit 142ca00

Please sign in to comment.