Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

minifaker

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minifaker

lightweight faker.js

  • 1.34.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23K
increased by5.92%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 26 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc