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

es5-operations.mddocs/

ES5 Operations

ECMAScript 5 foundation operations providing core language semantics for type system, comparisons, property descriptors, and date/time operations.

Capabilities

Type System Operations

Core type detection and conversion operations that form the foundation of JavaScript's type system.

/**
 * Returns the ECMAScript Language Type of a value
 * @param x - Any value to check the type of
 * @returns String indicating the ECMAScript type
 */
function Type(x: any): 'Undefined' | 'Null' | 'Boolean' | 'Number' | 'String' | 'Object';

/**
 * Converts argument to Boolean type
 * @param argument - Value to convert to boolean
 * @returns Boolean representation of the argument
 */
function ToBoolean(argument: any): boolean;

/**
 * Converts argument to Number type  
 * @param argument - Value to convert to number
 * @returns Number representation of the argument
 */
function ToNumber(argument: any): number;

/**
 * Converts argument to String type
 * @param argument - Value to convert to string  
 * @returns String representation of the argument
 */
function ToString(argument: any): string;

/**
 * Converts argument to Object type
 * @param argument - Value to convert to object
 * @returns Object representation of the argument
 */
function ToObject(argument: any): object;

/**
 * Converts argument to primitive value
 * @param input - Value to convert
 * @param PreferredType - Optional preferred type hint ('number' or 'string')
 * @returns Primitive representation of the input
 */
function ToPrimitive(input: any, PreferredType?: 'number' | 'string'): any;

/**
 * Converts argument to 32-bit signed integer
 * @param argument - Value to convert
 * @returns 32-bit signed integer
 */
function ToInt32(argument: any): number;

/**
 * Converts argument to 32-bit unsigned integer
 * @param argument - Value to convert
 * @returns 32-bit unsigned integer
 */
function ToUint32(argument: any): number;

/**
 * Converts argument to 16-bit unsigned integer
 * @param argument - Value to convert
 * @returns 16-bit unsigned integer
 */
function ToUint16(argument: any): number;

/**
 * Converts argument to integer (ES5 ToInteger)
 * @param argument - Value to convert
 * @returns Integer value
 */
function ToInteger(argument: any): number;

Usage Examples:

const ES5 = require('es-abstract/es5');

// Type checking
console.log(ES5.Type(42));           // 'Number'
console.log(ES5.Type('hello'));      // 'String'
console.log(ES5.Type(null));         // 'Null'
console.log(ES5.Type(undefined));    // 'Undefined'
console.log(ES5.Type({}));           // 'Object'

// Type conversions
console.log(ES5.ToNumber('123'));    // 123
console.log(ES5.ToNumber(true));     // 1
console.log(ES5.ToString(456));      // '456'
console.log(ES5.ToBoolean(0));       // false
console.log(ES5.ToBoolean(''));      // false
console.log(ES5.ToBoolean('hi'));    // true

Comparison Operations

Comparison and equality testing operations following ECMAScript semantics.

/**
 * Performs the SameValue comparison  
 * @param x - First value to compare
 * @param y - Second value to compare
 * @returns true if values are the same, false otherwise
 */
function SameValue(x: any, y: any): boolean;

/**
 * Abstract Equality Comparison (==)
 * @param x - First value to compare
 * @param y - Second value to compare  
 * @returns Result of abstract equality comparison
 */
function AbstractEqualityComparison(x: any, y: any): boolean;

/**
 * Abstract Relational Comparison (<, >, <=, >=)
 * @param x - First value to compare
 * @param y - Second value to compare
 * @param LeftFirst - Whether to evaluate x before y
 * @returns Result of relational comparison or undefined
 */
function AbstractRelationalComparison(x: any, y: any, LeftFirst: boolean): boolean | undefined;

/**
 * Strict Equality Comparison (===)
 * @param x - First value to compare
 * @param y - Second value to compare
 * @returns Result of strict equality comparison
 */
function StrictEqualityComparison(x: any, y: any): boolean;

Property Descriptor Operations

