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.17.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
21K
increased by5.45%
Maintainers
1
Weekly downloads
 
Created
Source

minifaker

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

NPM

npm i minifaker

Why

faker.js is too big and it's not currently supporting tree shaking. https://github.com/Marak/faker.js/issues/785

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.

Better function alternatives

I will deprecate functions with better alternatives.

  • use npm i nanoid to generate string ID
  • use npm i lorem-ipsum to generate lorem words

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.

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, Gender } from 'minifaker'
// There is no default locale import (not even `english`)
import 'minifaker/dist/locales/en' // the first locale import is set as default
import 'minifaker/dist/locales/fr'

minifaker.firstName({ gender: 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/dist/locales/en'

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

Function mapping

Faker.jsLocalesFunc
arrayElementn/aarrayElement
number,floatn/anumber
booleann/aboolean
uuidn/ause nanoid
firstNameen,frfirstName
phoneNumberen,fr,fr-CAphoneNumber
cityNameen,frcityName
cityPrefixencityPrefix
citySuffixencitySufix
imageUrln/aimageUrlFromPlaceIMG
imageUrln/aimageUrlFromPlaceholder
loremn/ause lorem-ipsum
objectElementn/aobjectElement
n/an/aarray
lastNameen,frlastName
jobTitleenjobTitle
jobAreaenjobArea
jobDescriptorenjobDescriptor
jobTypeen,frjobType
nameen,frname
ipn/aip
portn/aport
adjective,adverb,conjunction, interjection,noun,preposition,verbenword
ipv6n/aipv6
colorn/acolor
usernameen,frusername
macn/amacAddress
domainNameen,fr,fr-CAdomainName
domainSuffixen,fr,fr-CAdomainSuffix
emailen,fr,fr-CAemail
urlen,fr,fr-CAdomainUrl
zipCodeen,fr,fr-CAzipCode
streetPrefixfrstreetPrefix
streetSuffixen,frstreetSuffix
streetNameen,frstreetName
streetAddressen,frstreetAddress
timeZoneentimeZone
latiduden/alatidude
longituden/alongitude
n/an/alatLong
direction,cardinalDirection,ordinalDirectionen,frdirection
state,stateAbbren,fr,fr-CAstate
country,countryCodeen,frcountry
priceallprice with Intl.NumberFormat

FAQs

Package last updated on 26 Nov 2021

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