https://github.com/sindresorhus/ts-extras
Essential utilities for TypeScript projects
https://github.com/sindresorhus/ts-extras
Last synced: 8 days ago
JSON representation
Essential utilities for TypeScript projects
- Host: GitHub
- URL: https://github.com/sindresorhus/ts-extras
- Owner: sindresorhus
- License: mit
- Created: 2021-10-15T12:19:22.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T11:26:19.000Z (11 days ago)
- Last Synced: 2025-04-11T19:14:22.382Z (8 days ago)
- Language: TypeScript
- Homepage:
- Size: 53.7 KB
- Stars: 603
- Watchers: 4
- Forks: 17
- Open Issues: 18
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
- awesome-web-dev - ts-extras
README
# ts-extras [](https://giphy.com/gifs/illustration-rainbow-unicorn-26AHG5KGFxSkUWw1i) [](https://www.npmjs.com/package/ts-extras?activeTab=dependents) [](https://www.npmjs.com/package/ts-extras)
> Essential utilities for TypeScript projects
*Ideas for additional **essential** utilities welcome. Type-only utilities belong in [type-fest](https://github.com/sindresorhus/type-fest).*
## Install
```sh
npm install ts-extras
```## Usage
```js
import {isDefined} from 'ts-extras';[1, undefined, 2].filter(isDefined);
//=> [1, 2]
```## API
**General**
- [`asWritable`](source/as-writable.ts) - Cast the given value to be [`Writable`](https://github.com/sindresorhus/type-fest/blob/main/source/writable.d.ts).
- [`safeCastTo`](source/safe-cast-to.ts) - Cast a value to the given type safely.**Type guard**
- [`isDefined`](source/is-defined.ts) - Check whether a value is defined (not `undefined`).
- [`isPresent`](source/is-present.ts) - Check whether a value is present (not `null` or `undefined`).
- [`isEmpty`](source/is-empty.ts) - Check whether an array is empty.
- [`isInfinite`](source/is-infinite.ts) - Check whether a value is infinite.
- [`assertDefined`](source/assert-defined.ts) - Assert that the given value is defined, meaning it is not `undefined`.
- [`assertPresent`](source/assert-present.ts) - Assert that the given value is present (non-nullable), meaning it is neither `null` or `undefined`.
- [`assertError`](source/assert-error.ts) - Assert that the given value is an `Error`.**Improved builtin**
- [`arrayIncludes`](source/array-includes.ts) - An alternative to `Array#includes()` that properly acts as a type guard.
- [`setHas`](source/set-has.ts) - An alternative to `Set#has()` that properly acts as a type guard.
- [`objectKeys`](source/object-keys.ts) - A strongly-typed version of `Object.keys()`.
- [`objectEntries`](source/object-entries.ts) - A strongly-typed version of `Object.entries()`.
- [`objectFromEntries`](source/object-from-entries.ts) - A strongly-typed version of `Object.fromEntries()`.
- [`objectHasOwn`](source/object-has-own.ts) - A strongly-typed version of `Object.hasOwn()`.
- [`isFinite`](source/is-finite.ts) - A strongly-typed version of `Number.isFinite()`.
- [`isInteger`](source/is-integer.ts) - A strongly-typed version of `Number.isInteger()`.
- [`isSafeInteger`](source/is-safe-integer.ts) - A strongly-typed version of `Number.isSafeInteger()`.## FAQ
#### What is the difference between this and `type-fest`?
The `type-fest` package contains only types, meaning they are only used at compile-time and nothing is ever compiled into actual JavaScript code. This package contains functions that are compiled into JavaScript code and used at runtime.
## Related
- [type-fest](https://github.com/sindresorhus/type-fest) - A collection of essential TypeScript types
- [is](https://github.com/sindresorhus/is) - Type guards for any situation