jsfakeit
Version:

185 lines (184 loc) • 7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.chromeUserAgent = exports.firefoxUserAgent = exports.operaUserAgent = exports.randomPlatform = exports.httpVersion = exports.windowsPlatformToken = exports.macPlatformToken = exports.linuxPlatformToken = exports.logLevel = exports.macAddress = exports.ipv6Address = exports.ipv4Address = exports.url = exports.domainName = exports.httpStatusCodeSimple = exports.httpStatusCode = exports.httpMethod = exports.domainSuffix = void 0;
const internet_1 = require("../data/internet");
const status_code_1 = require("../data/status_code");
const log_level_1 = require("../data/log_level");
const computer_1 = require("../data/computer");
const chooseRand_1 = require("../helper/chooseRand");
const company_1 = require("../company");
const time_1 = require("../time");
/** Generates a random domain suffix */
const domainSuffix = () => {
return (0, chooseRand_1.chooseRand)('domain_suffix', internet_1.internet);
};
exports.domainSuffix = domainSuffix;
/** Generates a random http method */
const httpMethod = () => {
return (0, chooseRand_1.chooseRand)('http_method', internet_1.internet);
};
exports.httpMethod = httpMethod;
/** Generates a random status code */
const httpStatusCode = () => {
return (0, chooseRand_1.chooseRand)('general', status_code_1.statusCode);
};
exports.httpStatusCode = httpStatusCode;
/** Generates a random simple status code */
const httpStatusCodeSimple = () => {
return (0, chooseRand_1.chooseRand)('simple', status_code_1.statusCode);
};
exports.httpStatusCodeSimple = httpStatusCodeSimple;
//** Generates a random domain name */
const domainName = () => {
const text = ((0, company_1.jobDescriptor)() + (0, company_1.bS)()).toLowerCase();
const text_1 = text.replace(' ', '');
return `${text_1}.${(0, exports.domainSuffix)()}`;
};
exports.domainName = domainName;
/** Generates a random url */
const url = () => {
let num = (0, chooseRand_1.getRandomArbitrary)(1, 4);
let slug = [];
for (let i = 0; i < num; i++) {
slug[i] = (0, company_1.bS)();
}
const protocol = ['https', 'http'];
let scheme = protocol[(0, chooseRand_1.getRandomArbitrary)(0, 2)];
let path = slug.join('/');
let url = `${scheme}://www.${(0, exports.domainName)()}/${path}`;
return url.replace(' ', '');
};
exports.url = url;
/** Generates a random ipv4Address */
const ipv4Address = () => {
const num = () => {
return (0, chooseRand_1.getRandomArbitrary)(0, 256);
};
return `${num()}.${num()}.${num()}.${num()}`;
};
exports.ipv4Address = ipv4Address;
/** Generates a random ipv6Address */
const ipv6Address = () => {
const num = () => {
return (0, chooseRand_1.getRandomArbitrary)(0, 65536);
};
return `${num()}.${num()}.${num()}.${num()}.${num()}.${num()}.${num()}.${num()}`;
};
exports.ipv6Address = ipv6Address;
/** Generates a random Mac address */
const macAddress = () => {
const num = () => (0, chooseRand_1.getRandomArbitrary)(17, 255).toString(16);
return `${num()}:${num()}:${num()}:${num()}:${num()}:${num()}`;
};
exports.macAddress = macAddress;
/** LogLevel will generate a random log level */
const logLevel = (logType) => {
const keys = Object.keys(log_level_1.logLevels);
if (keys.findIndex(exports.logLevel) >= 0) {
//@ts-ignore
return (0, chooseRand_1.chooseRand)(logType, log_level_1.logLevels);
}
return (0, chooseRand_1.chooseRand)('general', log_level_1.logLevels);
};
exports.logLevel = logLevel;
/** Generate a random linux platfrom */
const linuxPlatformToken = () => {
return (0, chooseRand_1.chooseRand)('linux_processor', computer_1.computer);
};
exports.linuxPlatformToken = linuxPlatformToken;
/** Generate a random mac platfrom */
const macPlatformToken = () => {
return (0, chooseRand_1.chooseRand)('mac_processor', computer_1.computer);
};
exports.macPlatformToken = macPlatformToken;
/**Generate a random window platfrom*/
const windowsPlatformToken = () => {
return (0, chooseRand_1.chooseRand)('windows_platform', computer_1.computer);
};
exports.windowsPlatformToken = windowsPlatformToken;
/**Generate random http version*/
const httpVersion = () => {
return (0, chooseRand_1.chooseRand)('http_version', internet_1.internet);
};
exports.httpVersion = httpVersion;
/**Generate random platform*/
const randomPlatform = () => {
const platforms = [
(0, exports.linuxPlatformToken)(),
(0, exports.macPlatformToken)(),
(0, exports.windowsPlatformToken)(),
];
let num = (0, chooseRand_1.getRandomArbitrary)(0, 3);
return platforms[num];
};
exports.randomPlatform = randomPlatform;
/**Generate a random opera browser user agent string*/
const operaUserAgent = () => {
let platform = '(' +
(0, exports.randomPlatform)() +
'; en-US) Presto/2.' +
(0, chooseRand_1.getRandomArbitrary)(8, 13) +
'.' +
(0, chooseRand_1.getRandomArbitrary)(160, 355) +
' Version/' +
(0, chooseRand_1.getRandomArbitrary)(10, 13) +
'.00';
return ('Opera/' +
(0, chooseRand_1.getRandomArbitrary)(8, 10) +
'.' +
(0, chooseRand_1.getRandomArbitrary)(10, 99) +
' ' +
platform);
};
exports.operaUserAgent = operaUserAgent;
/**Generate firefox user agent browswer string*/
const firefoxUserAgent = () => {
let ver = 'Gecko/' +
(0, time_1.date)().toDateString() +
' Firefox/' +
(0, chooseRand_1.getRandomArbitrary)(35, 58) +
'.0';
let platforms = [
'(' +
(0, exports.windowsPlatformToken)() +
'; ' +
'en-US' +
'; rv:1.9.' +
(0, chooseRand_1.getRandomArbitrary)(0, 3) +
'.20) ' +
ver,
'(' +
(0, exports.linuxPlatformToken)() +
'; rv:' +
(0, chooseRand_1.getRandomArbitrary)(5, 8) +
'.0) ' +
ver,
'(' +
(0, exports.macPlatformToken)() +
' rv:' +
(0, chooseRand_1.getRandomArbitrary)(2, 7) +
'.0) ' +
ver,
];
return ('Mozilla/5.0 ' + platforms[Math.floor(Math.random() * platforms.length)]);
};
exports.firefoxUserAgent = firefoxUserAgent;
/**Generate a random chrome browser user agent string*/
const chromeUserAgent = () => {
let randNum1 = (0, chooseRand_1.getRandomArbitrary)(531, 536).toString() +
(0, chooseRand_1.getRandomArbitrary)(0, 3).toString();
let randNum2 = (0, chooseRand_1.getRandomArbitrary)(36, 41);
let randNum3 = (0, chooseRand_1.getRandomArbitrary)(800, 900);
return ('Mozilla/5.0 ' +
'(' +
(0, exports.randomPlatform)() +
') AppleWebKit/' +
randNum1 +
' (KHTML, like Gecko) Chrome/' +
randNum2 +
'.0.' +
randNum3 +
'.0 Mobile Safari/' +
randNum1);
};
exports.chromeUserAgent = chromeUserAgent;