Giter Club home page Giter Club logo

randomall's Introduction

randomall

Simple and elegant generation of random data.

Installtion

npm i @liting-yes/randomall

Hello Random

const random = require('@liting-yes/randomall')

random number

simple to use

random.number()
// output: 88
// return an integer between [0, 100)

random.number.DEFAULT
// default parameter value

use with args

Function random.number has 5 params as follows:

  • min number

mininum random number isn't less than it

  • max number

maxinum random number doesn't exceed it

  • radix number

base of return value (2-36)

notice: when radix != 10, the return value will be the string value of the corresponding random number

  • isInteger boolean

whether the return value is integer

  • decimal number

max number of decimal places returned

random.number(1, 10, 10, false, 5)
// output: 1.58
// return a float between [1, 10) with no more than 5 decimal places


// support object passing
random.number({ isInteger: false })
// output: 62.664065

random string

simple to use

random.string()
// output: Z1Qdvk
// return a random string whose characters are letters and numbers

random.string.DEFAULT
random.string.CHARACTAR
// default parameter value

use with args

Function random.stringhas 6 params as follows:

  • len number

    length of random string

  • banNum number

    random string without numbers*

  • banLowercase boolean

    random string without lowercase letters

  • banUppercase boolean

    random string without uppercase letters*

  • add array

    special characters that random string contains

  • remove array

    special characters that random string must never contain

random.string(10, true, false, true, ['@', '#', '?'], ['a', 'b', 'c'])
// output: #sr#u?ljsv
// return a random string that contain possibly the characters '@', '#', '? ' and no digits, uppercase letters, 'a', 'b', 'c'


// support object passing
random.string({ banNum: true, banLowercase: true })
// output: ODMZPO

random boolean

simple to use

random.boolean()
// output: true
// return a random boolean value

random array

simple to use

random.array()
// output: [45, 71,  8, 20, 79, 17, 73, 16, 85, 44]
// return an array of length 10 and each element has a value greater than 0 and less than 100

use with args

  • len number

    length of random array

  • fn function

    the function to generate random value

  • args remain parameters

    function arguments of fn

random.array(5, random.number, 1, 10)
// output: [ 9, 5, 2, 5, 5 ]
// return an array with 5 number element which is greater than 1 less than 10

random image

simple to use

random.image().then(imgUrl => console.log(imgUrl))
// returns a configurable random image address

random.image.DEFAULT_CONFIG
random.image.DEFAULT_LOCATION
// default parameter value

use with args

  • userConfig object

same as axios request configuration

  • userLocation array

nested position of target data

random.image({ baseURL:'https://api.ixiaowai.cn', url: '/mcapi/mcapi.php' }, ['imgurl']).then(imgUrl => console.log(imgUrl))
// return an random image url about the api

statement

the image API the repo is using is 小歪API

in order to avoid some unforeseen problems, it is recommended to configure the API yourself

randomall's People

Stargazers

 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.