Socket
Book a DemoInstallSign in
Socket

alpha-deca

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alpha-deca

A lightweight JavaScript library for generating random alphanumeric strings and characters

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

Alpha Deca

A lightweight JavaScript library for generating random alphanumeric strings and characters. Perfect for creating IDs, tokens, passwords, or any random string needs.

Features

  • 🚀 Lightweight: No dependencies, minimal footprint
  • 🔧 ES6 Modules: Modern JavaScript with import/export support
  • 🎲 Random Generation: Cryptographically secure random characters
  • 📦 NPM Ready: Easy to install and use in any Node.js project
  • 🎯 Simple API: Clean, intuitive function names

Installation

npm install alpha-deca

Quick Start

import { randomString, randomChar, getAlphanumericChars } from 'alpha-deca';

// Generate a random 8-character string
const id = randomString(8);
console.log(id); // e.g., "A7bK9mN2"

// Generate a single random character
const char = randomChar();
console.log(char); // e.g., "X", "5", "z"

// Get all available alphanumeric characters
const chars = getAlphanumericChars();
console.log(chars); // ['0', '1', '2', ..., '9', 'A', 'B', ..., 'Z', 'a', 'b', ..., 'z']

API Reference

getAlphanumericChars()

Returns an array containing all alphanumeric characters (0-9, A-Z, a-z).

Returns: string[] - Array of alphanumeric characters

import { getAlphanumericChars } from 'alpha-deca';

const chars = getAlphanumericChars();
// Returns: ['0', '1', '2', ..., '9', 'A', 'B', ..., 'Z', 'a', 'b', ..., 'z']

randomChar()

Generates a single random alphanumeric character.

Returns: string - A single random character (0-9, A-Z, a-z)

import { randomChar } from 'alpha-deca';

const char = randomChar();
// Returns: "A", "5", "z", etc.

randomString(length)

Generates a random string of specified length using alphanumeric characters.

Parameters:

  • length (number) - The length of the string to generate

Returns: string - A random string of the specified length

import { randomString } from 'alpha-deca';

// Generate different length strings
const shortId = randomString(4);    // e.g., "K9mN"
const mediumId = randomString(8);   // e.g., "A7bK9mN2"
const longId = randomString(16);    // e.g., "X5kL8mN2pQ9rS3tU"

randomNumber(length)

Generates a random string of specified length using only numeric characters (0-9).

Parameters:

  • length (number) - The length of the string to generate

Returns: string - A random numeric string of the specified length

import { randomNumber } from 'alpha-deca';

const num = randomNumber(6);
// Returns: "847392"

const shortNum = randomNumber(2);
// Returns: "45"

Use Cases

Generate Unique IDs

import { randomString } from 'alpha-deca';

const userId = randomString(12);
const sessionId = randomString(16);
const orderId = randomString(8);

Create Temporary Passwords

import { randomString } from 'alpha-deca';

const tempPassword = randomString(10);
console.log(`Your temporary password is: ${tempPassword}`);

Generate API Keys

import { randomString } from 'alpha-deca';

const apiKey = randomString(32);
console.log(`API Key: ${apiKey}`);

Create Random Tokens

import { randomString } from 'alpha-deca';

const resetToken = randomString(24);
const verificationCode = randomString(6);

Generate Numeric Codes

import { randomNumber } from 'alpha-deca';

const pinCode = randomNumber(4);        // e.g., "8473"
const orderNumber = randomNumber(8);    // e.g., "56715382"
const verificationCode = randomNumber(6); // e.g., "123456"

Browser Usage

This package works in modern browsers that support ES6 modules:

<script type="module">
  import { randomString } from 'https://unpkg.com/alpha-deca@1.0.0/app.js';
  
  const id = randomString(8);
  console.log(id);
</script>

Development

Prerequisites

  • Node.js >= 14.0.0

Setup

git clone https://github.com/decagondev/alpha-deca.git
cd alpha-deca
npm install

Available Scripts

npm test      # Run tests
npm run lint  # Lint code
npm run format # Format code

Contributing

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

1.0.0

  • Initial release
  • Added getAlphanumericChars() function
  • Added randomChar() function
  • Added randomString() function
  • Added randomNumber() function

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Made with ❤️ for the JavaScript community

Keywords

random

FAQs

Package last updated on 27 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts