Skip to content

alobuuls/free-alerts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”” free-alerts

free-alerts


πŸ“‘ Table of Contents


🌐 Links

πŸš€ Demo

Open Demo

πŸ“¦ NPM Package

View on NPM

πŸ’» Repository

GitHub Repository

πŸ“– Description

Note

free-alerts is a lightweight JavaScript library designed to display modern notifications, alerts, and confirmation dialogs with a simple and intuitive API.

The library was created to provide a clean user experience without external dependencies, making it easy to integrate into any JavaScript application or framework.


✨ Features

  • πŸ”” Toast notifications
  • βœ… Success notifications
  • ❌ Error notifications
  • ⚠️ Warning notifications
  • ℹ️ Info notifications
  • πŸ“’ Alert dialogs
  • ❓ Confirmation dialogs
  • πŸš€ Zero dependencies
  • 🎨 Customizable through CSS
  • πŸ“¦ Framework agnostic
  • ⚑ Lightweight and fast
  • πŸ§ͺ Tested with Vitest
  • 🌍 Browser compatible
  • πŸ”§ Easy integration

βš™οΈ System Requirements

Before using the library, make sure you have:

  • 🌐 Modern browser
  • πŸ“¦ Node.js (for package installation)
  • πŸ“¦ npm

πŸš€ Installation

Install from NPM

npm install free-alerts

▢️ Quick Start

import FreeAlerts from 'free-alerts';
import 'free-alerts/style';

FreeAlerts.success('Operation completed successfully');

🌍 CDN Usage

CSS

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/free-alerts@1.0.0/dist/free-alerts.css" />

JavaScript

<script src="https://cdn.jsdelivr.net/npm/free-alerts@1.0.0/dist/free-alerts.umd.js"></script>

Example

<button id="btn">Show Toast</button>

<script>
  document.getElementById('btn').addEventListener('click', () => {
    FreeAlerts.success('Hello World!');
  });
</script>

πŸ“š API Reference

Method Description
success(message, options) 🟒 Shows a success notification
error(message, options) πŸ”΄ Shows an error notification
warning(message, options) 🟑 Shows a warning notification
info(message, options) πŸ”΅ Shows an info notification
alert(options) πŸͺŸ Opens an informational modal
confirm(options) ❓ Opens a confirmation modal

πŸ”” Toast Methods

The following methods display temporary notifications:

FreeAlerts.success();
FreeAlerts.error();
FreeAlerts.warning();
FreeAlerts.info();

🧩 Parameters

message: string

options?: {
  duration?: number
}

🟒 Success

FreeAlerts.success('User created successfully');

πŸ”΄ Error

FreeAlerts.error('Unexpected error occurred');

🟑 Warning

FreeAlerts.warning('Please complete all fields');

πŸ”΅ Info

FreeAlerts.info('New version available');

⏱️ Custom Duration

FreeAlerts.success('Saved correctly', {
  duration: 5000,
});

πŸ“’ Alert Method

Displays an informational modal dialog.

🧩 Parameters

{
  title?: string;
  message?: string;
}

Example

FreeAlerts.alert({
  title: 'Attention',
  message: 'This action cannot be undone.',
});

❓ Confirm Method

Displays a confirmation dialog and returns a Promise.

Parameters

{
  title?: string;
  message?: string;
}

Return Type

Promise<boolean>;

Example

const confirmed = await FreeAlerts.confirm({
  title: 'Delete User',
  message: 'Are you sure you want to continue?',
});

if (confirmed) {
  console.log('Confirmed');
}

πŸ’‘ Usage Examples

Form Submission

document.getElementById('form').addEventListener('submit', () => {
  FreeAlerts.success('Form submitted successfully');
});

Error Handling

try {
  await saveData();
} catch {
  FreeAlerts.error('Failed to save data');
}

Delete Confirmation

const confirmed = await FreeAlerts.confirm({
  title: 'Delete Record',
  message: 'This action cannot be undone.',
});

if (confirmed) {
  deleteRecord();
}

βš›οΈ React Example

import FreeAlerts from 'free-alerts';
import 'free-alerts/style';

function App() {
  const handleClick = () => {
    FreeAlerts.success('Saved from React');
  };

  return <button onClick={handleClick}>Save</button>;
}

export default App;

πŸ…°οΈ Angular Example

There are two ways to use FreeAlerts in Angular depending on TypeScript configuration.


🧩 Option 1 β€” Using @ts-ignore

import { Component } from '@angular/core';

// @ts-ignore
import FreeAlerts from 'free-alerts';

