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

@jysperu/helper-commons

v1.2.1

Published

Funciones generales

Downloads

306

Readme

@jysperu/helper-commons

npm version npm downloads License: MIT TypeScript Bundle Size

Librería de utilidades comunes para proyectos TypeScript/JavaScript con funciones de logging, manipulación de fechas y utilidades generales.

🚀 Características

  • 🔧 TypeScript completamente tipado
  • Funciones optimizadas para manipulación de fechas Unix
  • 🚩 Logging con timestamps y niveles
  • 📊 Utilidades de tiempo (hora anterior/siguiente, día, mes, año)
  • 📅 Formateo de fechas personalizable
  • 🔄 Funciones asíncronas de utilidad (sleep, noop)
  • 🌍 Re-exporta librerías de navegador (alert, cookie, api)

📦 Instalación

npm install @jysperu/helper-commons

⚡ Inicio Rápido

import { log, log$info, log$warn, log$error, unixtime, today, momento, sleep, prevday, nextday, prevhour, nexthour } from "@jysperu/helper-commons";

// Logging con diferentes niveles
log("Mensaje simple");
log$info("Información con timestamp");
log$warn("Advertencia con timestamp");
log$error("Error con timestamp");

// Utilidades de fecha y tiempo
const ahora = unixtime(); // Timestamp Unix actual
const ayer = prevday(); // Ayer en timestamp Unix
const mañana = nextday(); // Mañana en timestamp Unix

// Formateo de fechas
console.log(today()); // "2025-11-17"
console.log(today("/")); // "2025/11/17"
console.log(momento()); // "DOM 17NOV2025 2:30:45 PM"

// Utilidades asíncronas
await sleep(2); // Pausa 2 segundos

📚 API Reference

🔤 Funciones de Logging

log(...messages)

Logging básico sin timestamp.

log("Mensaje", "otro mensaje", { objeto: true });

log$info(...messages)

Log de información con timestamp.

log$info("Información importante");

log$warn(...messages)

Log de advertencia con timestamp.

log$warn("Advertencia del sistema");

log$error(...messages)

Log de error con timestamp.

log$error("Error crítico", error);

⏰ Funciones de Tiempo

unixtime()

Obtiene el timestamp Unix actual.

const ahora = unixtime(); // 1700227845

time()

Obtiene el timestamp en milisegundos.

const ms = time(); // 1700227845123

unixtime2date(timestamp?)

Convierte timestamp Unix a objeto Date.

const fecha = unixtime2date(1700227845);
const ahoraComoDate = unixtime2date(); // usa timestamp actual

📅 Manipulación de Fechas

Funciones de navegación temporal:

// Horas
prevhour(timestamp?, setminute0?) // Hora anterior
nexthour(timestamp?, setminute0?) // Hora siguiente

// Días
prevday(timestamp?) // Día anterior
nextday(timestamp?) // Día siguiente

// Meses
prevmonth(timestamp?) // Mes anterior
nextmonth(timestamp?) // Mes siguiente

// Años
prevyear(timestamp?) // Año anterior
nextyear(timestamp?) // Año siguiente

nearlyday(timestamp, day, afterToday?)

Encuentra la fecha más cercana con el día especificado.

const proximoDia15 = nearlyday(unixtime(), 15); // Próximo día 15 del mes

📊 Extracción de Fecha

unixtime2day(timestamp); // Extrae día (1-31)
unixtime2month(timestamp); // Extrae mes (1-12)
unixtime2year(timestamp); // Extrae año (ej: 2025)

🔄 Formateo

today(separator?)

Fecha actual formateada.

today(); // "2025-11-17"
today("/"); // "2025/11/17"
today("."); // "2025.11.17"

momento()

Timestamp formateado en timezone de Lima.

momento(); // "DOM 17NOV2025 2:30:45.123 PM"

🛠️ Utilidades

sleep(seconds)

Pausa asíncrona.

await sleep(1.5); // Pausa 1.5 segundos

noop()

Función vacía asíncrona.

await noop(); // No hace nada, útil como placeholder

isodate2unixtime(isoDate)

Convierte fecha ISO a timestamp Unix.

const unix = isodate2unixtime("2025-11-17T14:30:00Z");
const unix2 = isodate2unixtime(new Date());

🌍 Re-exports

Esta librería también re-exporta las siguientes utilidades de browser:

Alertas (desde @jysperu/browser-alert)

import {
  alert_loading,
  alert_confirm,
  alert_message,
  alert_success,
  alert_error,
  alert_info,
  alert_warning,
  alert_close,
} from "@jysperu/helper-commons";

Cookies (desde @jysperu/browser-cookie)

import { getCookie, setCookie, delCookie, getCookies, delCookies, cookieExists } from "@jysperu/helper-commons";

API (desde @jysperu/helper-fetcher)

import { api, api_get, api_post, api_request } from "@jysperu/helper-commons";

🌍 Compatibilidad

  • ✅ Todos los navegadores modernos
  • ✅ Compatible con frameworks (React, Vue, Angular, Svelte)
  • ✅ Node.js y entornos SSR
  • ✅ TypeScript nativo
  • ✅ ES Modules y CommonJS

🔗 Enlaces y Recursos

📄 Licencia

MIT License - Consulta el archivo LICENSE para detalles completos.

MIT License - Copyright (c) 2025 JYS Perú

Desarrollado con ❤️ por JYS Perú