# @xylabs/exists

[![npm][npm-badge]][npm-link]
[![license][license-badge]][license-link]

> Base functionality used throughout XY Labs TypeScript/JavaScript libraries

## Install

Using npm:

```sh
npm install {{name}}
```

Using yarn:

```sh
yarn add {{name}}
```

Using pnpm:

```sh
pnpm add {{name}}
```

Using bun:

```sh
bun add {{name}}
```


## License

See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).

## Reference

### packages

  ### exists

    ### .temp-typedoc

      ### functions

        ### <a id="exists"></a>exists

[**@xylabs/exists**](#../README)

***

```ts
function exists<T>(x?): x is NonNullable<T>;
```

Used to type narrow an object which is possibly null or undefined. Works well
with functional Array methods. For example:

## Type Parameters

### T

`T`

## Parameters

### x?

`T` \| `null`

The object which is potentially undefined or null

## Returns

`x is NonNullable<T>`

False if the object is null/undefined, true otherwise

## Example

```ts
const payloads: XyoPayload[] = boundWitness._payloads?.filter(exists) || []
```


[npm-badge]: https://img.shields.io/npm/v/@xylabs/exists.svg
[npm-link]: https://www.npmjs.com/package/@xylabs/exists
[license-badge]: https://img.shields.io/npm/l/@xylabs/exists.svg
[license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
