1.34.1 • Published 2 years ago

minifaker v1.34.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

minifaker

Generate fake data.
An alternative to faker.js with both esm and cjs syntax https://github.com/Marak/faker.js

NPM

npm i minifaker

Supported locales

en | fr, fr-CA | es

Why

faker.js is big, does not support tree shaking and is not in Typescript https://github.com/Marak/faker.js/issues/785

On 2021/01/05, Marak deleted fakerjs from npm and github.

Why not create a pull request to faker.js?

Supporting ES6 modules for faker.js would need a big restructure change.

Right now, I just need a couple of functions and it's faster to create a new package mirroring functions without having to do a lot of refactoring. However, importing the entire package will take work and time, but at least I can start using it without having to finish it.

I also want to use Typescript and introduce new functions.

Duplicates

I've notice that faker locales have duplicate words :S.
I'll try fix the duplicates when importing locale files to reduce size as much as possible.

Replacing old functions with new powerful packages instead

  • nanoid, uuid

Example / usage

Using functions

// You can either import minifaker completely 
// or import the functions you need
import minifaker, { arrayElement } from 'minifaker'
// const minifaker = require('minifaker')

minifaker.number()
arrayElement(['one', 'two', 'three'])

Using locale dependent functions

import minifaker, { cityName } from 'minifaker'
// There is no default locale import (not even `english`)
import 'minifaker/locales/en' // the first locale import is set as default
import 'minifaker/locales/fr'

minifaker.firstName({ gender: 'female' }) // female name in english
cityName({ locale: 'fr' }) // french city name

Generating a list of 50 english names

import { array, name } from 'minifaker'
import 'minifaker/locales/en'

array(50, () => name())

Generating english words

import { word } from 'minifaker'
import 'minifaker/locales/en'

word() // Can be an adjective, adverb, conjunction, interjection, noun, preposition, verb
word({ filter: (word) => word.length > 5 }) // Word with at least 5 characters
word({ type: 'noun' }) // A noun

Word types

verb,preposition,noun, interjection, conjunction, adverb, adjective

Direct access to more performant/popular packages

import { nanoId, uuid, nonsecure } from 'minifaker'

nanoId.nanoid() // nanoid - https://github.com/ai/nanoid
nonsecure.nanoid() // nanoid/non-secure - https://github.com/ai/nanoid/blob/main/non-secure/index.js
uuid.v4() // uuid - https://github.com/uuidjs/uuid

Function mapping

Faker.jsLocalesFunc
random.arrayElementn/aarrayElement
random.number,random.floatn/anumber
random.booleann/aboolean
random.uuidn/auuid -> uuid funcs
n/an/ananoid -> nanoId funcs
name.firstNameen,frfirstName
phone.phoneNumberen,fr,fr-CAphoneNumber
address.cityNameen,frcityName
address.cityPrefixencityPrefix
address.citySuffixencitySufix
image.imageUrln/aimageUrlFromPlaceIMG
image.imageUrln/aimageUrlFromPlaceholder
loremn/atodo
random.objectElementn/aobjectElement
n/an/aarray
name.lastNameen,frlastName
name.jobTitleenjobTitle
name.jobAreaenjobArea
name.jobDescriptorenjobDescriptor
name.jobTypeen,frjobType
n/aen,frname
internet.ipn/aip
internet.portn/aport
adjective,adverb,conjunction,interjection,noun,preposition,verbenword
internet.ipv6n/aipv6
internet.colorn/acolor
internet.usernameen,frusername
internet.macn/amacAddress
internet.domainNameen,fr,fr-CAdomainName
internet.domainSuffixen,fr,fr-CAdomainSuffix
internet.emailen,fr,fr-CAemail
internet.urlen,fr,fr-CAdomainUrl
address.zipCodeen,fr,fr-CAzipCode
address.streetPrefixfrstreetPrefix
address.streetSuffixen,frstreetSuffix
address.streetNameen,frstreetName
address.streetAddressen,frstreetAddress
address.timeZoneentimeZone
address.latituden/alatitude
address.longituden/alongitude
n/an/alatLong
address.direction,address.cardinalDirection,address.ordinalDirectionen,frdirection
address.state,address.stateAbbren,esstate
address.country,address.countryCodeen,frcountry
commerce.priceallprice with Intl.NumberFormat
finance.creditCardNumbern/acreditCardNumber
finance.creditCardCVVn/acreditCardCVV
system.semvern/asemver
internet.passwordn/apassword
date.monthen,frmonth
date.weekdayen,frweekday
datealldate
finance.bitcoinAddressn/abitcoinAddress
system.fileExt,commonFileExtn/afileExt
system.fileName,commonFileNameenfileName
system.filePathenfilePath
system.mimeType,commonMimeTypen/amimeType
system.dirPathn/adirPath
seedn/asetSeed
hexaDecimaln/ahex
address.countyencounty
address.provincefr,es,fr-CAprovince
1.34.1

2 years ago

1.34.0

2 years ago

1.33.1

2 years ago

1.21.0

2 years ago

1.22.0

2 years ago

1.25.0

2 years ago

1.26.0

2 years ago

1.23.0

2 years ago

1.24.0

2 years ago

1.29.0

2 years ago

1.29.1

2 years ago

1.27.0

2 years ago

1.28.0

2 years ago

1.32.0

2 years ago

1.33.0

2 years ago

1.30.0

2 years ago

1.31.0

2 years ago

1.20.0

2 years ago

1.19.0

2 years ago

1.18.0

2 years ago

1.17.0

2 years ago

1.16.0

2 years ago

1.15.0

2 years ago

1.14.0

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago