CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-vue--shared

Internal utility functions shared across Vue.js packages for DOM manipulation, type checking, and general utilities

Pending
Overview
Eval results
Files

type-checking.mddocs/

Type Checking and Validation

Comprehensive type guards and validation utilities for runtime type checking, safe property access, and data validation across Vue's codebase.

Capabilities

Basic Type Guards

Core type checking functions that provide TypeScript type narrowing and runtime validation.

/**
 * Check if value is a string
 */
function isString(val: unknown): val is string;

/**
 * Check if value is a function
 */
function isFunction(val: unknown): val is Function;

/**
 * Check if value is a symbol
 */
function isSymbol(val: unknown): val is symbol;

/**
 * Check if value is an object (not null)
 */
function isObject(val: unknown): val is Record<any, any>;

/**
 * Check if value is a plain object
 */
function isPlainObject(val: unknown): val is object;

Collection Type Guards

Type guards for JavaScript collection types and arrays.

/**
 * Alias for Array.isArray with proper typing
 */
const isArray: typeof Array.isArray;

/**
 * Check if value is a Map
 */
function isMap(val: unknown): val is Map<any, any>;

/**
 * Check if value is a Set
 */
function isSet(val: unknown): val is Set<any>;

Built-in Object Type Guards

Type guards for built-in JavaScript objects and primitives.

/**
 * Check if value is a Date object
 */
function isDate(val: unknown): val is Date;

/**
 * Check if value is a RegExp object
 */
function isRegExp(val: unknown): val is RegExp;

/**
 * Check if value is a Promise
 */
function isPromise<T = any>(val: unknown): val is Promise<T>;

Property and Key Validation

Utilities for validating object properties and keys.

/**
 * Check if object has own property (type-safe)
 * @param val - Object to check
 * @param key - Property key to check for
 * @returns Type predicate indicating key exists
 */
function hasOwn(val: object, key: string | symbol): key is keyof typeof val;

/**
 * Check if key represents an integer-like string
 * @param key - Key to validate
 * @returns True if key is integer-like ("0", "123", etc.)
 */
function isIntegerKey(key: unknown): boolean;

Vue-Specific Type Checks

Type validation utilities specific to Vue's component and template system.

/**
 * Check if string is an event handler name (starts with "on" + uppercase)
 * @param key - Property name to check
 * @returns True if key follows event handler pattern
 */
function isOn(key: string): boolean;

/**
 * Check if string is a model listener (v-model update event)
 * @param key - Property name to check
 * @returns Type predicate for update event names
 */
function isModelListener(key: string): key is `onUpdate:${string}`;

/**
 * Check if property name is reserved by Vue
 * @param key - Property name to check
 * @returns True if property is reserved (key, ref, etc.)
 */
function isReservedProp(key: string): boolean;

/**
 * Check if directive name is a built-in Vue directive
 * @param key - Directive name to check
 * @returns True if directive is built-in (v-if, v-for, etc.)
 */
function isBuiltInDirective(key: string): boolean;

Type String Utilities

Low-level utilities for working with JavaScript's type system and toString representations.

/**
 * Reference to Object.prototype.toString for type checking
 */
const objectToString: typeof Object.prototype.toString;

/**
 * Get the type string representation of a value
 * @param value - Value to get type string for
 * @returns Type string like "[object String]"
 */
function toTypeString(value: unknown): string;

/**
 * Extract the raw type name from a type string
 * @param value - Value to get raw type for
 * @returns Raw type name like "String", "Array", etc.
 */
function toRawType(value: unknown): string;

Usage Examples:

import { isString, isObject, hasOwn, isOn, toRawType } from "@vue/shared";

// Basic type checking with type narrowing
function processValue(value: unknown) {
  if (isString(value)) {
    // TypeScript knows value is string here
    return value.toUpperCase();
  }
  
  if (isObject(value)) {
    // TypeScript knows value is Record<any, any> here
    return Object.keys(value);
  }
}

// Safe property access
function getProperty(obj: object, key: string) {
  if (hasOwn(obj, key)) {
    // TypeScript knows key exists on obj
    return obj[key];
  }
  return undefined;
}

// Vue-specific checks
function isEventProp(key: string) {
  return isOn(key); // true for "onClick", "onMouseover", etc.
}

// Type introspection
const type = toRawType(new Date()); // "Date"
const type2 = toRawType([]); // "Array"

Install with Tessl CLI

npx tessl i tessl/npm-vue--shared

docs

display-utilities.md

dom-configuration.md

environment-utilities.md

equality-utilities.md

html-security.md

index.md

normalization.md

object-utilities.md

reactive-flags.md

string-transformations.md

type-checking.md

tile.json