Operations for working with ECMAScript property descriptors.

/**
 * Determines if a descriptor is a Property Descriptor
 * @param Desc - Potential property descriptor
 * @returns true if Desc is a valid property descriptor
 */
function IsPropertyDescriptor(Desc: any): boolean;

/**
 * Determines if a descriptor is an Accessor Descriptor
 * @param Desc - Property descriptor to check
 * @returns true if Desc is an accessor descriptor
 */
function IsAccessorDescriptor(Desc: PropertyDescriptor): boolean;

/**
 * Determines if a descriptor is a Data Descriptor
 * @param Desc - Property descriptor to check
 * @returns true if Desc is a data descriptor  
 */
function IsDataDescriptor(Desc: PropertyDescriptor): boolean;

/**
 * Determines if a descriptor is a Generic Descriptor
 * @param Desc - Property descriptor to check
 * @returns true if Desc is a generic descriptor
 */
function IsGenericDescriptor(Desc: PropertyDescriptor): boolean;

/**
 * Converts a Property Descriptor to an Object
 * @param Desc - Property descriptor to convert
 * @returns Object representation of the descriptor
 */
function FromPropertyDescriptor(Desc: PropertyDescriptor): object | undefined;

/**
 * Converts an Object to a Property Descriptor
 * @param Obj - Object to convert to property descriptor
 * @returns Property descriptor representation
 */
function ToPropertyDescriptor(Obj: object): PropertyDescriptor;

Date and Time Operations

Date and time calculation operations following ECMAScript specification.

/**
 * Returns the day number from a time value
 * @param t - Time value
 * @returns Day number
 */  
function Day(t: number): number;

/**
 * Returns the time within the day from a time value
 * @param t - Time value
 * @returns Time within day in milliseconds
 */
function TimeWithinDay(t: number): number;

/**
 * Returns the year from a time value
 * @param t - Time value
 * @returns Year number
 */
function YearFromTime(t: number): number;

/**
 * Returns the month from a time value
 * @param t - Time value
 * @returns Month number (0-11)
 */
function MonthFromTime(t: number): number;

/**
 * Returns the date from a time value
 * @param t - Time value
 * @returns Date number (1-31)
 */
function DateFromTime(t: number): number;

/**
 * Returns the weekday from a time value
 * @param t - Time value
 * @returns Weekday number (0-6)
 */
function WeekDay(t: number): number;

/**
 * Returns the hour from a time value
 * @param t - Time value
 * @returns Hour number (0-23)
 */
function HourFromTime(t: number): number;

/**
 * Returns the minute from a time value
 * @param t - Time value
 * @returns Minute number (0-59)
 */
function MinFromTime(t: number): number;

/**
 * Returns the second from a time value
 * @param t - Time value
 * @returns Second number (0-59)
 */
function SecFromTime(t: number): number;

/**
 * Returns the millisecond from a time value
 * @param t - Time value
 * @returns Millisecond number (0-999)
 */
function msFromTime(t: number): number;

Utility Operations

Core utility operations used throughout the specification.

/**
 * Determines if argument is callable
 * @param argument - Value to test for callability
 * @returns true if argument is callable
 */
function IsCallable(argument: any): boolean;

/**
 * Throws TypeError if argument is null or undefined
 * @param argument - Value to check for coercibility
 * @returns The argument if coercible
 */
function CheckObjectCoercible(argument: any): any;

/**
 * Returns absolute value
 * @param x - Number to get absolute value of
 * @returns Absolute value of x
 */
function abs(x: number): number;

/**
 * Returns floor of a number
 * @param x - Number to floor
 * @returns Floor of x
 */
function floor(x: number): number;

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

Import Patterns

// Import entire ES5 collection
const ES5 = require('es-abstract/es5');

// Import individual operations (recommended)
const Type = require('es-abstract/5/Type');
const ToNumber = require('es-abstract/5/ToNumber');
const SameValue = require('es-abstract/5/SameValue');
const IsCallable = require('es-abstract/5/IsCallable');