Packages@accelint/predicates
isSomething
Type guard that determines if a value is not null or undefined
Usage
import { isSomething } from '@accelint/predicates/is-something';
isSomething(0); // true
isSomething(''); // true
isSomething(false); // true
isSomething(null); // false
isSomething(undefined); // falseReference
function isSomething(val: unknown): booleanParameters
| Parameter | Type | Description |
|---|---|---|
val | unknown | Value to check |
Returns
Returns true if the value is not null or undefined, false otherwise.
Examples
Example: Happy path validation
import { isSomething } from '@accelint/predicates/is-something';
function processUser(user: User | null | undefined) {
if (isSomething(user)) {
// Happy path - safe to use user
console.log(user.name);
return;
}
console.log('No user provided');
}Example: Filtering arrays
import { isSomething } from '@accelint/predicates/is-something';
const values = [1, null, 2, undefined, 3, 0, ''];
const defined = values.filter(isSomething);
// [1, 2, 3, 0, '']Example: Type narrowing for optional properties
import { isSomething } from '@accelint/predicates/is-something';
interface Config {
apiKey?: string;
timeout?: number;
}
function validateConfig(config: Config) {
const hasApiKey = isSomething(config.apiKey);
const hasTimeout = isSomething(config.timeout);
return hasApiKey && hasTimeout;
}Good to know: This is a composed function using
compose(not, isNothing), demonstrating functional composition. Falsy values like0,'', andfalsereturntruebecause they are defined values.