Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

randexp

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

randexp

Create random strings that match a given regular expression.

  • 0.5.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5M
decreased by-20.78%
Maintainers
1
Weekly downloads
 
Created

What is randexp?

The randexp npm package is used to generate random strings that match a given regular expression. This can be useful for testing, generating mock data, or any scenario where you need random but structured strings.

What are randexp's main functionalities?

Generate Random String from Regex

This feature allows you to generate a random string that matches a given regular expression. In this example, the generated string will match the pattern 'hello+ (world|to you)'.

const RandExp = require('randexp');
const randexp = new RandExp(/hello+ (world|to you)/);
console.log(randexp.gen());

Custom Randomness

You can customize the randomness by overriding the `randInt` method. In this example, the `randInt` method is overridden to always return the lower bound, making the output deterministic.

const RandExp = require('randexp');
const randexp = new RandExp(/hello+ (world|to you)/);
randexp.randInt = (a, b) => a; // Always return the lower bound
console.log(randexp.gen());

Using Flags

RandExp supports regex flags such as case insensitivity. In this example, the 'i' flag makes the regex case insensitive.

const RandExp = require('randexp');
const randexp = new RandExp(/hello+ (world|to you)/i); // Case insensitive
console.log(randexp.gen());

Other packages similar to randexp

Keywords

FAQs

Package last updated on 21 Jul 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc