CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-xe-utils

Comprehensive JavaScript utility library with 150+ functions for objects, arrays, dates, strings, numbers, and more

Overview
Eval results
Files

object-operations.mddocs/

Object Operations

Core functionality for object manipulation including property copying, merging, iteration, and transformation. These utilities provide reliable object handling with support for deep operations and custom iteration patterns.

Capabilities

Object Assignment

Copy properties from source objects to a target object, similar to Object.assign but with additional features.

/**
 * Copy properties from source objects to target object
 * @param target - Target object to copy properties to
 * @param sources - Source objects to copy properties from
 * @returns Target object with copied properties
 */
function assign(target: any, ...sources: any[]): any;

/**
 * Deep copy properties (when first parameter is true)
 * @param deep - Set to true for deep copying
 * @param target - Target object for deep copy
 * @param sources - Source objects to deep copy from
 * @returns Target object with deep copied properties
 */
function assign(deep: true, target: any, ...sources: any[]): any;

Usage Examples:

import { assign } from 'xe-utils';

// Basic assignment
const target = { a: 1 };
const result = assign(target, { b: 2 }, { c: 3 });
// Result: { a: 1, b: 2, c: 3 }

// Deep assignment
const deepResult = assign(true, {}, 
  { user: { name: 'Alice' } }, 
  { user: { age: 25 } }
);
// Result: { user: { name: 'Alice', age: 25 } }

Object Merging

Deep merge multiple objects into a target object, recursively combining nested properties.

/**
 * Deep merge objects recursively
 * @param target - Target object to merge into
 * @param sources - Source objects to merge from
 * @returns Target object with merged properties
 */
function merge(target: any, ...sources: any[]): any;

Usage Examples:

import { merge } from 'xe-utils';

const config = { 
  api: { timeout: 5000 }, 
  features: { auth: true } 
};

const overrides = { 
  api: { retries: 3 }, 
  features: { logging: true } 
};

const merged = merge(config, overrides);
// Result: {
//   api: { timeout: 5000, retries: 3 },
//   features: { auth: true, logging: true }
// }

Object Iteration

Iterate over object properties with support for custom contexts and both forward and reverse iteration.

/**
 * Iterate over object properties
 * @param obj - Object to iterate over
 * @param iterate - Iterator function receiving (value, key, obj)
 * @param context - Optional context for iterator function
 */
function objectEach<T, C = any>(
  obj: T, 
  iterate: (this: C, value: any, key: string, obj: T) => void, 
  context?: C
): void;

/**
 * Reverse iterate over object properties
 * @param obj - Object to iterate over
 * @param iterate - Iterator function receiving (value, key, obj)
 * @param context - Optional context for iterator function
 */
function lastObjectEach<T, C = any>(
  obj: T, 
  iterate: (this: C, value: any, key: string, obj: T) => void, 
  context?: C
): void;

Usage Examples:

import { objectEach, lastObjectEach } from 'xe-utils';

const user = { name: 'Alice', age: 25, city: 'NYC' };

// Forward iteration
objectEach(user, (value, key) => {
  console.log(`${key}: ${value}`);
});
// Output: name: Alice, age: 25, city: NYC

// Reverse iteration
lastObjectEach(user, (value, key) => {
  console.log(`${key}: ${value}`);
});
// Output: city: NYC, age: 25, name: Alice

// With context
const processor = {
  prefix: 'User',
  process(value, key) {
    console.log(`${this.prefix} ${key}: ${value}`);
  }
};

objectEach(user, processor.process, processor);

Object Mapping

Transform object properties by applying a function to each value, creating a new object with the results.

/**
 * Transform object values by applying iterator function
 * @param obj - Object to transform
 * @param iterate - Iterator function receiving (value, key, obj)
 * @param context - Optional context for iterator function
 * @returns New object with transformed values
 */
function objectMap<T, U, C = any>(
  obj: T, 
  iterate: (this: C, value: any, key: string, obj: T) => U, 
  context?: C
): { [key: string]: U };

Usage Examples:

import { objectMap } from 'xe-utils';

const numbers = { a: 1, b: 2, c: 3 };

// Transform values
const doubled = objectMap(numbers, (value) => value * 2);
// Result: { a: 2, b: 4, c: 6 }

// Transform with key information
const withKeys = objectMap(numbers, (value, key) => `${key}:${value}`);
// Result: { a: 'a:1', b: 'b:2', c: 'c:3' }

// Complex transformation
const users = { 
  user1: { name: 'Alice', age: 25 },
  user2: { name: 'Bob', age: 30 }
};

const userSummaries = objectMap(users, (user) => ({
  display: `${user.name} (${user.age})`,
  isAdult: user.age >= 18
}));
// Result: {
//   user1: { display: 'Alice (25)', isAdult: true },
//   user2: { display: 'Bob (30)', isAdult: true }
// }

Install with Tessl CLI

npx tessl i tessl/npm-xe-utils

docs

array-operations.md

base-utilities.md

date-time.md

function-utilities.md

index.md

number-operations.md

object-operations.md

string-processing.md

type-checking.md

web-browser.md

tile.json