Random User Agents

NPM package to generate random user agents effortlessly

Primary Stack:

TypeScript Javascript Vittest Github Action NPM Package
Random User Agents

🛠️ Random User Agents

npm version Github

Description

A simple yet powerful NPM package to generate random user agents effortlessly. Whether you’re working on web scraping, testing, or automation, this tool provides flexibility to create one or many user agents in seconds.


Features

  • Generate single or multiple user agents.
  • Built with TypeScript for type safety and maintainability.
  • Tested with Vitest and formatted with Prettier for consistent code quality.
  • Fully automated CI/CD pipeline via GitHub Actions.

Installation

Run the following command to install the package:

npm i @rahulxf/random-user-agent

Usage

Generate multiple user agents:

import { generateUserAgents } from '@rahulxf/random-user-agent';

// Generate 5 user agents
const userAgents = generateUserAgents(5);
console.log(userAgents);

Example Output:

[
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.350.56 Safari/537.36',
  'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.259.94 Safari/537.36',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.434.38 Safari/537.36'
]

Generate a single user agent:

import { getUserAgent } from '@rahulxf/random-user-agent';

const userAgent = getUserAgent();
console.log(userAgent); // Output: Random user agent string

You can also specify a count:

console.log(getUserAgent(10)); // Outputs an array of 10 user agents

Development & Contribution

If you’d like to contribute or run the project locally:

  1. Clone the repository:

    git clone https://github.com/manzil-infinity180/random-user-agent.git
    cd random-user-agent
    npm install
  2. Run tests:

    npm run test
  3. Ensure changes meet the project’s standards:

    npm run ci

This project uses TypeScript for development, Vitest for testing, and Prettier for formatting. All contributions are welcome!


Technology Stack

  • Languages & Tools: TypeScript, JavaScript, Node.js
  • Testing: Vitest
  • Code Formatting: Prettier
  • Automation: GitHub Actions

Package Details

Here’s an overview of the key NPM scripts included:

ScriptDescription
buildCompiles TypeScript files to JavaScript.
ciRuns all checks (build, format, exports, tests).
formatFormats code using Prettier.
testRuns tests using Vitest.
local-releaseHandles changeset versioning and local publishing.

License

This project is licensed under the MIT License, allowing developers to use, modify, and share freely.