npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

save-statistics

v1.0.0

Published

Librería para guardar UUID y enviar texto a una API

Readme

save-statistics

Una librería simple y eficiente para gestionar el envío de textos junto con UUID a APIs. Ideal para aplicaciones que necesitan realizar seguimiento de estadísticas o eventos con identificadores únicos.

Instalación

npm install save-statistics

Características

  • 🔒 Almacenamiento seguro de UUID para identificación
  • 📨 Envío de texto junto con UUID a endpoints API
  • ⚛️ Compatible con React y otras librerías/frameworks
  • 🔄 Manejo de promesas y errores robusto
  • 📝 Completamente tipada con TypeScript

Uso

Configuración básica

import { setUUID, sendText } from 'save-statistics';

// Configura el UUID al iniciar tu aplicación
setUUID('123e4567-e89b-12d3-a456-426614174000');

// Envía texto a la API (función asíncrona)
async function enviarMensaje() {
  try {
    await sendText('Mensaje de prueba');
    console.log('Mensaje enviado correctamente');
  } catch (error) {
    console.error('Error al enviar el mensaje:', error);
  }
}

enviarMensaje();

Uso con React

import React, { useState, useEffect } from 'react';
import { setUUID, sendText } from 'save-statistics';

const MessageForm: React.FC = () => {
  const [message, setMessage] = useState('');
  const [status, setStatus] = useState('');
  const [isLoading, setIsLoading] = useState(false);

  // Configura el UUID al montar el componente
  useEffect(() => {
    // En una aplicación real, este UUID podría venir de:
    // - Un servicio de autenticación
    // - Generarse con una librería como uuid
    // - Recuperarse del localStorage
    setUUID('123e4567-e89b-12d3-a456-426614174000');
  }, []);

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    
    if (!message.trim()) return;
    
    setIsLoading(true);
    setStatus('');
    
    try {
      await sendText(message);
      setStatus('✅ Mensaje enviado correctamente');
      setMessage(''); // Limpiar el campo después de enviar
    } catch (error) {
      if (error instanceof Error) {
        setStatus(`❌ Error: ${error.message}`);
      } else {
        setStatus('❌ Ocurrió un error desconocido');
      }
    } finally {
      setIsLoading(false);
    }
  };

  return (
    <div className="message-form">
      <h2>Enviar mensaje</h2>
      
      {status && <div className={status.includes('Error') ? 'error' : 'success'}>{status}</div>}
      
      <form onSubmit={handleSubmit}>
        <div className="form-group">
          <label htmlFor="message">Mensaje:</label>
          <textarea
            id="message"
            value={message}
            onChange={(e) => setMessage(e.target.value)}
            disabled={isLoading}
            placeholder="Escribe tu mensaje aquí..."
            rows={4}
          />
        </div>
        
        <button 
          type="submit" 
          disabled={isLoading || !message.trim()}
        >
          {isLoading ? 'Enviando...' : 'Enviar'}
        </button>
      </form>
    </div>
  );
};

export default MessageForm;

API

setUUID(uuid: string): void

Guarda un UUID para uso posterior en las llamadas a la API.

  • Parámetros:
    • uuid: String - El UUID a guardar
  • Comportamiento: Almacena el UUID en memoria para usarlo en llamadas posteriores
  • Ejemplo:
    setUUID('123e4567-e89b-12d3-a456-426614174000');

sendText(text: string): Promise<void>

Envía texto junto con el UUID guardado a una API.

  • Parámetros:
    • text: String - El texto a enviar
  • Retorna: Promise que se resuelve sin valor en caso de éxito
  • Lanza: Error si no hay UUID configurado o si la API responde con error
  • Ejemplo:
    try {
      await sendText('Hola mundo');
      console.log('Texto enviado correctamente');
    } catch (error) {
      console.error('Falló el envío:', error);
    }

Flujo de trabajo típico

  1. Al inicializar la aplicación, llama a setUUID() con el identificador único
  2. Cuando necesites enviar un texto, usa sendText()
  3. Maneja posibles errores con bloques try/catch

Configuración avanzada

Para configurar una URL de API personalizada, puedes modificar el archivo index.ts antes de construir la librería:

// En src/index.ts
const API_URL = 'https://tu-api-personalizada.com/endpoint';

Licencia

MIT