Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@glideapps/ts-necessities

Package Overview
Dependencies
Maintainers
29
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@glideapps/ts-necessities

Small utilities to make life with TypeScript easier

  • 2.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
29
Created

What is @glideapps/ts-necessities?

@glideapps/ts-necessities is a utility library for TypeScript that provides a collection of essential types and utility functions to simplify common tasks and improve type safety in TypeScript projects.

What are @glideapps/ts-necessities's main functionalities?

Optional

The `Optional` type allows you to define a type that can either be a specific type or `null` or `undefined`. This is useful for handling optional values in a type-safe manner.

import { Optional } from '@glideapps/ts-necessities';

function getLength(str: Optional<string>): number {
  return str ? str.length : 0;
}

console.log(getLength('hello')); // 5
console.log(getLength(null)); // 0

NonEmptyArray

The `NonEmptyArray` type ensures that an array has at least one element. This is useful for functions that require a non-empty array as input.

import { NonEmptyArray } from '@glideapps/ts-necessities';

function getFirstElement(arr: NonEmptyArray<number>): number {
  return arr[0];
}

console.log(getFirstElement([1, 2, 3])); // 1

assertNever

The `assertNever` function is used in exhaustive type checking. It ensures that all possible cases in a union type are handled, and if not, it throws a compile-time error.

import { assertNever } from '@glideapps/ts-necessities';

type Shape = 'circle' | 'square';

function getArea(shape: Shape): number {
  switch (shape) {
    case 'circle':
      return Math.PI * 1 * 1;
    case 'square':
      return 1 * 1;
    default:
      return assertNever(shape);
  }
}

console.log(getArea('circle')); // 3.141592653589793

Other packages similar to @glideapps/ts-necessities

Keywords

FAQs

Package last updated on 14 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc