@haystacks/async
Version:
A framework to build any number or any kind of native application or automation solution.
761 lines (740 loc) • 89 kB
JavaScript
/**
* @file stringGeneration.js
* @module stringGeneration
* @description Contains all business rules for randomly generating strings of all kinds.
* @requires module:ruleParsing
* @requires module:loggers
* @requires {@link https://www.npmjs.com/package/@haystacks/constants|@haystacks/constants}
* @requires {@link https://www.npmjs.com/package/path|path}
* @author Seth Hollingsead
* @date 2022/01/25
* @copyright Copyright © 2022-… by Seth Hollingsead. All rights reserved
*/
// Internal imports
import ruleParsing from './ruleParsing.js';
import loggers from '../../executrix/loggers.js';
// External imports
import hayConst from '@haystacks/constants';
import path from 'path';
const {bas, biz, gen, lng, msg, num, sys, wrd} = hayConst;
const baseFileName = path.basename(import.meta.url, path.extname(import.meta.url));
// framework.businessRules.rules.stringGeneration.
const namespacePrefix = wrd.cframework + bas.cDot + sys.cbusinessRules + bas.cDot + wrd.crules + bas.cDot + baseFileName + bas.cDot;
/**
* @function generateRandomMixedCaseTextByLength
* @description Parse the input string, and determine how many mixed case
* english alphabetic characters should be generated,
* generate them and string them together.
* @param {string} inputData The string that contains a number or how many
* randomly generated mixed case alphabetic characters should be generated.
* @param {string} inputMetaData The name of the language who's alphabet should be used for international characters.
* @return {string} A string of randomly generated mixed case letters where the
* length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomMixedCaseTextByLength(inputData, inputMetaData) {
let functionName = generateRandomMixedCaseTextByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([inputData, inputMetaData], [biz.crandomlyGenerateMixedCaseAlphabeticCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomUpperCaseTextByLength
* @description Parse the input string, and determine how many upper case
* english alphabetic characters should be generated, generate them and string them together.
* @param {string} inputData The string that contains a number for how many randomly
* generated upper case english alphabetic characters should be generated.
* @param {string} inputMetaData The name of the language who's alphabet should be used for international characters.
* @return {string} A string of randomly generated upper case letters where the
* length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomUpperCaseTextByLength(inputData, inputMetaData) {
let functionName = generateRandomUpperCaseTextByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([inputData, inputMetaData], [biz.crandomlyGenerateUpperCaseLetter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomLowerCaseTextByLength
* @description Parse the input string, and determine how many lower case
* english alphabetic characters should be generated, generate them and string them together.
* @param {string} inputData The string that contains a number for how many randomly
* generated lower case english alphabetic characters that should be generated.
* @param {string} inputMetaData The name of the language who's alphabet should be used for international characters.
* @return {string} A string of randomly generated lower case letters where the
* length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomLowerCaseTextByLength(inputData, inputMetaData) {
let functionName = generateRandomLowerCaseTextByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([inputData, inputMetaData], [biz.crandomlyGenerateLowerCaseLetter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomMixedCaseTextWithSpecialCharactersByLength
* @description Generate the specified number of random mixed case letters and/or
* special characters and string them together.
* @param {string} inputData The number of randomly generated mixed case letters and/or
* special characters to generate the output string.
* @param {string} inputMetaData A JSON data structure object that contains the list of special characters that should be used during the generation process,
* and also the name of the language who's alphabet should be used for international characters.
* [
* "!@#$%^&*()_+-=[]{};:',./<>?\|\"", // SpecialCharacters
* "English" // Language
* ]
* @return {string} A string of randomly generated mixed case letters and
* special characters where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomMixedCaseTextWithSpecialCharactersByLength(inputData, inputMetaData) {
let functionName = generateRandomMixedCaseTextWithSpecialCharactersByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData && inputMetaData) {
let numberOfCharactersToGenerate = parseInt(inputData);
let specialCharacters = inputMetaData[0];
let language = inputMetaData[1];
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([specialCharacters, language], [biz.crandomlyGenerateMixedCaseLetterOrSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomUpperCaseTextWithSpecialCharactersByLength
* @description Generate the specified number of random upper cae letters and/or special characters and string them together.
* @param {string} inputData The number of randomly generated upper case english letters and/or special characters to generate.
* @param {string} inputMetaData A JSON data structure object that contains the list of special characters that should be used during the generation process,
* and also the name of the language who's alphabet should be used for international characters.
* [
* "!@#$%^&*()_+-=[]{};:',./<>?\|\"", // SpecialCharacters
* "English" // Language
* ]
* @return {string} A string of randomly generated upper case english letters and
* special characters where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomUpperCaseTextWithSpecialCharactersByLength(inputData, inputMetaData) {
let functionName = generateRandomUpperCaseTextWithSpecialCharactersByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData && inputMetaData) {
let numberOfCharactersToGenerate = parseInt(inputData);
let specialCharacters = inputMetaData[0];
let language = inputMetaData[1];
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([specialCharacters, language], [biz.crandomlyGenerateUpperCaseLetterOrSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomLowerCaseTextWithSpecialCharactersByLength
* @description Generate the specified number of random lower case english letters and/or
* special characters and string them together.
* @param {string} inputData The number of randomly generated lower case letters and/or
* special characters to generate.
* @param {string} inputMetaData A JSON data structure object that contains the list of special characters that should be used during the generation process,
* and also the name of the language who's alphabet should be used for international characters.
* [
* "!@#$%^&*()_+-=[]{};:',./<>?\|\"", // SpecialCharacters
* "English" // Language
* ]
* @return {string} A string of randomly generated lower case english letters and
* special characters where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomLowerCaseTextWithSpecialCharactersByLength(inputData, inputMetaData) {
let functionName = generateRandomLowerCaseTextWithSpecialCharactersByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData && inputMetaData) {
let numberOfCharactersToGenerate = parseInt(inputData);
let specialCharacters = inputMetaData[0];
let language = inputMetaData[1];
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([specialCharacters, language], [biz.crandomlyGenerateLowerCaseLetterOrSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomMixedCaseAlphaNumericCodeByLength
* @description Generate the specified number of random mixed case english letters and/or
* numeric characters and string them together.
* @param {string} inputData The number of randomly generated mixed case letters and/or
* numbers that should be generated.
* @param {string} inputMetaData The name of the language who's alphabet should be used for international characters.
* @return {string} A string of randomly generated mixed case english letters and
* numbers where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomMixedCaseAlphaNumericCodeByLength(inputData, inputMetaData) {
let functionName = generateRandomMixedCaseAlphaNumericCodeByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal(['', inputMetaData], [biz.crandomlyGenerateMixedCaseAlphaNumericCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomUpperCaseAlphaNumericCodeByLength
* @description Generate the specified number of random upper case english letters and/or
* numeric characters and string them together.
* @param {string} inputData The string that contains a number for how many randomly
* generated upper case english letters and/or numbers that should be generated.
* @param {string} inputMetaData The name of the language who's alphabet should be used for international characters.
* @return {string} A string of randomly generated upper case english letters and numbers
* where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomUpperCaseAlphaNumericCodeByLength(inputData, inputMetaData) {
let functionName = generateRandomUpperCaseAlphaNumericCodeByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal(['', inputMetaData], [biz.crandomlyGenerateUpperCaseAlphaNumericCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomLowerCaseAlphaNumericCodeByLength
* @description Generate the specified number of random lower case english letters and/or
* numeric characters and string them together.
* @param {string} inputData The number of randomly generated lower case letters and/or
* numbers that should be generated.
* @param {string} inputMetaData The name of the language who's alphabet should be used for international characters.
* @return {string} A string of randomly generated lower case english letters and
* numbers where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomLowerCaseAlphaNumericCodeByLength(inputData, inputMetaData) {
let functionName = generateRandomLowerCaseAlphaNumericCodeByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal(['', inputMetaData], [biz.crandomlyGenerateLowerCaseAlphaNumericCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomNumericCodeByLength
* @description Generate the specified number of random numeric characters and string them together.
* @param {string} inputData The number of randomly generated numeric characters that should be generated.
* @param {string} inputMetaData Not used for this business rule.
* @return {string} A string of randomly generated numeric characters where the
* length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomNumericCodeByLength(inputData, inputMetaData) {
let functionName = generateRandomNumericCodeByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal(['', inputMetaData], [biz.crandomlyGenerateNumericCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomMixedCaseAlphaNumericCodeWithSpecialCharactersByLength
* @description Generate a random selection of mixed case english letters,
* numeric characters and special characters from a list of allowable special characters,
* should be generated; generate them and string them together to the specified length.
* @param {string} inputData The number of randomly generated english letters,
* numeric characters and special characters that should be generated.
* @param {string} inputMetaData A JSON data structure object that contains the list of special characters that should be used during the generation process,
* and also the name of the language who's alphabet should be used for international characters.
* [
* "!@#$%^&*()_+-=[]{};:',./<>?\|\"", // SpecialCharacters
* "English" // Language
* ]
* @return {string} A string of randomly generated mixed case alpha numeric characters,
* and special characters where the length of the string is defined by the input parameter.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomMixedCaseAlphaNumericCodeWithSpecialCharactersByLength(inputData, inputMetaData) {
let functionName = generateRandomMixedCaseAlphaNumericCodeWithSpecialCharactersByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData && inputMetaData) {
let numberOfCharactersToGenerate = parseInt(inputData);
let specialCharacters = inputMetaData[0];
let language = inputMetaData[1];
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([specialCharacters, language], [biz.crandomlyGenerateEitherMixedCaseLetterOrNumberOrSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomUpperCaseAlphaNumericCodeWithSpecialCharactersByLength
* @description Generate a random selection of upper case english letters,
* numeric characters and special characters from a list of allowable special characters,
* should be generated; generate them and string them together to the specified length.
* @param {string} inputData The number of randomly generated upper case english letters,
* numeric characters and special characters that should be generated.
* @param {string} inputMetaData A JSON data structure object that contains the list of special characters that should be used during the generation process,
* and also the name of the language who's alphabet should be used for international characters.
* [
* "!@#$%^&*()_+-=[]{};:',./<>?\|\"", // SpecialCharacters
* "English" // Language
* ]
* @return {string} A string of randomly generated upper case alpha numeric characters,
* and special characters where the length of the string is defined as one of the input parameters.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomUpperCaseAlphaNumericCodeWithSpecialCharactersByLength(inputData, inputMetaData) {
let functionName = generateRandomUpperCaseAlphaNumericCodeWithSpecialCharactersByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData && inputMetaData) {
let numberOfCharactersToGenerate = parseInt(inputData);
let specialCharacters = inputMetaData[0];
let language = inputMetaData[1];
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([specialCharacters, language], [biz.crandomlyGenerateEitherUpperCaseLetterOrNumberOrSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomLowerCaseAlphaNumericCodeWithSpecialCharactersByLength
* @description Generate a random selection of lower case english letters,
* numeric characters and special characters from a list of allowable special characters,
* should be generated; generate them and string them together to the specified length.
* @param {string} inputData The number of randomly generated lower case english letters,
* numeric characters adn special characters that should be generated.
* @param {string} inputMetaData A JSON data structure object that contains the list of special characters that should be used during the generation process,
* and also the name of the language who's alphabet should be used for international characters.
* [
* "!@#$%^&*()_+-=[]{};:',./<>?\|\"", // SpecialCharacters
* "English" // Language
* ]
* @return {string} A string of randomly generated lower case alpha numeric characters,
* and special characters where the length of the string is defined as one of the input parameters.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomLowerCaseAlphaNumericCodeWithSpecialCharactersByLength(inputData, inputMetaData) {
let functionName = generateRandomLowerCaseAlphaNumericCodeWithSpecialCharactersByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData && inputMetaData) {
let numberOfCharactersToGenerate = parseInt(inputData);
let specialCharacters = inputMetaData[0];
let language = inputMetaData[1];
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([specialCharacters, language], [biz.crandomlyGenerateEitherLowerCaseLetterOrNumberOrSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomSpecialCharacterCodeByLength
* @description Generate a random selection of characters from the input allowable alphabet of characters,
* generate them and string them together to the specified length.
* @param {string} inputData The number of randomly generated special characters that should be generated.
* @param {string} inputMetaData The list of special characters that should be used during the generation process.
* @return {string} A string of randomly generated characters from the list of
* allowable special characters that are passed in where the length of the string is defined as one of the input parameters.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomSpecialCharacterCodeByLength(inputData, inputMetaData) {
let functionName = generateRandomSpecialCharacterCodeByLength.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
if (inputData) {
let numberOfCharactersToGenerate = parseInt(inputData);
for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++) {
returnData = returnData.concat(await ruleParsing.processRulesInternal([inputMetaData, ''], [biz.crandomlyGenerateSpecialCharacter]));
} // End-for (let counter = 1; counter <= numberOfCharactersToGenerate; counter++)
} // End-if (inputData)
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateValidEmail
* @description Generate a valid random email address composed of a random selection of
* mixed case english letters, numeric characters and optionally special characters
* from an optional list of allowable special characters, should be generated;
* generate them and string them together to the specified length.
* Basically this function acts as an input filter to ensure that valid inputs are passed into the functions for doing the word of generating random valid emails.
* @param {string} inputData The string that contains the number of characters to generate.
* @param {array<boolean,string,string>} inputMetaData An array map with multiple input parameters.
* inputMetaData[0] - generateSpecialCharacters - A boolean value to indicate if special characters should be included when randomly generating characters for the output string.
* inputMetaData[1] - allowableSpecialCharacters - The list of allowable special characters as a string, only used if the {@code generateSpecialCharacters} boolean value is set to {@code TRUE}.
* inputMetaData[2] - specifiedSuffixAndDomain - The specified suffix and domain to use after the "@" symbol in the email being generated, example "Yahoo.com".
* inputMetaData[3] - language - The language that should be used to determine the alphabet that should be used for international characters.
* @return {string} A string of randomly generated mixed case alpha numeric characters and optionally special characters
* where the length of the string is also defined as one of the input parameters, formatted as an email: a@b.com".
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateValidEmail(inputData, inputMetaData) {
let functionName = generateValidEmail.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
let newInputMetaData = [];
if (!!inputMetaData && inputMetaData !== 'undefined' && inputMetaData !== '') {
if (inputMetaData.length === 4) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = inputMetaData[1]; // allowableSpecialCharacters
newInputMetaData[2] = inputMetaData[2]; // specifiedSuffixAndDomain
newInputMetaData[3] = inputMetaData[3]; // language
// NOTE: The above function stringParsingUtilities.stringToBoolean will default to False if the input is an empty or undefined string.
// We want to flip it back to True but ony if some special characters are passed in.
if (newInputMetaData[0] === false && newInputMetaData[1] !== '') {
newInputMetaData[0] = true;
}
returnData = await generateValidEmailWithSpecificSuffixAndDomainName(inputData, newInputMetaData);
} else if (inputMetaData.length === 3) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = inputMetaData[1]; // allowableSpecialCharacters
newInputMetaData[2] = inputMetaData[2]; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
// NOTE: The above function stringParsingUtilities.stringToBoolean will default to False if the input is an empty or undefined string.
// We want to flip it back to True but only if some special characters are passed in.
if (newInputMetaData[0] === false && newInputMetaData[1] !== '') {
newInputMetaData[0] = true;
}
returnData = await generateValidEmailWithSpecificSuffixAndDomainName(inputData, newInputMetaData);
} else if (inputMetaData.length === 2) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = inputMetaData[1]; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
// NOTE: The above function stringParsingUtilities.stringToBoolean will default to False if the input is an empty or undefined string.
// We want to flip it back to True but only if some special characters are passed in.
if (newInputMetaData[0] === false && newInputMetaData[1] !== '') {
newInputMetaData[0] = true;
}
returnData = await generateRandomValidEmail(inputData, newInputMetaData);
} else if (inputMetaData.length === 1) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = ''; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
returnData = await generateRandomValidEmail(inputData, newInputMetaData);
} else {
newInputMetaData[0] = false; // generateSpecialCharacters
newInputMetaData[1] = ''; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
returnData = await generateRandomValidEmail(inputData, newInputMetaData);
}
} else { // Else-clause if (!!inputMetaData && inputMetaData !== 'undefined' && inputMetaData !== '')
newInputMetaData[0] = false; // generateSpecialCharacters
newInputMetaData[1] = ''; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
returnData = await generateRandomValidEmail(inputData, newInputMetaData);
} // End-else-clause if (!!inputMetaData && inputMetaData !== 'undefined' && inputMetaData !== '')
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + JSON.stringify(returnData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateInvalidEmail
* @description Generate an invalid random email address composed of a random selection of mixed case english letters,
* numeric characters adn optionally special characters from an optional list of allowable special characters,
* should be generated; generate them and string them together to the specified length.
* @param {string} inputData The string that contains the number of characters to generate.
* @param {array<boolean,string,string>} inputMetaData An array map with multiple input parameters:
* inputMetaData[0] - generateSpecialCharacters - A boolean value to indicate if special characters should be included when randomly generating characters for the output string.
* inputMetaData[1] - allowableSpecialCharacters - The list of allowable special characters as a string, only used if the {@code generateSpecialCharacters} boolean value is set to {@code TRUE}.
* inputMetaData[2] - specifiedSuffixAndDomain - The specified suffix and domain to use after the "@" symbol in the email being generated, example "Yahoo.com".
* inputMetaData[3] - language - The language that should be used to determine the alphabet that should be used for international characters.
* @return {string} A string of randomly generated mixed case alpha numeric characters and
* optionally special characters where the length of the string is also defined as one
* of the input parameters, formatted as an email: "a@b.com".
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateInvalidEmail(inputData, inputMetaData) {
let functionName = generateInvalidEmail.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
let newInputMetaData = [];
if (!!inputMetaData && inputMetaData !== 'undefined' && inputMetaData !== '') {
if (inputMetaData.length === 4) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = inputMetaData[1]; // allowableSpecialCharacters
newInputMetaData[2] = inputMetaData[2]; // specifiedSuffixAndDomain
newInputMetaData[3] = inputMetaData[3]; // language
// @NOTE The above function stringParsingUtilities.stringToBoolean will default to False if the input is an empty or undefined string.
// We want to flip it back to True but ony if some special characters are passed in.
if (newInputMetaData[0] === false && newInputMetaData[1] !== '') {
newInputMetaData = true;
}
returnData = await generateInvalidEmailWithSpecificSuffixAndDomainName(inputData, newInputMetaData);
} else if (inputMetaData.length === 3) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = inputMetaData[1]; // allowableSpecialCharacters
newInputMetaData[2] = inputMetaData[2]; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
// @NOTE The above function stringParsingUtilities.stringToBoolean will default to False if the input is an empty or undefined string.
// We want to flip it back to True but ony if some special characters are passed in.
if (newInputMetaData[0] === false && newInputMetaData[1] !== '') {
newInputMetaData[0] = true;
}
returnData = await generateInvalidEmailWithSpecificSuffixAndDomainName(inputData, newInputMetaData);
} else if (inputMetaData.length === 2) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = inputMetaData[1]; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
// @NOTE The above function stringParsingUtilities.stringToBoolean will default to False if the input is an empty or undefined string.
// We want to flip it back to True but ony if some special characters are passed in.
if (newInputMetaData[0] === false && newInputMetaData[1] !== '') {
newInputMetaData[0] = true;
}
returnData = await generateRandomInvalidEmail(inputData, newInputMetaData);
} else if (inputMetaData.length === 1) {
newInputMetaData[0] = await ruleParsing.processRulesInternal([inputMetaData[0], ''], [biz.cstringToBoolean]); // generateSpecialCharacters
newInputMetaData[1] = ''; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
returnData = await generateRandomInvalidEmail(inputData, newInputMetaData);
} else {
newInputMetaData[0] = false; // generateSpecialCharacters
newInputMetaData[1] = ''; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
returnData = await generateRandomInvalidEmail(inputData, newInputMetaData);
}
} else {
newInputMetaData[0] = false; // generateSpecialCharacters
newInputMetaData[1] = ''; // allowableSpecialCharacters
newInputMetaData[2] = ''; // specifiedSuffixAndDomain
newInputMetaData[3] = lng.cEnglish; // language
returnData = await generateRandomInvalidEmail(inputData, newInputMetaData);
}
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + returnData);
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateValidEmailWithSpecificSuffixAndDomainName
* @description Generate a valid email composed of a random selection of mixed case english letters,
* numeric characters and optionally special characters from an optional list of allowable special characters,
* should be generated; generate them and string them together to the specified length.
* @param {string} inputData The string that contains the number of characters to generate.
* @param {array<string|boolean>} inputMetaData An array with multiple input parameters:
* inputMetaData[0] - generateSpecialCharacters - A boolean value to indicate if special characters should be included when randomly generating characters for the output string.
* inputMetaData[1] - allowableSpecialCharacters - The list of allowable special characters as a string, only used if the {@code generateSpecialCharacters} boolean value is set to {@code TRUE}.
* inputMetaData[2] - specifiedSuffixAndDomain - The specified suffix and domain to use after the "@" symbol in the email being generated, example "Yahoo.com".
* inputMetaData[3] - language - The language that should be used to determine the alphabet that should be used for international characters.
* @return {string} A string of randomly generated mixed case alpha numeric characters and optionally special characters
* where the length of the string is also defined as one of the input parameters, formatted as an email: "a@b.com".
* @NOTE The number of characters in the {@code specifiedSuffixAndDomain} input variable must not
* exceed the {@code numberOfCharactersToGenerate + 2} or the function/rule will return an empty string.
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateValidEmailWithSpecificSuffixAndDomainName(inputData, inputMetaData) {
let functionName = generateValidEmailWithSpecificSuffixAndDomainName.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
let prefix = '';
if (inputData && inputMetaData && Array.isArray(inputMetaData) === true && inputMetaData.length === 4) {
let numberOfCharactersToGenerate = inputData;
let generateSpecialCharacters = inputMetaData[0];
let allowableSpecialCharacters = inputMetaData[1];
let specifiedSuffixAndDomain = inputMetaData[2];
let language = inputMetaData[3]
if ((numberOfCharactersToGenerate >= specifiedSuffixAndDomain.length + 2) && numberOfCharactersToGenerate >= 6 &&
specifiedSuffixAndDomain.includes(bas.cDot)) {
// @NOTE we cannot have less then 6 characters, because an e-mail address cannot be shorter than a@b.cc which is 6 characters long.
// We know we have to use an "@" symbol, and a "." symbol, the rest of the characters ust be generated....and the "." should have already been passed in.
// First need to figure out how many characters of each we must generate to et the desired final length.
//
// So lets remove the characters that we know we are already going to be reserved, the "@" symbol.
numberOfCharactersToGenerate = numberOfCharactersToGenerate - 1;
numberOfCharactersToGenerate = numberOfCharactersToGenerate - specifiedSuffixAndDomain.length;
if (generateSpecialCharacters === false) {
prefix = await generateRandomMixedCaseAlphaNumericCodeByLength(numberOfCharactersToGenerate, language);
} else {
prefix = await generateRandomMixedCaseAlphaNumericCodeWithSpecialCharactersByLength(numberOfCharactersToGenerate, [allowableSpecialCharacters, language]);
}
returnData = prefix + bas.cAt + specifiedSuffixAndDomain;
} else {
returnData = '';
}
} else {
returnData = '';
}
await loggers.consoleLog(namespacePrefix + functionName, msg.creturnDataIs + returnData);
await loggers.consoleLog(namespacePrefix + functionName, msg.cEND_Function);
return returnData;
}
/**
* @function generateRandomValidEmail
* @description Generate a valid email composed of a random selection of mixed case english letters,
* numeric characters and optional special characters from an optional list of allowable special characters,
* should be generated; generate them and string them together to the specified length.
* @param {string} inputData The string that contains the number of characters to generate.
* @param {array<string|boolean>} inputMetaData An array that contains a set of objects, strings and booleans as detailed below.
* inputMetaData[0] - generateSpecialCharacters - A Boolean value to indicate if special characters should be included when randomly generating characters for the output string.
* inputMetaData[1] - allowableSpecialCharacters - The list of allowable special characters as a string, only used if the {@code generateSpecialCharacters} Boolean value is set to {@code TRUE}.
* inputMetaData[2] - specifiedSuffixAndDomain - Not used for this business rule.
* inputMetaData[3] - language - The language that should be used to determine the alphabet that should be used for international characters.
* @return {string} A string of randomly generated mixed case alpha numeric characters adn optionally special characters
* where the length of the string is also defined as one of the input parameters, formatted as an email "a@b.com".
* @author Seth Hollingsead
* @date 2022/01/26
*/
async function generateRandomValidEmail(inputData, inputMetaData) {
let functionName = generateRandomValidEmail.name;
await loggers.consoleLog(namespacePrefix + functionName, msg.cBEGIN_Function);
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputDataIs + JSON.stringify(inputData));
await loggers.consoleLog(namespacePrefix + functionName, msg.cinputMetaDataIs + JSON.stringify(inputMetaData));
let returnData = '';
let prefix = '';
let suffix = '';
let domainName = '';
let numberOfPrefixCharacters = 0;
let numberOfSuffixCharacters = 0;
if (inputData && inputMetaData && Array.isArray(inputMetaData) === true && inputMetaData.length === 3) {
let numberOfCharactersToGenerate = inputData;
let generateSpecialCharacters = inputMetaData[0];
let allowableSpecialCharacters = inputMetaData[1];
// let specifiedSuffixAndDomain = inputMetaData[2]; NOTE: This array index is not used for this business rule.
let language = inputMetaData[3];
if (numberOfCharactersToGenerate >= 6) {
// @NOTE We cannot have less than 6, because an e-mail address cannot be shorter than a@b.cc which is 6 characters long.
// We know we have to use an "@" symbol, and a "." symbol, the rest of the characters must be generated.
// first need to figure out how many characters of each we must generate to get the desired file length.
//
// So lets remove the characters that we know are already going to be reserved, the "@" symbol and the "." symbol.
numberOfCharactersToGenerate = numberOfCharactersToGenerate - 2;
// Consider that the number of characters in the domain must be either 2 or 3. (according to IpV5, IpV6 is a whole other ball of wax!!)
// So let us first figure that out, then the rest of the available characters that we must provide can be divided up between the prefix and suffix.
if (numberOfCharactersToGenerate === 4) { // Stick with a 2-character domain name.
if (generateSpecialCharacters === false) {
domainName = await generateRandomMixedCaseTextByLength(num.c2, language);
} else {
domainName = await generateRandomMixedCaseAlphaNumericCodeWithSpecialCharactersByLength(num.c2, [allowableSpecialCharacters, language]);
}
} else if (numberOfCharactersToGenerate >= 5) {
// Randomly determine if we should generate a 2-character or 3-character domain name. We can do either one,
// but we need to decide now so we can get it done and be fair.
// (That is generate 2-character domains roughly equal to the times we generate a 3-character domain.)
if (await ruleParsing.processRulesInternal(['', ''], [biz.crandomlyGenerateBooleanValue]) === true) { // Stick with a 2-character domain name.
if (generateSpecialCharacters === false) {
domainName = await generateRandomMixedCaseTextByLength(num.c2, language);
} else {
domainName = await generateRandomMixedCaseAlphaNumericCodeWithSpecialCharactersByLength(num.c2, [allowableSpecialCharacters, language]);
}
numberOfCharactersToGenerate = numberOfCharactersToGenerate - 2;
} else { // Do a 3-character domain name.
if (generateSpecialCharacters === false) {
domainName = await generateRandomMixedCaseTextByLength(num.c3, language);
} else {
domainName = await generateRandomMixedCaseAlphaNumericCodeWithSpecialCharacter