Standard Toolkit
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);  // false

Reference

function isSomething(val: unknown): boolean

Parameters

ParameterTypeDescription
valunknownValue 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 like 0, '', and false return true because they are defined values.

  • isNothing - Opposite check: value is null or undefined
  • isString - Check if value is a string
  • isNumber - Check if value is a number

On this page