Skip to content

getPrimitivesExcept

Jason Godesky edited this page Jul 11, 2026 · 1 revision

getPrimitivesExcept returns an array of tuples ([string, any]), where the string is a description and the any is a JavaScript primitive (null, undefined, a function, a boolean, a string, a number, etc.). The primitives array contains one example of each primitive in the language. getPrimitivesExcept allows you to filter out specific examples by specifying their labels.

Parameters

...exceptions: PrimitiveLabel[]

The labels of the primitives to leave out. Valid options are any combination of:

  • 'null'
  • 'undefined'
  • 'a function'
  • 'true'
  • 'false'
  • 'a string'
  • 'a number'
  • 'an empty array'
  • 'an empty object'

Returns

The list of primitives with the exceptions you requested filtered out.

Examples

import { getPrimitivesExcept, primitives } from '@revolutionarygamesco/common'

/*
 * const primitives = [
 *   ['null', null],
 *   ['undefined', undefined],
 *   ['a function', () => {}],
 *   ['true', true],
 *   ['false', false],
 *   ['a string', 'a string'],
 *   ['a number', 42],
 *   ['a symbol', Symbol()],
 *   ['an empty array', []],
 *   ['an empty object', {}],
 * ] as Array<[PrimitiveLabel, any]>
 */

const example = getPrimitivesExcept('a string')
/*
 * const example = [
 *   ['null', null],
 *   ['undefined', undefined],
 *   ['a function', () => {}],
 *   ['true', true],
 *   ['false', false],
 *   ['a number', 42],
 *   ['a symbol', Symbol()],
 *   ['an empty array', []],
 *   ['an empty object', {}],
 * ] as Array<[PrimitiveLabel, any]>
 */

Clone this wiki locally