MyLib Reference

Introduction

Welcome to the MyLib reference documentation. MyLib provides a set of utilities to simplify data processing, networking, and UI rendering in modern web applications.

Installation

Install MyLib via npm:

npm install mylib --save

Or include it directly via CDN:

<script src="https://cdn.example.com/mylib/1.0.0/mylib.min.js"></script>

API Overview

MyLib exposes three main namespaces:

  • mylib.utils – Helper functions for data manipulation.
  • mylib.net – Simplified HTTP client.
  • mylib.ui – Components for building UI.

Functions

mylist.utils.clone(obj)

Creates a deep copy of an object.

const copy = mylib.utils.clone(originalObj);

mylist.utils.isEmpty(value)

Returns true if the value is null, undefined, an empty string, or an empty array.

if (mylib.utils.isEmpty(data)) { /* handle empty */ }

Classes

mylist.net.HttpClient

Simple wrapper around fetch with built‑in JSON handling and timeout support.

const client = new mylib.net.HttpClient({ baseURL: '/api', timeout: 5000 });
client.get('/users')
      .then(res => console.log(res))
      .catch(err => console.error(err));

mylist.ui.Modal

Creates a modal dialog with customizable content and actions.

const modal = new mylib.ui.Modal({
    title: 'Confirm Delete',
    content: 'Are you sure you want to delete this item?',
    confirmText: 'Delete',
    cancelText: 'Cancel',
    onConfirm: () => {/* delete logic */}
});
modal.open();

Examples

Below is a simple example of using MyLib to fetch data and display it in a modal.

// Initialize client
const api = new mylib.net.HttpClient({ baseURL: '/api' });

// Fetch user info
api.get('/user/42')
   .then(user => {
       const modal = new mylib.ui.Modal({
           title: `User: ${user.name}`,
           content: `

Email: ${user.email}

`, confirmText: 'Close', onConfirm: () => modal.close() }); modal.open(); }) .catch(err => console.error('Failed to load user', err));