CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-type-of

Complete type checking utility library for Node.js with TypeScript support and type guards

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

external-objects.mddocs/

External Object Type Checking

Type checking for objects from external libraries. Currently supports Long objects from the 'long' npm package.

Capabilities

Long Object Type Checking

Returns true if value is a LongObject from the 'long' npm package.

/**
 * Returns true if val is LongObject
 * LongObject is from npm package `long`
 * @param obj - Value to check
 * @returns Type guard indicating if value is LongObject
 */
function isLongObject(obj?: unknown): obj is LongObject;

interface LongObject {
  high: number;
  low: number;
}

Usage Example:

import { isLongObject } from "is-type-of";
import Long from "long"; // npm install long

const longValue = Long.fromNumber(123456789);
const regularObject = { high: 1, low: 2 };

isLongObject(longValue);      // => true
isLongObject(regularObject);  // => true (if it has high/low number properties)
isLongObject({ high: "1", low: 2 }); // => false (high must be number)
isLongObject({});             // => false

Long.js Integration

The long.js library provides support for 64-bit integers in JavaScript. Long objects have the following structure:

interface LongObject {
  high: number;  // The high 32 bits
  low: number;   // The low 32 bits
}

The isLongObject function validates that an object:

  1. Is an object (not null)
  2. Has both high and low properties
  3. Both properties are numbers

Note: This function checks for the structural shape of Long objects, not strict instanceof checking. Any object with the correct high and low number properties will pass this check.

Working with Long Objects

import { isLongObject } from "is-type-of";
import Long from "long";

function processLongValue(value: unknown) {
  if (isLongObject(value)) {
    // value is now typed as LongObject
    console.log(`High: ${value.high}, Low: ${value.low}`);
    
    // If using with long.js library
    if (Long.isLong(value)) {
      // It's an actual Long instance
      console.log(`As string: ${value.toString()}`);
    }
  }
}

// Examples
const longValue = Long.fromString("9223372036854775807");
const longLike = { high: 2147483647, low: -1 };

processLongValue(longValue);  // Both high/low properties and Long methods
processLongValue(longLike);   // Just high/low properties

Type Definitions

interface LongObject {
  high: number;
  low: number;
}

docs

external-objects.md

index.md

node-objects.md

primitive-types.md

standard-objects.md

tile.json