0.0.3 • Published 7 years ago

nhm v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

nhm

a javascript class to generate a random string.

install

npm install nhm --save

usage

import Nhm from 'nhm';

let string = new Nhm(length[, option][, additionalCharsString]);

args

{
  args:{
    description: `need true of one of 
          lowerCase, 
          upperCase, 
          number, 
          symbol,
        at least or have additionalCharString`,
    length: {
      description: 'the length of the string',
      type: Number,
      required: true,
      restrain: '>=0',
    },
    option: {
      lowerCase: {
        description: 'contain lower case letter?',
        type: Boolean,
        required: false,
        default: false,
        include: 'abcdefghijklmnopqrstuvwxyz',
      },
      upperCase: {
        description: 'contain upper case letter?',
        type: Boolean,
        required: false,
        default: false,
        include: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
      },
      number: {
        description: 'contain number char?',
        type: Boolean,
        required: false,
        default: true,
        include: '0123456789',
      },
      symbol: {
        description: 'contain symbol char?',
        type: Boolean,
        required: false,
        default: false,
        include: '`-=[]\\;\',./~!@#$%^&*()_+{}|:"<>?',
      },
    },
    additionalCharsString: {
      description: `
        add chars you want to insert the string that nhm generate
      `,
      type: String,
      required: false,
      default: undefined,
    },
  }
}

demo

import Nhm from 'nhm';

let string = new Nhm(18, {
  lowerCase: true,
  upperCase: true,
  number: true,
  symbol: true,
});

console.log(string); // "QMhh1}=9{d@ujlz<Q]"
console.log(Object.prototype.toString.call(string)); // "[object String]"

string = new Nhm(18, {
  lowerCase: true,
  upperCase: true,
  number: true,
  symbol: true,
}, '你好吗');

console.log(string); // ")ez>Vl&0<)XGLTj吗yz"

string = new Nhm(18, {
  lowerCase: false,
  upperCase: false,
  number: false,
  symbol: false,
}, '你好吗');

console.log(string); // "好你吗好好你吗好吗好你吗你你吗你吗你"