npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@veloss/assertion

v0.0.5

Published

Simple assertion library with no dependencies

Readme

@veloss/assertion

npm version npm downloads bundle size MIT License

데이터에 대한 타입을 검증하고 검증된 데이터를 안전한 타입으로 변환하는 라이브러리입니다.

Usage

Install:

# npm
npm install @veloss/assertion

# yarn
yarn add @veloss/assertion

# pnpm
pnpm add @veloss/assertion

Import:

// ESM / Typescript
import { isNumber, ... } from "@veloss/assertion";

// CommonJS
const { isNumber, ... } = require("@veloss/assertion");

isNumber

Type: (value: any) => value is number

validate if the value is a number.

function isNumber(value: any): value is number;

Example

import { isNumber } from "@veloss/assertion";

console.log(isNumber(1)); // true
console.log(isNumber("1")); // false

isNotNumber

Type: (value: any) => value is null | undefined | string | boolean | object | any[]

validate if the value is not a number.

function isNotNumber(
  value: any
): value is null | undefined | string | boolean | object | any[];

Example

import { isNotNumber } from "@veloss/assertion";

console.log(isNotNumber(1)); // false
console.log(isNotNumber("1")); // true

isNumeric

Type: (value: any) => boolean

validate if the value is a numeric value.

function isNumeric(value: any): boolean;

Example

import { isNumeric } from "@veloss/assertion";

console.log(isNumeric(1)); // true
console.log(isNumeric("1")); // true
console.log(isNumeric("1.1")); // true
console.log(isNumeric("1.1.1")); // false

isInteger

Type: (value: any) => value is number

validate if the value is an integer.

function isInteger(value: any): value is number;

Example

import { isInteger } from "@veloss/assertion";

console.log(isInteger(1)); // true
console.log(isInteger(1.1)); // false

isFloat

Type: (value: any) => value is number

validate if the value is a float.

function isFloat(value: any): value is number;

Example

import { isFloat } from "@veloss/assertion";

console.log(isFloat(1.1)); // true
console.log(isFloat(1)); // false

isArray

Type: <T>(value: any) => value is T[]

validate if the value is an array.

function isArray<T>(value: any): value is T[];

Example

import { isArray } from "@veloss/assertion";

console.log(isArray([1, 2, 3])); // true
console.log(isArray("1,2,3".split(","))); // true

isEmptyArray

Type: (value: any) => value is []

validate if the value is an empty array.

function isEmptyArray(value: any): value is [];

Example

import { isEmptyArray } from "@veloss/assertion";

console.log(isEmptyArray([])); // true
console.log(isEmptyArray([1, 2, 3])); // false

isFunction

Type: <T extends AnyFunction = AnyFunction>(value: any) => value is T

validate if the value is a function.

function isFunction<T extends AnyFunction = AnyFunction>(
  value: any
): value is T;

Example

import { isFunction } from "@veloss/assertion";

console.log(isFunction(() => {})); // true
console.log(isFunction(function () {})); // true

isDefined

Type: <T>(value: T) => value is NonNullable<T>

validate if the value is defined.

function isDefined<T>(value: T): value is NonNullable<T>;

Example

import { isDefined } from "@veloss/assertion";

console.log(isDefined(1)); // true
console.log(isDefined(null)); // false

isUndefined

Type: (value: any) => value is undefined

validate if the value is undefined.

function isUndefined(value: any): value is undefined;

Example

import { isUndefined } from "@veloss/assertion";

console.log(isUndefined(undefined)); // true
console.log(isUndefined(null)); // false

isNull

Type: (value: any) => value is null

validate if the value is null.

function isNull(value: any): value is null;

Example

import { isNull } from "@veloss/assertion";

console.log(isNull(null)); // true
console.log(isNull(undefined)); // false

isObject

Type: <T extends object = object>(value: any) => value is T

validate if the value is an object.

function isObject<T extends object = object>(value: any): value is T;

Example

import { isObject } from "@veloss/assertion";

console.log(isObject({})); // true
console.log(isObject([])); // false

isEmptyObject

Type: (value: any) => value is {}

validate if the value is an empty object.

function isEmptyObject(value: any): value is {};

Example

import { isEmptyObject } from "@veloss/assertion";

console.log(isEmptyObject({})); // true
console.log(isEmptyObject({ a: 1 })); // false

