remeda
Version:
A utility library for JavaScript and Typescript.
1 lines • 933 B
Source Map (JSON)
{"version":3,"file":"isTruthy.cjs","names":[],"sources":["../src/isTruthy.ts"],"sourcesContent":["/**\n * A function that checks if the passed parameter is truthy and narrows its type accordingly.\n *\n * @param data - The variable to check.\n * @returns True if the passed input is truthy, false otherwise.\n * @signature\n * R.isTruthy(data)\n * @example\n * R.isTruthy('somethingElse') //=> true\n * R.isTruthy(null) //=> false\n * R.isTruthy(undefined) //=> false\n * R.isTruthy(false) //=> false\n * R.isTruthy(0) //=> false\n * R.isTruthy('') //=> false\n * @category Guard\n */\n// eslint-disable-next-line unicorn/prefer-native-coercion-functions -- This is not entirely correct, our isTruthy also coerces the type.\nexport function isTruthy<T>(\n data: T,\n): data is Exclude<T, \"\" | 0 | false | null | undefined> {\n return Boolean(data);\n}\n"],"mappings":"AAiBA,SAAgB,EACd,EACuD,CACvD,MAAO,EAAQ"}