CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-intlify--shared

Shared utility package for intlify project providing performance tools, string formatting, event emitters, and type checking utilities.

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

type-checking.mddocs/

Type Checking Utilities

Comprehensive type checking functions for runtime type validation and type guards. These utilities help with safe type checking in dynamic JavaScript environments.

Capabilities

Array Type Checking

Check if a value is an array.

/**
 * Checks if a value is an array
 * @param val - The value to check
 * @returns Type guard indicating if value is an array
 */
const isArray: (val: unknown) => val is any[];

Usage Example:

import { isArray } from "@intlify/shared";

const value = [1, 2, 3];
if (isArray(value)) {
  // TypeScript now knows value is an array
  console.log(value.length); // Safe to use array methods
}

String Type Checking

Check if a value is a string.

/**
 * Checks if a value is a string
 * @param val - The value to check
 * @returns Type guard indicating if value is a string
 */
function isString(val: unknown): val is string;

Object Type Checking

Check if a value is an object (non-null and not an array).

/**
 * Checks if a value is an object (non-null, non-array)
 * @param val - The value to check
 * @returns Type guard indicating if value is an object
 */
function isObject(val: unknown): val is Record<any, any>;

Function Type Checking

Check if a value is a function.

/**
 * Checks if a value is a function
 * @param val - The value to check
 * @returns Type guard indicating if value is a function
 */
function isFunction(val: unknown): val is Function;

Boolean Type Checking

Check if a value is a boolean.

/**
 * Checks if a value is a boolean
 * @param val - The value to check
 * @returns Type guard indicating if value is a boolean
 */
function isBoolean(val: unknown): val is boolean;

Symbol Type Checking

Check if a value is a symbol.

/**
 * Checks if a value is a symbol
 * @param val - The value to check
 * @returns Type guard indicating if value is a symbol
 */
function isSymbol(val: unknown): val is symbol;

Number Type Checking

Check if a value is a finite number.

/**
 * Checks if a value is a finite number
 * @param val - The value to check
 * @returns Type guard indicating if value is a finite number
 */
function isNumber(val: unknown): val is number;

Date Type Checking

Check if a value is a Date object.

/**
 * Checks if a value is a Date object
 * @param val - The value to check
 * @returns Type guard indicating if value is a Date
 */
function isDate(val: unknown): val is Date;

RegExp Type Checking

Check if a value is a RegExp object.

/**
 * Checks if a value is a RegExp object
 * @param val - The value to check
 * @returns Type guard indicating if value is a RegExp
 */
function isRegExp(val: unknown): val is RegExp;

Promise Type Checking

Check if a value is a Promise-like object (has then and catch methods).

/**
 * Checks if a value is a Promise-like object
 * @param val - The value to check
 * @returns Type guard indicating if value is a Promise
 */
function isPromise<T = any>(val: unknown): val is Promise<T>;

Plain Object Type Checking

Check if a value is a plain object (created by Object constructor or object literal).

/**
 * Checks if a value is a plain object
 * @param val - The value to check
 * @returns Type guard indicating if value is a plain object
 */
function isPlainObject(val: unknown): val is object;

Empty Object Type Checking

Check if a value is an empty plain object.

/**
 * Checks if a value is an empty plain object
 * Note: Return type annotation in source code may be incorrect
 * @param val - The value to check
 * @returns Type guard (source declares 'val is boolean' but likely should be 'val is object')
 */
function isEmptyObject(val: unknown): val is boolean;

Type Utilities

Type String Conversion

Get the type string representation of a value.

/**
 * Gets the type string representation of a value
 * @param value - The value to get type string for
 * @returns Type string like '[object Object]', '[object Array]', etc.
 */
function toTypeString(value: unknown): string;

/**
 * Reference to Object.prototype.toString
 */
const objectToString: () => string;

Usage Example:

import { isObject, isArray, isString, isNumber } from "@intlify/shared";

function processValue(value: unknown) {
  if (isString(value)) {
    return value.toUpperCase();
  } else if (isNumber(value)) {
    return value * 2;
  } else if (isArray(value)) {
    return value.map(processValue);
  } else if (isObject(value)) {
    // Safe to iterate over object properties
    return Object.keys(value).reduce((acc, key) => {
      acc[key] = processValue(value[key]);
      return acc;
    }, {} as any);
  }
  return value;
}

docs

environment-performance.md

event-system.md

index.md

object-utilities.md

string-processing.md

type-checking.md

warning-system.md

tile.json