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

npm-shortidx

v1.4.1

Published

Generador de Id aleatorios, Random Id Generator

Readme

npm-shortidx

npm-shortidx es una librería para generar identificadores aleatorios cortos. Incluye funciones para generar IDs con diferentes conjuntos de caracteres y para reordenar arrays de manera aleatoria.

⚠️ Nota de Versión 1.4.0

A partir de la versión 1.4.0, todas las funciones de generación de IDs (ShortIdx, RandomIdx, etc.) utilizan crypto.getRandomValues para una aleatoriedad criptográficamente segura.

Sin embargo, para contraseñas, seguimos recomendando usar PasswordGen ya que ofrece una API específica para configuración de seguridad.

Tabla de Contenidos

Instalación

npm i npm-shortidx
yarn add npm-shortidx

Métodos

🛡️ Seguridad

Desde la versión 1.4.0, esta librería utiliza crypto.getRandomValues (Web Crypto API) internamente para todas las operaciones de aleatoriedad.

  • IDs Seguros: ShortIdx, RandomIdx y CustomIdx generan identificadores con alta entropía y aleatoriedad criptográfica.
  • Contraseñas: PasswordGen está optimizada específicamente para generar contraseñas seguras.
ShortIdx(),
  RandomIdx(),
  CustomIdx(),
  RepeatIdx(),
  ShuffleX(),
  IndexShuffle(),
  ShuffleString(),
  PasswordGen();

ShortIdx()

Genera IDs aleatorios con caracteres alfanuméricos.

Caracteres usados:

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_

Uso:

import { ShortIdx } from "npm-shortidx";

ShortIdx(); // "G7ksLzW"
ShortIdx(12); // "AdE8fsU1KqpQ"

RandomIdx()

Genera IDs aleatorios que incluyen símbolos y caracteres especiales.

Caracteres usados:

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_!#$%&'()*+,./:;<=>?@[]^`{|}~\"

Uso:

import { RandomIdx } from "npm-shortidx";

RandomIdx(); // "s@L!z82_"
RandomIdx(10); // "*>d3@9x^Z!"

CustomIdx()

Genera un ID usando un conjunto de caracteres personalizado.

import { CustomIdx } from "npm-shortidx";

CustomIdx("ABC123", 5); // "2B1AC"

RepeatIdx()

Genera múltiples IDs de forma masiva.

import { RepeatIdx, ShortIdx } from "npm-shortidx";

RepeatIdx(4, ShortIdx); // ["R3f7tK1", "gTz1xL9", ...]
RepeatIdx(3, RandomIdx, 10); // ["<xD&0j9@#", "2K!lm8$@#", ...]

ShuffleX()

Reordena arrays de forma aleatoria.

import { ShuffleX } from "npm-shortidx";

const items = ["a", "b", "c", "d"];
ShuffleX(items); // ['c', 'a', 'd', 'b']
ShuffleX(items, 2); // ['b', 'd']

IndexShuffle()

Devuelve un array de índices aleatorios.

import { IndexShuffle } from "npm-shortidx";

IndexShuffle(5); // [2, 0, 4, 1, 3]

ShuffleString()

Desordena los caracteres de un string.

import { ShuffleString } from "npm-shortidx";

ShuffleString("abcdef"); // "ecdbfa"

¿Qué función debo usar?

| Caso de uso | Función | | --------------------------------- | --------------- | | IDs cortos y ligeros | ShortIdx | | IDs con símbolos | RandomIdx | | IDs con charset personalizado | CustomIdx | | Generar múltiples IDs | RepeatIdx | | Barajar arrays sin mutarlos | ShuffleX | | Obtener índices aleatorios | IndexShuffle | | Reordenar caracteres de un string | ShuffleString | | Generar contraseñas seguras | PasswordGen |


Ejemplos

Uso en React

import { ShortIdx } from "npm-shortidx";

function App() {
  const letters = ["a", "b", "c", "d"];
  return (
    <>
      <p>{ShortIdx()}</p>
      {letters.map((letter) => (
        <p key={ShortIdx()}>{letter}</p>
      ))}
    </>
  );
}

Cambiando la longitud del ID

ShortIdx(15); // "Kz83kJqsTg92Lm1"

Generando múltiples IDs

RepeatIdx(5, RandomIdx, 10); // ['@d8Lz!pZ3x', '29&Lk1@9Tq', ...]

Reordenando caracteres de un string

ShuffleString("hola mundo"); // "ouh nldma"

PasswordGen()

Genera contraseñas aleatorias utilizando una fuente de aleatoriedad criptográficamente segura (crypto.getRandomValues).

Uso recomendado:

  • Contraseñas
  • Tokens de seguridad
  • Claves temporales sensibles

No recomendado para:

  • IDs visuales
  • Keys de UI
  • Slugs

Por defecto, el generador utiliza únicamente letras ASCII:

  • a–z
  • A–Z

Esto garantiza compatibilidad máxima con cualquier sistema.

Caracteres por defecto:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

Si necesitas números, símbolos o caracteres Unicode, agrégalos explícitamente mediante extraChars .

Uso:

import { PasswordGen } from "npm-shortidx";

PasswordGen();
// Ejemplo: "A9kP2Lm8Qx1Z" (Alfanumérico por defecto)

PasswordGen({
  extraChars: "!@#$%"
});
// Ejemplo con símbolos: "A9$kP2@Lm8#Qx1!Z"

PasswordGen({
  length: 24,
});

PasswordGen({
  extraChars: "_-+=",
});

PasswordGen está diseñada para seguridad. Usa esta función siempre que necesites una contraseña real.


Contribuciones

¡Las contribuciones son bienvenidas! Siéntete libre de abrir un issue o enviar un pull request.


Licencia

MIT