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 🙏

© 2026 – Pkg Stats / Ryan Hefner

segmentslibrary

v1.1.1

Published

A React library for segment displays

Readme

Documentación del Componente Segments

Link del repositorio Link de la libreria

Licencia

MIT License

Copyright (c) 2025

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Descripción

El componente Segments permite mostrar un display de segmentos al estilo de relojes digitales o pantallas de calculadoras. Es altamente configurable y admite distintos tamaños, colores y estilos de segmentos.

Instalación

Para usar este componente en tu proyecto, primero instala la librería:

npm install segmentslibrary

Luego, impórtalo en tu código:

import Segments from "segmentslibrary";

Props del Componente

| Propiedad | Tipo | Descripción | |------------------------|---------|-------------| | id | String | Identificador único del display (por defecto "1"). | | pattern | String | Patrón del display (ej. "#####", "##:##:##"). | | textopredefinido | String | Texto inicial que se mostrará en el display. | | width | Number | Ancho del canvas (px). | | height | Number | Alto del canvas (px). | | colorOn | String | Color de los segmentos activos. | | colorOff | String | Color de los segmentos inactivos. | | cantidadSegmentos | Number | Cantidad de segmentos (7, 14 o 16). | | altoDisplay | Number | Altura de los dígitos. | | anchoDisplay | Number | Ancho de los dígitos. | | distanciaEntreDigitos | Number | Espacio entre los dígitos. | | anchoSegmento | Number | Ancho de los segmentos. | | distanciaSegmento | Number | Distancia entre los segmentos. | | tipoBorde | Number | Tipo de borde (0, 1, 2 o 3). | | anguloDisplay | Number | Ángulo de inclinación del display. |

Ejemplo: Crear un Reloj Digital

Para mostrar un reloj en tiempo real con este componente:

import React, { useState, useEffect } from 'react';
import Segments from 'segmentslibrary';  // Ajusta la ruta según tu estructura de archivos

const DigitalClock = () => {
  const [time, setTime] = useState('');

  useEffect(() => {
    const formatTime = (date) => {
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      const seconds = date.getSeconds().toString().padStart(2, '0');
      return `${hours}:${minutes}:${seconds}`;
    };

    setTime(formatTime(new Date()));

    const intervalId = setInterval(() => {
      setTime(formatTime(new Date()));
    }, 1000);

    return () => clearInterval(intervalId);
  }, []);

  return (
    <div className="digital-clock">
      <Segments
        id="reloj"
        textopredefinido={time}
        pattern="##:##:##"
        width={400}
        height={200}
        colorOn="#ff5555"
        colorOff="#33333330"
        altoDisplay={30}
        anchoDisplay={18}
        distanciaEntreDigitos={3}
        anchoSegmento={3.5}
        cantidadSegmentos={7}
        anguloDisplay={7}
      />
    </div>
  );
};

export default DigitalClock;

Ejemplo: Animación de Palabra Letra por Letra

Para animar una palabra letra por letra con parpadeo:

import React, { useState, useEffect } from 'react'; 
import Segments from 'segmentslibrary';  // Ajusta la ruta según tu estructura de archivos

const AnimatedSegments = ({
  text = "TUTEC",
  animationSpeed = 500,
  blinkCount = 2,
  id = "animated"
}) => {
  const [displayText, setDisplayText] = useState('');
  const [index, setIndex] = useState(0);
  const [blinkPhase, setBlinkPhase] = useState(0);

  useEffect(() => {
    const animate = () => {
      if (index <= text.length) {
        setDisplayText(text.substring(0, index));
        setIndex(prev => prev + 1);
      } else if (blinkPhase < blinkCount * 2) {
        if (blinkPhase % 2 === 0) {
          setDisplayText('     ');
        } else {
          setDisplayText(text);
        }
        setBlinkPhase(prev => prev + 1);
      } else {
        setIndex(0);
        setBlinkPhase(0);
      }
    };

    const intervalId = setInterval(animate, animationSpeed);
    return () => clearInterval(intervalId);
  }, [text, animationSpeed, blinkCount, index, blinkPhase]);

  return (
    <Segments
      id={id}
      textopredefinido={displayText}
      pattern="#####"
      width={300}
      height={180}
      colorOn="#4d91cd"
      colorOff="#53595e45"
      cantidadSegmentos={14}
      altoDisplay={23.5}
      anchoDisplay={14.5}
      distanciaEntreDigitos={2.5}
      anchoSegmento={3}
      distanciaSegmento={0.3}
      tipoBorde={3}
      anguloDisplay={6}
    />
  );
};

export default AnimatedSegments;

Ejemplo de Manejo de Errores

Si se proporciona un valor incorrecto en cantidadSegmentos, el componente lo corregirá automáticamente a 7, 14 o 16.

<Segments cantidadSegmentos={10} />  // Se corregirá a 7

Este componente es ideal para paneles de control, relojes digitales, y más. 🚀