isNotEmptyObject

Type: (value: any) => value is object

validate if the value is not an empty object.

function isNotEmptyObject(value: any): value is object;

Example

import { isNotEmptyObject } from "@veloss/assertion";

console.log(isNotEmptyObject({})); // false
console.log(isNotEmptyObject({ a: 1 })); // true

isString

Type: (value: any) => value is string

validate if the value is a string.

function isString(value: any): value is string;

Example

import { isString } from "@veloss/assertion";

console.log(isString("")); // true
console.log(isString(1)); // false

isBoolean

Type: (value: any) => value is boolean

validate if the value is a boolean.

function isBoolean(value: any): value is boolean;

Example

import { isBoolean } from "@veloss/assertion";

console.log(isBoolean(true)); // true
console.log(isBoolean(1)); // false

isSymbol

Type: (value: any) => value is symbol

validate if the value is a symbol.

function isSymbol(value: any): value is symbol;

Example

import { isSymbol } from "@veloss/assertion";

console.log(isSymbol(Symbol())); // true
console.log(isSymbol(1)); // false

isDate

Type: (value: any) => value is Date

validate if the value is a date.

function isDate(value: any): value is Date;

Example

import { isDate } from "@veloss/assertion";

console.log(isDate(new Date())); // true
console.log(isDate(1)); // false

isEmpty

Type: (value: any) => boolean

validate if the value is empty.

function isEmpty(value: any): boolean;

Example

import { isEmpty } from "@veloss/assertion";

console.log(isEmpty("")); // true
console.log(isEmpty([])); // true
console.log(isEmpty({})); // true
console.log(isEmpty(null)); // true
console.log(isEmpty(undefined)); // true
console.log(isEmpty(0)); // false
console.log(isEmpty("1")); // false

isNullOrUndefined

Type: (value: any) => value is null | undefined

validate if the value is null or undefined.

function isNullOrUndefined(value: any): value is null | undefined;

Example

import { isNullOrUndefined } from "@veloss/assertion";

console.log(isNullOrUndefined(null)); // true
console.log(isNullOrUndefined(undefined)); // true
console.log(isNullOrUndefined(0)); // false

isBrowser

Type: () => boolean

validate if the code is running in a browser environment.

function isBrowser(): boolean;

Example

import { isBrowser } from "@veloss/assertion";

console.log(isBrowser()); // true

isNode

Type: () => boolean

validate if the code is running in a Node.js environment.

function isNode(): boolean;

Example

import { isNode } from "@veloss/assertion";

console.log(isNode()); // false

isFalsy

Type: (value: any) => value is false | null | undefined | 0 | ""

validate if the value is falsy.

function isFalsy(value: any): value is false | null | undefined | 0 | "";

Example

import { isFalsy } from "@veloss/assertion";

console.log(isFalsy(null)); // true
console.log(isFalsy(undefined)); // true
console.log(isFalsy(0)); // true
console.log(isFalsy("")); // true
console.log(isFalsy(1)); // false

isTruthy

Type: (value: any) => value is true

validate if the value is truthy.

function isTruthy(value: any): value is true;

Example

import { isTruthy } from "@veloss/assertion";

console.log(isTruthy(true)); // true
console.log(isTruthy(1)); // false

isPromiseLike

Type: <T = any>(value: any) => value is PromiseLike<T>

validate if the value is a promise-like object.

function isPromiseLike<T = any>(value: any): value is PromiseLike<T>;

Example

import { isPromiseLike } from "@veloss/assertion";

console.log(isPromiseLike(Promise.resolve())); // true
console.log(isPromiseLike({ then: () => {} })); // true

isPrimitive

Type: (value: any) => value is string | number | boolean | symbol | null | undefined

validate if the value is a primitive value.

function isPrimitive(
  value: any
): value is string | number | boolean | symbol | null | undefined;

Example

import { isPrimitive } from "@veloss/assertion";

console.log(isPrimitive("")); // true
console.log(isPrimitive(1)); // true
console.log(isPrimitive(true)); // true
console.log(isPrimitive(Symbol())); // true
console.log(isPrimitive(null)); // true
console.log(isPrimitive(undefined)); // true
console.log(isPrimitive({})); // false

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm test
  • Build the project using pnpm build
  • format and lint the project using pnpm format and pnpm lint and pnpm typecheck

License

MIT