Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

randomatic

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

randomatic - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

75

index.js

@@ -7,8 +7,18 @@ /*!

*
* Originally inspired by <http://stackoverflow.com/a/10727155/1267639>
* Many changes have been made, but this was originally
* inspired by <http://stackoverflow.com/a/10727155/1267639>
*/
'use strict';
var isNumber = require('is-number');
var typeOf = require('kind-of');
/**
* Expose `randomatic`
*/
module.exports = randomatic;
/**
* Available mask characters

@@ -20,6 +30,8 @@ */

upper: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
numeric: '0123456789',
number: '0123456789',
special: '~!@#$%^&()_+-={}[];\',.'
};
type.all = type.lower + type.upper + type.number;
/**

@@ -36,49 +48,42 @@ * Generate random character sequences of a specified `length`,

module.exports = function randomatic(pattern, length, options) {
if (arguments.length === 1 && typeof pattern === 'number') {
options = length;
length = pattern;
pattern = '*';
function randomatic(pattern, length, options) {
if (typeof pattern === 'undefined') {
throw new Error('randomatic expects a string or number.');
}
var opts = options || {};
var mask = '';
var res = '';
var custom = false;
if (arguments.length === 1) {
if (typeof pattern === 'string') {
length = pattern.length;
opts.chars = opts.chars || '';
// if `length` is an object, since `chars` is currently the only
// option, use the length of the special chars as `length`
if(typeof length === 'object') {
opts = length;
if (isNumber(pattern)) {
length = pattern;
} else {
length = opts.chars.length;
} else if (isNumber(pattern)) {
options = {}; length = pattern; pattern = '*';
}
pattern = opts.chars;
}
// if no `length` is defined, use the length of the pattern
if(typeof length === 'undefined') {
if(typeOf(length) === 'object' && length.hasOwnProperty('chars')) {
options = length;
pattern = options.chars;
length = pattern.length;
custom = true;
}
var opts = options || {};
var mask = '';
var res = '';
// Characters to be used
if (pattern.indexOf('?') > -1) mask += opts.chars;
if (pattern.indexOf('a') > -1) mask += type.lower;
if (pattern.indexOf('A') > -1) mask += type.upper;
if (pattern.indexOf('0') > -1) mask += type.numeric;
if (pattern.indexOf('!') > -1) mask += type.special;
if (pattern.indexOf('*') > -1) mask += type.all;
if (pattern.indexOf('?') !== -1) mask += opts.chars;
if (pattern.indexOf('a') !== -1) mask += type.lower;
if (pattern.indexOf('A') !== -1) mask += type.upper;
if (pattern.indexOf('0') !== -1) mask += type.number;
if (pattern.indexOf('!') !== -1) mask += type.special;
if (pattern.indexOf('*') !== -1) mask += type.all;
if (custom) mask += pattern;
if (mask.length === 0 || mask == null) {
mask += pattern;
while (length--) {
res += mask.charAt(parseInt(Math.random() * mask.length));
}
var len = mask.length - 1;
while (length--) {
res += mask[parseInt(Math.random() * len)];
}
return res;
};
{
"name": "randomatic",
"description": "Generate randomized strings of a specified length, fast. Only the length is necessary, but you can optionally generate patterns using any combination of numeric, alpha-numeric, alphabetical, special or custom characters.",
"version": "1.0.1",
"version": "1.1.0",
"homepage": "https://github.com/jonschlinkert/randomatic",

@@ -22,9 +22,16 @@ "author": {

"scripts": {
"test": "mocha -R spec",
"docs": "update && license && npmignore && deps && verb",
"all": "npm run test && npm run docs"
"test": "mocha -R spec"
},
"main": "index.js",
"files": [
"index.js"
],
"dependencies": {
"is-number": "^1.1.0",
"kind-of": "^1.0.0"
},
"devDependencies": {
"mocha": "^2.0.1",
"benchmarked": "^0.1.3",
"chalk": "^0.5.1",
"glob": "^4.3.5",
"should": "^4.4.1"

@@ -43,6 +50,3 @@ },

"randomized"
],
"dependencies": {
"is-number": "^0.1.1"
}
]
}

@@ -138,2 +138,2 @@ # randomatic [![NPM version](https://badge.fury.io/js/randomatic.svg)](http://badge.fury.io/js/randomatic)

_This file was generated by [verb](https://github.com/assemble/verb) on January 02, 2015._
_This file was generated by [verb](https://github.com/assemble/verb) on January 26, 2015._
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc