Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including random-rule with all npm packages installed. Try it out:

var randomRule = require("random-rule")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

random-rule v1.0.4

get random string

random-rule

简介

random-rule 是一个使用十分简单按照固定规则生成随机字符串的库

在线demo

在线demo

安装

npm install random-rule --save

使用


/**
 *
 * @param {!Object}
 *
 * @param {Boolean} Object.capitalLetters 是否包含大写字母
 * @param {Boolean} Object.lowercaseLetters 是否包含小写字母
 * @param {Boolean} Object.number 是否包含数字
 * @param {Boolean} Object.symbols 是否包含符号
 * @param {Number} Object.length 生成字符串长度
 *
 * @return string
 */

randomRule({
  capitalLetters: true,
  lowercaseLetters: true,
  number: true,
  symbols: true,
  length: 10
})

// => 'KGRuf^381K'


/**
 *
 * @param {String} 字符串模板,根据该字符串生成长度与数字大小写符号位置商都相对应的随机字符串
 *
 * @return string
 *
 */

randomRule('123qweQWE!@#')

// => '085pnwPNF)^#'

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free