// @ts-ignore
import 'free-alerts/style';

@Component({
  selector: 'app-root',
  template: '<button (click)="showAlert()">Show alert</button>',
})
export class AppComponent {
  showAlert(): void {
    FreeAlerts.success('test');
  }
}

🧩 Option 2 β€” Recommended (Type Declarations)

πŸ“ Type Setup

Create the TypeScript declaration file:

src/types/free-alerts.d.ts
// This is for the FreeAlerts  ↓
declare module 'free-alerts' {
  const FreeAlerts: {
    success(message: string, options?: Record<string, any>): void;
    error(message: string, options?: Record<string, any>): void;
    warning(message: string, options?: Record<string, any>): void;
    info(message: string, options?: Record<string, any>): void;
    alert(options: { title?: string; message?: string }): void;
    confirm(options: { title?: string; message?: string }): Promise<boolean>;
  };
  export default FreeAlerts;
}

// This is for the styles  ↓
declare module 'free-alerts/style';

⚑ Angular Usage

import { Component } from '@angular/core';

//  Imports here ↓
import FreeAlerts from 'free-alerts';
import 'free-alerts/style';

@Component({
  selector: 'app-root',
  template: '<button (click)="showAlert()">Show alert</button>',
})
export class AppComponent {
  showAlert(): void {
    FreeAlerts.success('test');
  }
}

πŸ’‘ Notes

  • No @ts-ignore needed when using .d.ts files
  • Keeps Angular clean and fully typed

πŸ’š Vue Example

<template>
  <button @click="notify">Notify</button>
</template>

<script setup>
import FreeAlerts from 'free-alerts';
import 'free-alerts/style';

function notify() {
  FreeAlerts.success('Saved from Vue');
}
</script>

πŸ§ͺ Testing

The library includes unit tests using Vitest.

Run Tests

npm run test

Example Test

import { describe, it, expect } from 'vitest';
import FreeAlerts from '../src/index.js';

describe('FreeAlerts.alert', () => {
  it('should create modal', () => {
    FreeAlerts.alert({
      title: 'Error',
      message: 'Something happened',
    });

    const modal = document.querySelector('.free-alerts-modal');

    expect(modal).not.toBeNull();
  });
});

πŸ“ Project Structure

free-alerts/
β”œβ”€β”€ demo/
β”‚   β”œβ”€β”€ dev/
β”‚   β”‚   β”œβ”€β”€ app.js
β”‚   β”‚   β”œβ”€β”€ index.html
β”‚   β”‚   └── styles.css
β”‚   └── prod/
β”‚       β”œβ”€β”€ app.js
β”‚       β”œβ”€β”€ index.html
β”‚       └── styles.css
β”‚
β”œβ”€β”€ dist/
β”‚   β”œβ”€β”€ free-alerts.css
β”‚   β”œβ”€β”€ free-alerts.mjs
β”‚   └── free-alerts.umd.js
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   └── preview.png
β”‚   β”‚
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ alert.js
β”‚   β”‚   β”œβ”€β”€ confirm.js
β”‚   β”‚   β”œβ”€β”€ createElement.js
β”‚   β”‚   └── toast.js
β”‚   β”‚
β”‚   β”œβ”€β”€ styles/
β”‚   β”‚   └── free-alerts.css
β”‚   β”‚
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   β”œβ”€β”€ constants.js
β”‚   β”‚   └── icons.js
β”‚   β”‚
β”‚   └── index.js
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ alert.test.js
β”‚   β”œβ”€β”€ confirm.test.js
β”‚   └── setup.js
β”‚
β”œβ”€β”€ package.json
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ vite.config.js
β”œβ”€β”€ vitest.config.js
β”œβ”€β”€ LICENSE
└── README.md

πŸ”₯ Best Practices

  • Use success notifications for successful operations
  • Use error notifications for failures
  • Use confirm dialogs before destructive actions
  • Keep messages concise and meaningful
  • Avoid excessive notifications
  • Maintain consistent user feedback
  • Provide clear action outcomes

🀝 Contributing

Contributions are welcome.

Clone Repository

git clone git@github.com:alobuuls/free-alerts.git

Install Dependencies

npm install

Start Development Mode

npm run dev

Run Tests

npm run test

Build Package

npm run build

If you find bugs, have ideas for improvements, or want to contribute new features, feel free to open an issue or submit a pull request.


πŸ“„ License

This project is intended for educational and portfolio purposes.

Created by Alondra Francisco.

About

A lightweight JavaScript library for toasts, alerts, and confirmations. Enhance your user experience with modern, quick notifications.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors