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 🙏

© 2024 – Pkg Stats / Ryan Hefner

randcraft

v1.0.1

Published

A utility library for generating random numbers, strings, and validating phone numbers across various formats.

Downloads

6

Readme

Randcraft

A utility library for generating random numbers, strings, and validating phone numbers. Randcraft provides developers with essential functions to handle randomness and phone number validation making it easier to integrate these features into applications.

Features

  • Generate Random Numbers: Easily create random integers and floating-point numbers within specified ranges.
  • Generate Random Strings: Create random strings with customizable lengths and character sets.
  • Phone Number Validation: Validate phone numbers based on various international formats, ensuring they conform to the correct structure for different countries.

Phone Number Validation

The phone number validation function allows you to verify if a given phone number is valid according to specific country formats. Supported countries include:

  • United States: Formats like (123) 456-7890 or 123-456-7890
  • United Kingdom: Formats like +447123456789 or 07123 456789
  • Georgia: Formats like +995 5XX XXX XXX or +9955XX-XXX-XXX
  • And more: The library supports validation for multiple popular countries.

Usage

To use the library, first install it via npm:

npm install randcraft

Importing Functions

Using CommonJS (Node.js) const { generateRandomNumber, generateRandomString, validatePhoneNumber } = require('randcraft');

Using ES6 Modules If you're using a module bundler or an environment that supports ES6 modules, you can import the library as follows: import { generateRandomNumber, generateRandomString, validatePhoneNumber } from 'randcraft';

Public Methods validatePhoneNumber(phoneNumber, country = 'GE') Validates a phone number based on common patterns for different countries. The country parameter can be specified to validate against a specific country's format (default is Georgia). The function also allows validation without the country code.

Parameters:

phoneNumber (string): The phone number to validate. country (string, optional): The country code (default is 'GE' for Georgia). Returns: true if the phone number is valid; otherwise, false. console.log(validatePhoneNumber("+995 599 123 456")); // true (valid Georgian number) console.log(validatePhoneNumber("599 123 456")); // true (valid Georgian number without country code) console.log(validatePhoneNumber("+1 123 456 7890", 'US')); // true (valid US number)

Parameters:

min (number): The minimum value (inclusive). max (number): The maximum value (inclusive). Returns: A random integer between min and max.

Example: const randomNumber = generateRandomNumber(1, 100); console.log(randomNumber); // Example output: 42

generateRandomString(length) Generates a random string of the specified length using alphanumeric characters.

Parameters:

length (number): The length of the generated string. Returns: A random alphanumeric string.

Example: const randomString = generateRandomString(10); console.log(randomString); // Example output: 'a1b2c3d4e5' License This project is licensed under the MIT License. Author Arsen Akhalaia