or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

es5-operations.mdhelper-utilities.mdindex.mdlatest-features.mdmodern-operations.md
tile.json

helper-utilities.mddocs/

Helper Utilities

Shared utilities and record type validators that support the main abstract operations throughout the es-abstract library.

Capabilities

Type Checking Utilities

Core type detection utilities used throughout abstract operations.

/**
 * Determines if a value is an Array
 * @param argument - Value to test
 * @returns true if argument is an Array
 */
function IsArray(argument: any): boolean;

/**
 * Determines if a value is an object (non-null object)
 * @param argument - Value to test
 * @returns true if argument is an object
 */
function isObject(argument: any): boolean;

/**
 * Determines if a value is a primitive
 * @param argument - Value to test
 * @returns true if argument is a primitive value
 */
function isPrimitive(argument: any): boolean;

/**
 * Determines if a value is a valid property key
 * @param argument - Value to test
 * @returns true if argument can be used as property key
 */
function isPropertyKey(argument: any): boolean;

/**
 * Determines if a number is finite
 * @param number - Number to test
 * @returns true if number is finite
 */
function isFinite(number: number): boolean;

/**
 * Determines if a value is NaN
 * @param number - Value to test
 * @returns true if value is NaN
 */
function isNaN(number: any): boolean;

/**
 * Determines if a number is an integer
 * @param number - Number to test
 * @returns true if number is an integer
 */
function isInteger(number: number): boolean;

/**
 * Determines if a value is negative zero
 * @param number - Number to test
 * @returns true if number is -0
 */
function isNegativeZero(number: number): boolean;

/**
 * Determines if a value is a byte value (0-255)
 * @param number - Number to test
 * @returns true if number is a valid byte value
 */
function isByteValue(number: number): boolean;

/**
 * Determines if a value is a valid code point
 * @param number - Number to test
 * @returns true if number is a valid Unicode code point
 */
function isCodePoint(number: number): boolean;

Usage Examples:

const IsArray = require('es-abstract/helpers/IsArray');
const isObject = require('es-abstract/helpers/isObject');
const isPrimitive = require('es-abstract/helpers/isPrimitive');

// Type checking
console.log(IsArray([1, 2, 3]));     // true
console.log(isObject({}));           // true
console.log(isPrimitive('hello'));   // true
console.log(isPrimitive({}));        // false

Mathematical Utilities

Mathematical helper functions supporting numeric operations.

/**
 * Returns the sign of a number
 * @param number - Number to get sign of
 * @returns -1, 0, or 1 indicating sign
 */
function sign(number: number): number;

/**
 * Performs modulo operation
 * @param x - Dividend
 * @param y - Divisor
 * @returns x modulo y
 */
function mod(x: number, y: number): number;

/**
 * Performs BigInt modulo operation
 * @param x - BigInt dividend
 * @param y - BigInt divisor
 * @returns x modulo y as BigInt
 */
function modBigInt(x: bigint, y: bigint): bigint;

/**
 * Maximum safe integer value
 * @returns Maximum safe integer (2^53 - 1)
 */
function maxSafeInteger(): number;

/**
 * Maximum finite number value
 * @returns Maximum finite number value
 */
function maxValue(): number;

String and Character Utilities

String processing and character manipulation utilities.

/**
 * Determines if a character is a leading surrogate
 * @param charCode - Character code to test
 * @returns true if character is leading surrogate
 */
function isLeadingSurrogate(charCode: number): boolean;

/**
 * Determines if a character is a trailing surrogate
 * @param charCode - Character code to test
 * @returns true if character is trailing surrogate
 */
function isTrailingSurrogate(charCode: number): boolean;

/**
 * Determines if a character is a line terminator
 * @param charCode - Character code to test
 * @returns true if character is line terminator
 */
function isLineTerminator(charCode: number): boolean;

/**
 * Pads a time component with leading zeros
 * @param component - Time component number
 * @param length - Desired string length
 * @returns Zero-padded string
 */
function padTimeComponent(component: number, length: number): string;

/**
 * Extracts substring from a string
 * @param string - Source string
 * @param start - Start index
 * @param end - End index
 * @returns Substring
 */
function substring(string: string, start: number, end: number): string;

Array Utilities

Array processing helper functions.

/**
 * Tests if all array elements satisfy a predicate
 * @param array - Array to test
 * @param predicate - Test function
 * @returns true if all elements satisfy predicate
 */
function every(array: any[], predicate: Function): boolean;

/**
 * Executes a function for each array element
 * @param array - Array to iterate
 * @param callback - Function to execute
 * @returns undefined
 */
function forEach(array: any[], callback: Function): undefined;

/**
 * Tests if some array elements satisfy a predicate
 * @param array - Array to test
 * @param predicate - Test function
 * @returns true if some elements satisfy predicate
 */
function some(array: any[], predicate: Function): boolean;

/**
 * Reduces array to single value
 * @param array - Array to reduce
 * @param callback - Reducer function
 * @param initialValue - Initial accumulator value
 * @returns Reduced value
 */
function reduce(array: any[], callback: Function, initialValue?: any): any;

Property and Prototype Utilities

Property descriptor and prototype manipulation utilities.

/**
 * Gets own property descriptor
 * @param object - Object to get descriptor from
 * @param property - Property key
 * @returns Property descriptor or undefined
 */
function getOwnPropertyDescriptor(object: any, property: PropertyKey): PropertyDescriptor | undefined;

/**
 * Converts property descriptor to object form
 * @param descriptor - Property descriptor to convert
 * @returns Object representation of descriptor
 */
function fromPropertyDescriptor(descriptor: PropertyDescriptor): object | undefined;

/**
 * Gets object's prototype
 * @param object - Object to get prototype of
 * @returns Prototype object or null
 */
function getProto(object: any): any;

/**
 * Sets object's prototype
 * @param object - Object to set prototype of
 * @param proto - New prototype value
 * @returns true if successful
 */
function setProto(object: any, proto: any): boolean;

Function Binding Utilities

Function binding and calling utilities.

/**
 * Creates bound function with call-bind
 * @param fn - Function to bind
 * @param thisArg - This value for binding
 * @returns Bound function
 */
function callBind(fn: Function, thisArg?: any): Function;

/**
 * Creates bound function with call-bound
 * @param name - Method name to bind
 * @returns Bound method function
 */
function callBound(name: string): Function;

Binary and Numeric Conversion Utilities

Binary representation and numeric conversion utilities.

/**
 * Converts integer to binary string
 * @param number - Integer to convert
 * @param bitLength - Desired bit length
 * @returns Binary string representation
 */
function intToBinaryString(number: number, bitLength: number): string;

/**
 * Converts fraction to binary string
 * @param fraction - Fraction to convert
 * @param precision - Binary precision
 * @returns Binary fraction string
 */
function fractionToBinaryString(fraction: number, precision: number): string;

/**
 * Converts integer to N-byte representation
 * @param value - Integer value
 * @param n - Number of bytes
 * @param signed - Whether integer is signed
 * @param littleEndian - Byte ordering
 * @returns Byte array
 */
function integerToNBytes(value: number, n: number, signed: boolean, littleEndian: boolean): number[];

/**
 * Converts bytes to float16 value
 * @param bytes - Byte array
 * @param littleEndian - Byte ordering
 * @returns Float16 value
 */
function bytesAsFloat16(bytes: number[], littleEndian: boolean): number;

/**
 * Converts bytes to float32 value
 * @param bytes - Byte array
 * @param littleEndian - Byte ordering
 * @returns Float32 value
 */
function bytesAsFloat32(bytes: number[], littleEndian: boolean): number;

/**
 * Converts bytes to float64 value
 * @param bytes - Byte array
 * @param littleEndian - Byte ordering
 * @returns Float64 value
 */
function bytesAsFloat64(bytes: number[], littleEndian: boolean): number;

Iterator and Symbol Utilities

Iterator and symbol-related helper functions.

/**
 * Gets iterator method from an object
 * @param obj - Object to get iterator method from
 * @returns Iterator method function or undefined
 */
function getIteratorMethod(obj: any): Function | undefined;

/**
 * Gets symbol description
 * @param symbol - Symbol to get description of
 * @returns Symbol description string
 */
function getSymbolDescription(symbol: symbol): string | undefined;

/**
 * Gets inferred name from a function
 * @param fn - Function to get name from
 * @returns Function name or empty string
 */
function getInferredName(fn: Function): string;

Record Type Validators

Validators for ECMAScript specification record types.

/**
 * Validates property descriptor record
 * @param desc - Potential property descriptor
 * @returns true if valid property descriptor
 */
function isPropertyDescriptor(desc: any): boolean;

/**
 * Validates iterator record
 * @param record - Potential iterator record
 * @returns true if valid iterator record
 */
function isIteratorRecord(record: any): boolean;

/**
 * Validates match record
 * @param record - Potential match record
 * @returns true if valid match record
 */
function isMatchRecord(record: any): boolean;

/**
 * Validates promise capability record
 * @param record - Potential promise capability record
 * @returns true if valid promise capability record
 */
function isPromiseCapabilityRecord(record: any): boolean;

/**
 * Validates async generator request record
 * @param record - Potential async generator request record
 * @returns true if valid async generator request record
 */
function isAsyncGeneratorRequestRecord(record: any): boolean;

/**
 * Validates RegExp record
 * @param record - Potential RegExp record
 * @returns true if valid RegExp record
 */
function isRegExpRecord(record: any): boolean;

/**
 * Validates set record
 * @param record - Potential set record
 * @returns true if valid set record
 */
function isSetRecord(record: any): boolean;

/**
 * Asserts that a value is a specific record type
 * @param Type - Record type name
 * @param value - Value to validate
 * @param name - Parameter name for error messages
 * @returns The validated value
 */
function assertRecord(Type: string, value: any, name: string): any;

Typed Array Utilities

Utilities for working with typed arrays and buffers.

/**
 * Map of typed array constructor names to constructors
 * @returns Object mapping names to typed array constructors
 */
function typedArrayConstructors(): object;

/**
 * Gets default system endianness
 * @returns 'little' or 'big' indicating system endianness
 */
function defaultEndianness(): string;

/**
 * Converts bytes to integer value
 * @param bytes - Byte array
 * @param signed - Whether integer is signed
 * @param littleEndian - Byte ordering
 * @returns Integer value
 */
function bytesAsInteger(bytes: number[], signed: boolean, littleEndian: boolean): number;

Regular Expression Utilities

Regular expression testing and processing utilities.

/**
 * Creates regex tester function
 * @param regex - Regular expression to test with
 * @returns Function that tests strings against regex
 */
function regexTester(regex: RegExp): Function;

Time and Date Utilities

Time calculation and formatting utilities.

/**
 * Time-related constants
 * @returns Object with time constants (msPerSecond, etc.)
 */
function timeConstants(): object;

/**
 * Gets time value from a Date
 * @param date - Date object
 * @returns Time value in milliseconds
 */
function timeValue(date: Date): number;

Import Patterns

// Import helper utilities
const IsArray = require('es-abstract/helpers/IsArray');
const isObject = require('es-abstract/helpers/isObject');
const assertRecord = require('es-abstract/helpers/assertRecord');

// Import record validators
const isPropertyDescriptor = require('es-abstract/helpers/records/property-descriptor');
const isIteratorRecord = require('es-abstract/helpers/records/iterator-record');