Socket
Book a DemoInstallSign in
Socket

@std-types/is-all-of

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@std-types/is-all-of

Checks whether an element matches all of the given criteria

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

@std-types/is-all-of

Checks whether an element matches all of the given criteria

Installation

npm install @std-types/is-all-of

Usage

import isAllOf, { getIsAllOf } from "@std-types/is-all-of";

isAllOf(1, isNumber, isString); // false

interface Identity {
  name: string;
  age: number;
}

const isIdentity = (value: unknown): value is Identity => {
  return isObject(value) && isString(value.name) && isNumber(value.age);
};

interface Position {
  x: number;
  y: number;
}

const isPosition = (value: unknown): value is Position => {
  return isObject(value) && isNumber(value.x) && isNumber(value.y);
};

declare const value: unknown;
if (isAllOf(value, isIdentity, isPosition)) {
  // value is Identity & Position
  value;
}

const isIdentityAndPosition = getIsAllOf(isIdentity, isPosition);
if (isIdentityAndPosition(value)) {
  // value is Identity & Position
  value;
}

FAQs

Package last updated on 15 Apr 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