@lou.codes/predicates
Version:
🧐 Predicate util functions
20 lines (19 loc) • 648 B
JavaScript
import { isNumber } from "./isNumber.js";
import { isString } from "./isString.js";
import { isSymbol } from "./isSymbol.js";
/**
* Checks if the given value is a valid PropertyKey of an object (`string`, `symbol`, or `number`).
*
* @category Objects
* @example
* ```typescript
* isPropertyKey("Lou"); // true
* isPropertyKey(1); // true
* isPropertyKey(Symbol("Lou")); // true
* isPropertyKey({}); // false
* ```
* @param input Value to check.
* @returns `true` if the given value is a valid PropertyKey of an object, `false` otherwise.
*/
export const isPropertyKey = input =>
isNumber(input) || isString(input) || isSymbol(input);