jsfakeit
Version:

140 lines (139 loc) • 5.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bitcoinPrivateKey = exports.bitcoinAddress = exports.isLuhn = exports.achAccount = exports.achRouting = exports.creditCard = exports.creditCardCvv = exports.creditCardNumber = exports.creditCardExp = exports.creditCardType = exports.price = exports.currency = exports.currencyShort = exports.currencyLong = void 0;
const chooseRand_1 = require("../helper/chooseRand");
const currency_1 = require("../data/currency");
const payment_1 = require("../data/payment");
const strings_1 = require("../helper/strings");
const bs58_1 = __importDefault(require("bs58"));
const __1 = require("..");
const replaceWithNumber_1 = require("../helper/replaceWithNumber");
const number_1 = require("../number");
/** Generate a random long currency*/
const currencyLong = () => {
return (0, chooseRand_1.chooseRand)('long', currency_1.currency);
};
exports.currencyLong = currencyLong;
/** Generate a random short currency*/
const currencyShort = () => {
return (0, chooseRand_1.chooseRand)('short', currency_1.currency);
};
exports.currencyShort = currencyShort;
/** Generate currency with random currency information*/
const currency = () => {
const long = (0, exports.currencyLong)();
const short = (0, exports.currencyShort)();
return {
long,
short,
};
};
exports.currency = currency;
/** Price will take in a min and max value and return a formatted price*/
const price = (min, max) => {
return +(0, chooseRand_1.getRandomArbitrary)(min, max).toFixed(2);
};
exports.price = price;
/** CreditCardType will generate a random credit card type string*/
const creditCardType = () => {
const availCardType = Object.keys(payment_1.creditCards);
const i = (0, chooseRand_1.getRandomArbitrary)(0, availCardType.length);
const key = availCardType[i];
return key;
};
exports.creditCardType = creditCardType;
/** CreditCardExp will generate a random credit card expiration date string
Exp date will always be a future date*/
const creditCardExp = () => {
let month = (0, chooseRand_1.getRandomArbitrary)(1, 13).toString();
if (month.length == 1) {
month = `0${month}`;
}
const currentYear = new Date().getFullYear() - 2000;
return `${month}/${(0, chooseRand_1.getRandomArbitrary)(currentYear + 1, currentYear + 10)}`;
};
exports.creditCardExp = creditCardExp;
/** creditCardNumber will generate random credit card number*/
const creditCardNumber = (type) => {
const cc = payment_1.creditCards[type];
const len = (0, number_1.randomNum)(cc.lengths);
let numStr = `${(0, number_1.randomNum)(cc.patterns)}`;
numStr += '#'.repeat(len - numStr.length);
numStr = (0, replaceWithNumber_1.replaceWithNumber)(numStr);
let ui = parseInt(numStr, 10);
let isValid = (0, exports.isLuhn)(`${ui}`);
if (!isValid) {
ui = (0, exports.creditCardNumber)(type);
}
return ui;
};
exports.creditCardNumber = creditCardNumber;
/** Generates random credit card cvv*/
const creditCardCvv = (type) => {
const cc = payment_1.creditCards[type];
const len = cc.code.size;
const hashStr = Array(len).fill('#').join('');
return (0, replaceWithNumber_1.replaceWithNumber)(hashStr);
};
exports.creditCardCvv = creditCardCvv;
/** Generates random credit Card*/
const creditCard = () => {
const ccType = (0, exports.creditCardType)();
return {
type: ccType,
exp: (0, exports.creditCardExp)(),
number: (0, exports.creditCardNumber)(ccType),
cvv: (0, exports.creditCardCvv)(ccType),
};
};
exports.creditCard = creditCard;
/** Generate 9-digit AchRouting number*/
const achRouting = () => {
return (0, replaceWithNumber_1.replaceWithNumber)('#########');
};
exports.achRouting = achRouting;
/** Generate 12-digit AchAccount number*/
const achAccount = () => {
return (0, replaceWithNumber_1.replaceWithNumber)('############');
};
exports.achAccount = achAccount;
//checks is the given number is luhn number
const isLuhn = (num) => {
let a = num
.split('')
.reverse()
.map((a) => +a);
// double every second number
a = a.map((e, i) => (i % 2 != 0 ? 2 * e : e));
// if an element is a 2-digit number , sum the digits
a = a.map((e) => {
const b = e.toString();
if (b.length == 2) {
return +b[0] + +b[1];
}
return +e;
});
//Sum and check if res%10 is 0
const res = a.reduce((acc, e) => acc + e, 0);
return res % 10 == 0;
};
exports.isLuhn = isLuhn;
//BitcoinAddress will generate a random bitcoin address consisting of numbers, upper and lower characters
const bitcoinAddress = () => {
const size = (0, chooseRand_1.getRandomArbitrary)(25, 34);
return `${(0, strings_1.randomString)('13')}${(0, __1.password)(size, true, true, true, false, false)}`;
};
exports.bitcoinAddress = bitcoinAddress;
// BitcoinPrivateKey will generate a random bitcoin private key base58 consisting of numbers, upper and lower characters
const bitcoinPrivateKey = () => {
let res = '';
for (let i = 0; i < 49; i++) {
const c = (0, strings_1.randCharacter)();
res += bs58_1.default.encode(Buffer.from(c));
}
return `5${(0, strings_1.randomString)('HJK')}${res}`;
};
exports.bitcoinPrivateKey = bitcoinPrivateKey;