or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

array-helpers.mdasync-generators.mdclass-helpers.mddecorators.mdindex.mdmodule-interop.mdobject-helpers.mdprivate-members.mdresource-management.mdtype-utilities.md
tile.json

array-helpers.mddocs/

Array and Iterable Helpers

Array and iterable helpers provide utilities for array conversion, iteration, and destructuring operations that handle edge cases and ensure consistent behavior across JavaScript environments.

Capabilities

Array Conversion Helpers

arrayLikeToArray

Converts array-like objects to real arrays with optional length limit.

/**
 * Converts array-like objects to real arrays with optional length limit
 * @param arr - Array-like object to convert
 * @param len - Optional length limit
 * @returns Real array with copied elements
 */
function arrayLikeToArray(arr: ArrayLike<any>, len?: number): any[];

Usage Example:

import _arrayLikeToArray from '@babel/runtime/helpers/esm/arrayLikeToArray';

const nodeList = document.querySelectorAll('div');
const array = _arrayLikeToArray(nodeList);

arrayWithHoles

Checks if value is array, preserving holes for destructuring operations.

/**
 * Checks if value is array, preserving holes for destructuring
 * @param arr - Value to check
 * @returns Array or undefined to preserve holes
 */
function arrayWithHoles(arr: any): any[] | undefined;

arrayWithoutHoles

Converts array-like objects to arrays without holes, suitable for spread operations.

/**
 * Converts array-like to array without holes
 * @param arr - Array-like object
 * @returns Array without holes
 */
function arrayWithoutHoles(arr: ArrayLike<any>): any[];

iterableToArray

Converts iterables (like Set, Map) to arrays.

/**
 * Converts iterables to arrays
 * @param iter - Iterable object
 * @returns Array with iterable contents
 */
function iterableToArray(iter: Iterable<any>): any[];

iterableToArrayLimit

Converts iterables to arrays with a length limit.

/**
 * Converts iterables to arrays with length limit
 * @param iter - Iterable object
 * @param i - Maximum number of elements
 * @returns Array with limited elements
 */
function iterableToArrayLimit(iter: Iterable<any>, i: number): any[];

unsupportedIterableToArray

Fallback conversion for non-standard iterables and typed arrays.

/**
 * Fallback conversion for non-standard iterables
 * @param o - Object to convert
 * @param minLen - Minimum length
 * @returns Array or undefined
 */
function unsupportedIterableToArray(o: any, minLen?: number): any[] | undefined;

maybeArrayLike

Checks if a value is array-like (has length property).

/**
 * Checks if value is array-like
 * @param next - Value to check
 * @returns Array-like object or undefined
 */
function maybeArrayLike(next: any): ArrayLike<any> | undefined;

Array Processing Helpers

toArray

Generic array conversion with support for destructuring patterns.

/**
 * Generic array conversion for destructuring
 * @param arr - Value to convert to array
 * @returns Array representation
 */
function toArray(arr: any): any[];

Usage Example:

import _toArray from '@babel/runtime/helpers/esm/toArray';

// Used by Babel for: const [first, ...rest] = someValue;
const result = _toArray(someValue);
const first = result[0];
const rest = result.slice(1);

toConsumableArray

Converts values to arrays suitable for spread operations.

/**
 * Converts to array for spread operations
 * @param arr - Value to convert for spreading
 * @returns Array ready for spread syntax
 */
function toConsumableArray(arr: any): any[];

Usage Example:

import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';

// Used by Babel for: [...someIterable]
const spread = _toConsumableArray(someIterable);

slicedToArray

Array slicing for destructuring assignment with proper length handling.

/**
 * Array slicing for destructuring assignment
 * @param arr - Array to slice
 * @param i - Number of elements needed
 * @returns Array with exactly i elements (undefined-padded if needed)
 */
function slicedToArray(arr: any, i: number): any[];

Usage Example:

import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';

// Used by Babel for: const [a, b] = someArray;
const _someArray = _slicedToArray(someArray, 2);
const a = _someArray[0];
const b = _someArray[1];

Iterator Helpers

createForOfIteratorHelper

Creates optimized for-of loop iterator helpers with proper cleanup.

/**
 * Creates for-of loop iterator helpers
 * @param o - Object to iterate
 * @param allowArrayLike - Allow array-like objects
 * @returns Iterator helper object
 */
function createForOfIteratorHelper(o: any, allowArrayLike?: boolean): {
  s(): void;
  n(): { done: boolean; value: any };
  e(error: any): void;
  f(): void;
};

createForOfIteratorHelperLoose

Loose mode for-of iterator helpers with smaller bundle size.

/**
 * Loose mode for-of iterator helpers (smaller bundle)
 * @param o - Object to iterate
 * @param allowArrayLike - Allow array-like objects
 * @returns Simplified iterator helper
 */
function createForOfIteratorHelperLoose(o: any, allowArrayLike?: boolean): {
  s(): void;
  n(): { done: boolean; value: any };
  e(error: any): void;
  f(): void;
};

Error Handling

nonIterableRest

Throws appropriate error for non-iterable rest patterns.

/**
 * Throws error for non-iterable rest
 * @throws TypeError when rest pattern applied to non-iterable
 */
function nonIterableRest(): never;

nonIterableSpread

Throws appropriate error for non-iterable spread operations.

/**
 * Throws error for non-iterable spread
 * @throws TypeError when spread applied to non-iterable
 */
function nonIterableSpread(): never;

Types

// Array-like interface
interface ArrayLike<T> {
  readonly length: number;
  readonly [n: number]: T;
}

// Iterable interface
interface Iterable<T> {
  [Symbol.iterator](): Iterator<T>;
}

// Iterator interface
interface Iterator<T> {
  next(value?: any): IteratorResult<T>;
  return?(value?: any): IteratorResult<T>;
  throw?(e?: any): IteratorResult<T>;
}

interface IteratorResult<T> {
  done: boolean;
  value: T;
}

// For-of helper interface
interface ForOfIteratorHelper {
  s(): void;          // start iteration
  n(): IteratorResult<any>; // get next value  
  e(error: any): void; // handle error
  f(): void;          // finalize/cleanup
}