From 5d27d4e516bfcd70458a59aca498be8f1689a32f Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Fri, 23 Feb 2018 19:13:35 +0000 Subject: [PATCH] Fixed everything --- index.js | 41 ++++++++++++++++++++++------------------- package.json | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 025065c..3aaa5a4 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,13 @@ -const crypto = require('crypto') +'use strict' -/* froth - * num: number of test strings to return - * max: maximum length of test string - * opt: options object +/** + * Returns an array of random strings for fuzzing + * @param {number} num: number of test strings to return + * @param {number} max: maximum length of test string + * @param {object} opt: options + * @return {array} */ -exports.froth = function(num, max, opt={ +module.exports = function(num=10, max=20, opt={ // Set to true to include tests with... none: true, // Empty string whitespace: true, // Various whitespace chars @@ -16,10 +18,11 @@ exports.froth = function(num, max, opt={ alphanumeric: true, // Ordinary letters and numbers } ){ - let (chars,tests) = [] + let chars = [] + let tests = [] // Whitespace characters - if (opt.whitespace) chars.concat([ + if (opt.whitespace!==false) chars = chars.concat([ ' ', // Space ' ', // Tab '\n', // Newline @@ -28,45 +31,45 @@ exports.froth = function(num, max, opt={ ]) // Quotation characters - if (opt.quotes) chars.concat([ + if (opt.quotes!==false) chars = chars.concat([ '\'', '\'\'', '\'\'\'', // Single quotes '"', '""', '"""', // Double quotes '`', '``', '```', // Backticks ]) // Backslashes - if (opt.backslashing) chars.concat([ + if (opt.backslashing!==false) chars = chars.concat([ '\\', '\\\\', ]) // Symbols - if (opt.symbols) chars.concat( - '°~!@#$%€^&*()-_─=+[]{}|;:,./<>?¿¹²³¼½¬ł€¶ŧ←↓→»«¢„“”·…–'.split('') + if (opt.symbols!==false) chars = chars.concat( + '°~!@#$%€^&*()-_─=+[]{}|;:,./<>?¿¹²³¼½¬€¶←↓→»«¢„“”·…–'.split('') ) // Foreign characters - if (opt.foreign) chars.concat( - 'ßöäüñáóíúýéâêîôûŷàèìòùảẻỉỏỷÿïøþłĸŋđðſæµёйцукенгшщзхъэждлорпавыфячсмитьбюЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ'.split('') + if (opt.foreign!==false) chars = chars.concat( + 'ŧłßöäüñáóíúýéâêîôûŷàèìòùảẻỉỏỷÿïøþłĸŋđðſæµёйцукенгшщзхъэждлорпавыфячсмитьбюЁЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮ'.split('') ) // Ordinary letters and numbers - if (opt.alphanumeric) chars.concat( + if (opt.alphanumeric!==false) chars = chars.concat( 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split(''), ) - const min = (none)? 0 : 1 + const min = (opt.none!==false)? 0 : 1 // Add tests until we have enough tests for (let n=0; n