ModApp Utilities

1.8.0 · active · verified Sun Apr 19

ModApp Utilities (modapp-utils) provides a collection of generic utility functions intended for use across the broader ModApp ecosystem of JavaScript packages. These utilities typically cover common programming patterns such as object manipulation (e.g., deep merging, cloning), array helpers, string transformations, event debouncing/throttling, and unique ID generation. As of version 1.8.0, it serves as a foundational library, abstracting common logic to ensure consistency and reduce boilerplate in related ModApp projects. The package does not explicitly detail its release cadence, but incremental updates can be expected to support the evolving ModApp framework. Its key differentiator is its tailored integration and consistency within the ModApp architecture, rather than offering novel utility functions compared to broader libraries like Lodash or Ramda.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates importing and using a `debounce` function for event handling, a `mergeDeep` function for recursively combining objects, and a `generateUUID` function for creating unique identifiers. It sets up a simple debounced search input in the browser and logs merged configuration and a new UUID to the console.

import { debounce, mergeDeep, generateUUID } from 'modapp-utils';

// Example 1: Debouncing a function
const searchInputHandler = (query) => {
  console.log('Searching for:', query);
  // Simulate API call
};
const debouncedSearch = debounce(searchInputHandler, 500);

document.addEventListener('DOMContentLoaded', () => {
  const input = document.createElement('input');
  input.placeholder = 'Type to search (debounced)';
  input.onkeyup = (event) => debouncedSearch(event.target.value);
  document.body.appendChild(input);

  // Example 2: Deep merging objects
  const defaultConfig = { host: 'localhost', port: 8080, db: { user: 'guest', pass: 'guest' } };
  const userConfig = { port: 3000, db: { user: 'admin' }, api: { key: process.env.API_KEY ?? '' } };
  const mergedConfig = mergeDeep(defaultConfig, userConfig);
  console.log('Merged Configuration:', mergedConfig);

  // Example 3: Generating a UUID
  const newId = generateUUID();
  console.log('Generated UUID:', newId);

  // Cleanup for demonstration purposes
  setTimeout(() => {
    console.log('Demonstration complete. Open your browser console.');
    input.remove();
  }, 2000);
});

view raw JSON →