randbox
v1.0.0
Published
RandBox - Utility library to generate anything random with TypeScript support
Maintainers
Readme
RandBox Modular Structure
This directory contains the modularized version of RandBox, split into separate ES6 modules for better maintainability and tree-shaking support.
Module Structure
Core Module (core.js)
Contains the main RandBox constructor, constants, utility functions, and core dependencies that other modules depend on.
Exports:
RandBox- Main constructor- Constants:
MAX_INT,MIN_INT,NUMBERS,CHARS_LOWER,CHARS_UPPER,HEX_POOL - Utilities:
initOptions,testRange,range,base64,UnsupportedError
Feature Modules
Each module contains related functionality and can be imported individually:
Basics (
basics.js) - Core random generationbool,character,floating,integer,natural,string,buffer,hex
Helpers (
helpers.js) - Array and utility functionscapitalize,mixin,unique,n,pad,pick,pickone,pickset,shuffle,weighted
Text (
text.js) - Text generationparagraph,sentence,syllable,word,emoji
Person (
person.js) - People-related dataage,birthday,first,last,name,gender,ssn,animal, etc.
Mobile (
mobile.js) - Mobile device identifiersandroid_id,apple_token,wp8_anid2,wp7_anid,bb_pin
Web (
web.js) - Web-related dataavatar,color,domain,email,ip,url,hashtag, etc.
Location (
location.js) - Geographic dataaddress,city,country,coordinates,latitude,longitude,phone, etc.
Finance (
finance.js) - Financial datacc,currency,dollar,euro,iban,luhn_check, etc.
Music (
music.js) - Music-related datanote,chord,tempo,music_genre
Miscellaneous (
miscellaneous.js) - Various utilitiescoin, dice functions (d4,d6, etc.),guid,hash, date functions,normal
Usage
Import Everything (Equivalent to Original)
import RandBox from './src/index.js';
const randBox = new RandBox();
console.log(randBox.name()); // Works exactly like the originalImport Specific Modules (Tree Shaking)
import { RandBox, basicsFunctions } from './src/core.js';
import { name, email } from './src/person.js';
// Use individual functions
console.log(name()); // Direct function call
// Or extend a RandBox instance with specific modules
const randBox = new RandBox();
Object.assign(randBox, { name, email });
console.log(randBox.name());Import Individual Functions
import { name } from './src/person.js';
import { email } from './src/web.js';
import { natural } from './src/basics.js';
// Use directly (note: 'this' context will need to be bound to a RandBox instance)Benefits
- Tree Shaking: Bundle only the functions you need
- Maintainability: Related functions are grouped together
- Modularity: Easy to add new modules or modify existing ones
- ES6 Compatibility: Modern JavaScript module system
- Backwards Compatibility:
index.jsprovides the same API as the original
Dependencies
Each module imports only what it needs from core.js, minimizing dependencies and enabling better optimization.
