Giter VIP home page Giter VIP logo

random.js's Introduction

random

standard-readme compliant

Can randomly generate a specified type of string, support a variety of length, character composition types

Table of Contents

Install

CNPM

cnpm i comsvr-random --save

NPM

npm i comsvr-random --save

YARN

yarn add comsvr-random

PNPM

pnpm add comsvr-random

Usage

Introduce

Control the generated random string by passing in parameters such as type length options to function generateRandomStr

Argument

generateRandomStr(type, length, options = {mix, customScope, mixCustomScope})
  • type: Used to specify the range of characters in the resulting random string, which is specified by reference to an enumeration of RandomType.There are mainly the following areas:
    • RandomType.IntRandom: All numbers from 0 to 9
    • RandomType.LowerRandom: All lowercase letters from A to Z
    • RandomType.UpperRandom: All capital letters between A and Z
    • RandomType.LetterRandom: All uppercase letters from A to Z and lowercase letters
    • RandomType.IntLowerRandom: IntRandom and lowerRandom union
    • RandomType.IntUpperRandom: IntRandom and upperRandom union
    • RandomType.IntLetterRandom: IntRandom and lowerRandom and upperRandom union
    • RandomType.BinRandom: Just 0 and 1
    • RandomType.OctRandom: All numbers from 0 to 7
    • RandomType.DecRandom: All numbers from 0 to 9, IntRandom is an alias
    • RandomType.HexUpperRandom: IntRandom and All capital letters between A and F
    • RandomType.HexLowerRandom: IntRandom and All capital letters between a and f
    • RandomType.HexRandom: IntRandom and All capital letters between a and f and All capital letters between A and F
  • length: The length of the resulting random string
  • options: This parameter is optional. The value is in json format
    • options.mix: Default confusable string to cull. The default string is o O 0 i I L l 1 q g 9 Q G
    • options.customScope: The range of custom characters to add, such as the concatenated string name, or special characters.
    • options.mixCustomScope: The range of custom characters to cull

Example

Javascript

const {generateRandomStr, RandomType} = require("comsvr-random");
console.log(generateRandomStr(RandomType.IntRandom, 10)) // 3652887682
console.log(generateRandomStr(RandomType.LowerRandom, 10)) // aghdcdoiuy
console.log(generateRandomStr(RandomType.UpperRandom, 10, {mix:true})) // AXHDCDTHFY
console.log(generateRandomStr(RandomType.UpperRandom, 10, {mix:true, customScope:['a','c','f','5']})) // TREFa5BNMD
console.log(generateRandomStr(RandomType.UpperRandom, 10, {mix:true, customScope:['a','c','f','5'], mixCustomScope:['A','C','F']})) // TREfa5BNMD

Typescript

import {generateRandomStr, RandomType} from "comsvr-random";
console.log(generateRandomStr(RandomType.IntRandom, 10)) // 3652887682
console.log(generateRandomStr(RandomType.LowerRandom, 10)) // aghdcdoiuy
console.log(generateRandomStr(RandomType.UpperRandom, 10, {mix:true})) // AXHDCDTHFY
console.log(generateRandomStr(RandomType.UpperRandom, 10, {mix:true, customScope:['a','c','f','5']})) // TREFa5BNMD
console.log(generateRandomStr(RandomType.UpperRandom, 10, {mix:true, customScope:['a','c','f','5'], mixCustomScope:['A','C','F']})) // TREfa5BNMD

Maintainers

@eliassama

random.js's People

Contributors

eliassama avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.