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