outers
Version:
outers - a all in one package for your day to day use
40 lines • 2.27 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// import Gen functions
const NumGen_1 = __importDefault(require("../gen/NumGen")); // function for generating a random word
// function for generating a random number
/**
* This TypeScript function generates a random number ID of a specified length, with the option to
* exclude zero and use a custom set of numbers.
* @param {num} [length=1] - The length parameter is a number that specifies the length of the
* generated number ID.
* @param {bool} [WithZero=true] - A boolean value that determines whether or not the generated number
* can include the digit 0. If set to true, the digit 0 will be included in the possible numbers to
* generate. If set to false, the digit 0 will be removed from the possible numbers to generate.
* @param {num[] | undefined} CustomNumbers - An optional parameter that allows the user to provide a
* custom array of numbers to generate the random number ID from. If not provided, the function will
* use the default array of numbers from 0 to 9.
* @returns a Promise that resolves to a number (num).
*/
function GenerateNumberID(length = 1, WithZero = true, CustomNumbers) {
/* Creating an array of numbers from 0 to 9 that will be used to generate the random 10-digit number
ID. */
const NumbersArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; // All Possible Numbers to generate
// Filtered Array
const FilteredArray = CustomNumbers !== undefined ? CustomNumbers : NumbersArray;
if (WithZero === false) {
const ZeroIndexNum = FilteredArray.indexOf(0); // Get the index of Zero
FilteredArray.splice(ZeroIndexNum, 1); // Remove Zero from the Array
const GenerationResult = (0, NumGen_1.default)(length, FilteredArray); // Generate the Random Number
return GenerationResult; // Return the Result
}
else {
const GenerationResult = (0, NumGen_1.default)(length, FilteredArray); // Generate the Random Number
return GenerationResult; // Return the Result
}
}
exports.default = GenerateNumberID;
//# sourceMappingURL=NumFunction.js.map