Comparing version 1.17.0 to 1.18.0
@@ -0,1 +1,2 @@ | ||
import { CreditCardProvider } from './data/creditCardProviders'; | ||
export declare const addLocale: (name: string, locale: any) => void; | ||
@@ -195,2 +196,6 @@ export declare const setDefaultLocale: (locale: string) => void; | ||
}) => string; | ||
export { CreditCardProvider }; | ||
export declare const creditCard: (options?: { | ||
provider?: CreditCardProvider; | ||
}) => string; | ||
declare const _default: { | ||
@@ -343,3 +348,6 @@ setDefaultLocale: (locale: string) => void; | ||
}) => string; | ||
creditCard: (options?: { | ||
provider?: CreditCardProvider; | ||
}) => string; | ||
}; | ||
export default _default; |
@@ -0,2 +1,7 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
@@ -8,2 +13,13 @@ var __export = (target, all) => { | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
@@ -13,2 +29,3 @@ // src/index.ts | ||
CountryCodeType: () => CountryCodeType, | ||
CreditCardProvider: () => CreditCardProvider, | ||
DirectionType: () => DirectionType, | ||
@@ -23,5 +40,5 @@ Gender: () => Gender, | ||
addLocale: () => addLocale, | ||
array: () => array, | ||
arrayElement: () => arrayElement, | ||
boolean: () => boolean, | ||
array: () => array2, | ||
arrayElement: () => arrayElement2, | ||
boolean: () => boolean2, | ||
city: () => city, | ||
@@ -33,2 +50,3 @@ cityName: () => cityName, | ||
country: () => country, | ||
creditCard: () => creditCard, | ||
default: () => src_default, | ||
@@ -55,3 +73,3 @@ direction: () => direction, | ||
name: () => name, | ||
number: () => number, | ||
number: () => number2, | ||
objectElement: () => objectElement, | ||
@@ -72,2 +90,152 @@ phoneNumber: () => phoneNumber, | ||
}); | ||
// src/data/creditCardProviders.ts | ||
var americanExpress = [ | ||
"34##-######-####L", | ||
"37##-######-####L" | ||
]; | ||
var dinersClub = [ | ||
"30[0-5]#-######-###L", | ||
"36##-######-###L", | ||
"54##-####-####-###L" | ||
]; | ||
var discover = [ | ||
"6011-####-####-###L", | ||
"65##-####-####-###L", | ||
"64[4-9]#-####-####-###L", | ||
"6011-62##-####-####-###L", | ||
"65##-62##-####-####-###L", | ||
"64[4-9]#-62##-####-####-###L" | ||
]; | ||
var instapayment = [ | ||
"63[7-9]#-####-####-###L" | ||
]; | ||
var jcb = [ | ||
"3528-####-####-###L", | ||
"3529-####-####-###L", | ||
"35[3-8]#-####-####-###L" | ||
]; | ||
var laser = [ | ||
"6304###########L", | ||
"6706###########L", | ||
"6771###########L", | ||
"6709###########L", | ||
"6304#########{5,6}L", | ||
"6706#########{5,6}L", | ||
"6771#########{5,6}L", | ||
"6709#########{5,6}L" | ||
]; | ||
var maestro = [ | ||
"5018-#{4}-#{4}-#{3}L", | ||
"5020-#{4}-#{4}-#{3}L", | ||
"5038-#{4}-#{4}-#{3}L", | ||
"5893-#{4}-#{4}-#{3}L", | ||
"6304-#{4}-#{4}-#{3}L", | ||
"6759-#{4}-#{4}-#{3}L", | ||
"676[1-3]-####-####-###L", | ||
"5018#{11,15}L", | ||
"5020#{11,15}L", | ||
"5038#{11,15}L", | ||
"5893#{11,15}L", | ||
"6304#{11,15}L", | ||
"6759#{11,15}L", | ||
"676[1-3]#{11,15}L" | ||
]; | ||
var mastercard = [ | ||
"5[1-5]##-####-####-###L", | ||
"6771-89##-####-###L" | ||
]; | ||
var solo = [ | ||
"6767-####-####-###L", | ||
"6767-####-####-####-#L", | ||
"6767-####-####-####-##L" | ||
]; | ||
var visa = [ | ||
"4###########L", | ||
"4###-####-####-###L" | ||
]; | ||
var CreditCardProvider; | ||
(function(CreditCardProvider2) { | ||
CreditCardProvider2["SOLO"] = "solo"; | ||
CreditCardProvider2["VISA"] = "visa"; | ||
CreditCardProvider2["MASTERCARD"] = "mastercard"; | ||
CreditCardProvider2["MAESTRO"] = "maestro"; | ||
CreditCardProvider2["LASER"] = "laser"; | ||
CreditCardProvider2["JCB"] = "jcb"; | ||
CreditCardProvider2["INSTAPAYMENT"] = "instapayment"; | ||
CreditCardProvider2["DISCOVER"] = "discover"; | ||
CreditCardProvider2["DINERS_CLUB"] = "dinersClub"; | ||
CreditCardProvider2["AMERICAN_EXPRESS"] = "americanExpress"; | ||
})(CreditCardProvider || (CreditCardProvider = {})); | ||
var creditCardProviders_default = { | ||
visa, | ||
solo, | ||
mastercard, | ||
maestro, | ||
laser, | ||
jcb, | ||
instapayment, | ||
americanExpress, | ||
dinersClub, | ||
discover | ||
}; | ||
// src/helpers/checkLuhn.ts | ||
var checkLuhn_default = (numbers) => { | ||
numbers.reverse(); | ||
let sum = 0; | ||
for (let i = 0; i < numbers.length; i++) { | ||
let digit = numbers[i]; | ||
if (i % 2 === 0) | ||
digit *= 2; | ||
if (digit > 9) | ||
sum -= 9; | ||
sum += digit; | ||
} | ||
return 10 - sum % 10; | ||
}; | ||
// src/helpers/replaceStrings.ts | ||
var import__ = __toModule(require("../index")); | ||
var alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; | ||
var replaceSymbols = (value) => { | ||
return value.split("").map((c) => { | ||
if (c === "#") | ||
return (0, import__.number)({ max: 9 }).toString(); | ||
if (c === "?") | ||
return (0, import__.arrayElement)(alphabet); | ||
if (c === "*") { | ||
if ((0, import__.boolean)()) | ||
return (0, import__.arrayElement)(alphabet); | ||
else | ||
return (0, import__.number)({ max: 9 }).toString(); | ||
} | ||
return c; | ||
}).join(""); | ||
}; | ||
var rangeRepRegex = new RegExp(/(.)\{(\d+)\,(\d+)\}/, "g"); | ||
var repRegex = new RegExp(/(.)\{(\d+)\}/, "g"); | ||
var rangeRegex = new RegExp(/\[(\d+)\-(\d+)\]/, "g"); | ||
var regexMatchAllArray = (value, regex) => [...value.matchAll(regex)]; | ||
var replaceRangeSymbols = (value) => { | ||
let newValue = value.slice(); | ||
regexMatchAllArray(newValue, rangeRepRegex).forEach((values) => { | ||
const [match, symbol, min, max] = values; | ||
const valueToReplace = (0, import__.array)((0, import__.number)({ min: parseInt(min), max: parseInt(max) }), () => replaceSymbols(symbol)).join(""); | ||
newValue = newValue.replace(match, valueToReplace); | ||
}); | ||
regexMatchAllArray(newValue, repRegex).forEach((values) => { | ||
const [match, symbol, count] = values; | ||
const valueToReplace = (0, import__.array)(parseInt(count), () => replaceSymbols(symbol)).join(""); | ||
newValue = newValue.replace(match, valueToReplace); | ||
}); | ||
regexMatchAllArray(newValue, rangeRegex).forEach((values) => { | ||
const [match, min, max] = values; | ||
const valueToReplace = (0, import__.number)({ min: parseInt(min), max: parseInt(max) }).toString(); | ||
newValue = newValue.replace(match, valueToReplace); | ||
}); | ||
return newValue; | ||
}; | ||
// src/index.ts | ||
var locales = {}; | ||
@@ -109,3 +277,3 @@ var defaultLocale = null; | ||
}; | ||
var number = (options = {}) => { | ||
var number2 = (options = {}) => { | ||
const { min, max, float } = { min: 0, max: 1, float: false, ...options }; | ||
@@ -117,9 +285,9 @@ const value = min + Math.random() * (max - min); | ||
}; | ||
var boolean = () => { | ||
return !!number({ max: 1 }); | ||
var boolean2 = () => { | ||
return !!number2({ max: 1 }); | ||
}; | ||
var arrayElement = (array2) => { | ||
return array2[number({ max: array2.length - 1 })]; | ||
var arrayElement2 = (array3) => { | ||
return array3[number2({ max: array3.length - 1 })]; | ||
}; | ||
var array = (count, cb) => { | ||
var array2 = (count, cb) => { | ||
let newArray = []; | ||
@@ -135,3 +303,3 @@ for (let i = 0; i < count; i++) { | ||
const keys = Object.keys(obj); | ||
const key = arrayElement(keys); | ||
const key = arrayElement2(keys); | ||
return { key, value: obj[key] }; | ||
@@ -149,9 +317,9 @@ }; | ||
const femaleFirstNames = getLocaleData({ locale, key: "femaleFirstNames" }); | ||
return arrayElement(femaleFirstNames); | ||
return arrayElement2(femaleFirstNames); | ||
case Gender.MALE: | ||
const maleFirstNames = getLocaleData({ locale, key: "maleFirstNames" }); | ||
return arrayElement(maleFirstNames); | ||
return arrayElement2(maleFirstNames); | ||
default: | ||
const firstNames = getLocaleData({ locale, key: "firstNames" }); | ||
return arrayElement(firstNames); | ||
return arrayElement2(firstNames); | ||
} | ||
@@ -162,5 +330,5 @@ }; | ||
const phoneFormats = formats || getLocaleData({ locale, key: "phoneFormats" }); | ||
return arrayElement(phoneFormats).split("").map((c) => { | ||
return arrayElement2(phoneFormats).split("").map((c) => { | ||
if (c === "#") | ||
return number({ max: 9 }); | ||
return number2({ max: 9 }); | ||
return c; | ||
@@ -175,3 +343,3 @@ }).join(""); | ||
const cityNames = getLocaleData({ locale, key: "cityNames" }); | ||
return arrayElement(cityNames); | ||
return arrayElement2(cityNames); | ||
}; | ||
@@ -181,3 +349,3 @@ var cityPrefix = (options = {}) => { | ||
const cityPrefixes = getLocaleData({ locale, key: "cityPrefixes" }); | ||
return arrayElement(cityPrefixes); | ||
return arrayElement2(cityPrefixes); | ||
}; | ||
@@ -187,3 +355,3 @@ var citySuffix = (options = {}) => { | ||
const citySuffixes = getLocaleData({ locale, key: "citySuffixes" }); | ||
return arrayElement(citySuffixes); | ||
return arrayElement2(citySuffixes); | ||
}; | ||
@@ -227,3 +395,3 @@ var PlaceImgCategory; | ||
const lastNames = getLocaleData({ locale, key: "lastNames" }); | ||
return arrayElement(lastNames); | ||
return arrayElement2(lastNames); | ||
}; | ||
@@ -239,3 +407,3 @@ var name = (options) => { | ||
const jobTypes = getLocaleData({ locale, key: "jobTypes" }); | ||
return arrayElement(jobTypes); | ||
return arrayElement2(jobTypes); | ||
}; | ||
@@ -245,3 +413,3 @@ var jobArea = (options = {}) => { | ||
const jobLevels = getLocaleData({ locale, key: "jobLevels" }); | ||
return arrayElement(jobLevels); | ||
return arrayElement2(jobLevels); | ||
}; | ||
@@ -251,12 +419,12 @@ var jobDescriptor = (options = {}) => { | ||
const jobDescriptors = getLocaleData({ locale, key: "jobDescriptors" }); | ||
return arrayElement(jobDescriptors); | ||
return arrayElement2(jobDescriptors); | ||
}; | ||
var ip = () => { | ||
return array(4, () => number({ max: 255 })).join("."); | ||
return array2(4, () => number2({ max: 255 })).join("."); | ||
}; | ||
var port = () => { | ||
return number({ max: 65535 }); | ||
return number2({ max: 65535 }); | ||
}; | ||
var ipv6 = () => { | ||
return array(8, () => number({ max: 65535 }).toString(16)).join(":"); | ||
return array2(8, () => number2({ max: 65535 }).toString(16)).join(":"); | ||
}; | ||
@@ -270,5 +438,5 @@ var hexPadLeft = (value) => { | ||
const { r, g, b } = options; | ||
const red = (r || number({ max: 256 })).toString(16); | ||
const green = (g || number({ max: 256 })).toString(16); | ||
const blue = (b || number({ max: 256 })).toString(16); | ||
const red = (r || number2({ max: 256 })).toString(16); | ||
const green = (g || number2({ max: 256 })).toString(16); | ||
const blue = (b || number2({ max: 256 })).toString(16); | ||
return `#${hexPadLeft(red)}${hexPadLeft(green)}${hexPadLeft(blue)}`; | ||
@@ -288,7 +456,7 @@ }; | ||
const { type, locale, filter } = options; | ||
const _type = type || arrayElement(Object.values(WordType)); | ||
const _type = type || arrayElement2(Object.values(WordType)); | ||
const adjectives = getLocaleData({ locale, key: `${_type}s` }); | ||
if (typeof filter === "function") | ||
return arrayElement(adjectives.filter(filter)); | ||
return arrayElement(adjectives); | ||
return arrayElement2(adjectives.filter(filter)); | ||
return arrayElement2(adjectives); | ||
}; | ||
@@ -299,10 +467,10 @@ var username = (options = {}) => { | ||
const newLastName = _lastName || lastName({ locale }); | ||
const type = typeof _type !== "undefined" ? _type : number({ max: 2 }); | ||
const type = typeof _type !== "undefined" ? _type : number2({ max: 2 }); | ||
switch (type) { | ||
case 0: | ||
return newFirstName + number({ max: 99 }); | ||
return newFirstName + number2({ max: 99 }); | ||
case 1: | ||
return newFirstName + arrayElement([".", "_"]) + newLastName; | ||
return newFirstName + arrayElement2([".", "_"]) + newLastName; | ||
case 2: | ||
return newFirstName + arrayElement([".", "_"]) + newLastName + number({ max: 99 }); | ||
return newFirstName + arrayElement2([".", "_"]) + newLastName + number2({ max: 99 }); | ||
} | ||
@@ -330,4 +498,4 @@ }; | ||
const { separator = MacAddressSeparator.COLON, transmission, administration } = options; | ||
const mac = array(6, (index) => { | ||
let value = number({ max: 255 }); | ||
const mac = array2(6, (index) => { | ||
let value = number2({ max: 255 }); | ||
if (index === 0) { | ||
@@ -359,3 +527,3 @@ if (transmission === MacAddressTransmission.MULTICAST) | ||
const freeEmails = getLocaleData({ locale, key: "freeEmails" }); | ||
const provider = _provider || arrayElement(freeEmails); | ||
const provider = _provider || arrayElement2(freeEmails); | ||
return `${username(options)}@${provider}`; | ||
@@ -365,3 +533,3 @@ }; | ||
const { locale } = options; | ||
const name2 = arrayElement([ | ||
const name2 = arrayElement2([ | ||
word({ locale, type: WordType.NOUN }), | ||
@@ -375,3 +543,3 @@ firstName({ locale }) | ||
const domainSuffixes = getLocaleData({ locale, key: "domainSuffixes" }); | ||
return arrayElement(domainSuffixes); | ||
return arrayElement2(domainSuffixes); | ||
}; | ||
@@ -381,21 +549,8 @@ var domainUrl = (options = {}) => `https://${domainName(options)}`; | ||
const { locale, format: _format } = options; | ||
const alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; | ||
let format = _format; | ||
if (!format) { | ||
const formats = getLocaleData({ locale, key: "postCodeFormats" }); | ||
format = arrayElement(formats); | ||
format = arrayElement2(formats); | ||
} | ||
return format.split("").map((c) => { | ||
if (c === "#") | ||
return number({ max: 9 }).toString(); | ||
if (c === "?") | ||
return arrayElement(alphabet); | ||
if (c === "*") { | ||
if (boolean()) | ||
return arrayElement(alphabet); | ||
else | ||
return number({ max: 9 }).toString(); | ||
} | ||
return c; | ||
}).join(""); | ||
return replaceSymbols(format); | ||
}; | ||
@@ -405,3 +560,3 @@ var streetSuffix = (options = {}) => { | ||
const streetSuffixes = getLocaleData({ locale, key: "streetSuffixes" }); | ||
return arrayElement(streetSuffixes); | ||
return arrayElement2(streetSuffixes); | ||
}; | ||
@@ -411,9 +566,9 @@ var streetPrefix = (options = {}) => { | ||
const streetSuffixes = getLocaleData({ locale, key: "streetPrefixes" }); | ||
return arrayElement(streetSuffixes); | ||
return arrayElement2(streetSuffixes); | ||
}; | ||
var streetName = (options = {}) => { | ||
return `${arrayElement([firstName(options), lastName(options)])} ${streetSuffix(options)}`; | ||
return `${arrayElement2([firstName(options), lastName(options)])} ${streetSuffix(options)}`; | ||
}; | ||
var streetAddress = (options = {}) => { | ||
const streetNumber = array(number({ min: 3, max: 5 }), () => number({ max: 9 })).join(""); | ||
const streetNumber = array2(number2({ min: 3, max: 5 }), () => number2({ max: 9 })).join(""); | ||
return `${streetNumber} ${streetName(options)}`; | ||
@@ -424,9 +579,9 @@ }; | ||
const timeZones = getLocaleData({ locale, key: "timeZones" }); | ||
return arrayElement(timeZones); | ||
return arrayElement2(timeZones); | ||
}; | ||
var latidude = () => { | ||
return number({ min: -90, max: 90, float: true }).toFixed(6); | ||
return number2({ min: -90, max: 90, float: true }).toFixed(6); | ||
}; | ||
var longitude = () => { | ||
return number({ min: -180, max: 180, float: true }).toFixed(6); | ||
return number2({ min: -180, max: 180, float: true }).toFixed(6); | ||
}; | ||
@@ -447,4 +602,4 @@ var latLong = () => { | ||
if (type) | ||
return arrayElement(directions[type].map(mapValue)); | ||
return arrayElement(allDirections.map(mapValue)); | ||
return arrayElement2(directions[type].map(mapValue)); | ||
return arrayElement2(allDirections.map(mapValue)); | ||
}; | ||
@@ -454,3 +609,3 @@ var state = (options = {}) => { | ||
const states = useAbbr ? getLocaleData({ locale, key: "stateAbbrs" }) : getLocaleData({ locale, key: "states" }); | ||
return arrayElement(states); | ||
return arrayElement2(states); | ||
}; | ||
@@ -475,3 +630,3 @@ var CountryCodeType; | ||
const countries = getLocaleData({ locale, key: getLocaleDataKey() }); | ||
return arrayElement(countries); | ||
return arrayElement2(countries); | ||
}; | ||
@@ -483,4 +638,15 @@ var price = (options = {}) => { | ||
const formatter = new Intl.NumberFormat(locale, { style: "currency", currency }); | ||
return formatter.format(number({ min, max, float: true })); | ||
return formatter.format(number2({ min, max, float: true })); | ||
}; | ||
var creditCard = (options = {}) => { | ||
const { provider } = options; | ||
const providerFormats = provider ? creditCardProviders_default[provider] : Object.values(creditCardProviders_default).flat(); | ||
let cardNumberFormat = arrayElement2(providerFormats); | ||
cardNumberFormat = replaceSymbols(cardNumberFormat); | ||
cardNumberFormat = replaceRangeSymbols(cardNumberFormat); | ||
const cardNumbers = cardNumberFormat.replace(/\D/g, "").split("").map((v) => parseInt(v)); | ||
const luhnNumber = checkLuhn_default(cardNumbers); | ||
cardNumberFormat = cardNumberFormat.replace("L", luhnNumber.toString()); | ||
return cardNumberFormat; | ||
}; | ||
var src_default = { | ||
@@ -492,7 +658,7 @@ setDefaultLocale, | ||
cityPrefix, | ||
number, | ||
number: number2, | ||
phoneNumber, | ||
firstName, | ||
arrayElement, | ||
boolean, | ||
arrayElement: arrayElement2, | ||
boolean: boolean2, | ||
city, | ||
@@ -502,3 +668,3 @@ imageUrlFromPlaceIMG, | ||
objectElement, | ||
array, | ||
array: array2, | ||
lastName, | ||
@@ -533,3 +699,4 @@ name, | ||
country, | ||
price | ||
price, | ||
creditCard | ||
}; | ||
@@ -539,2 +706,3 @@ // Annotate the CommonJS export names for ESM import in node: | ||
CountryCodeType, | ||
CreditCardProvider, | ||
DirectionType, | ||
@@ -558,2 +726,3 @@ Gender, | ||
country, | ||
creditCard, | ||
direction, | ||
@@ -560,0 +729,0 @@ domainName, |
{ | ||
"name": "minifaker", | ||
"version": "1.17.0", | ||
"version": "1.18.0", | ||
"description": "lightweight faker.js", | ||
@@ -14,3 +14,3 @@ "types": "./dist/index.d.ts", | ||
"test": "jest --coverage", | ||
"build": "ts-node bundle.ts && tsc ./src/index.ts --declaration --emitDeclarationOnly --outdir dist", | ||
"build": "ts-node bundle.ts && tsc ./src/index.ts --declaration --emitDeclarationOnly --downlevelIteration --outdir dist", | ||
"prepublishOnly": "npm run build" | ||
@@ -29,5 +29,6 @@ }, | ||
"jest": "^27.3.1", | ||
"jest-extended": "^1.1.0", | ||
"ts-jest": "^27.0.7", | ||
"ts-node": "^10.4.0" | ||
} | ||
} | ||
} |
@@ -119,1 +119,2 @@ # minifaker | ||
price|all|price with `Intl.NumberFormat` | ||
creditCardNumber|n/a|creditCard |
Sorry, the diff of this file is not supported yet
600025
16
42626
120
6