faker.js是一个用于在浏览器或者node中生成大量逼真的假数据的JavaScript库,它的出现是为了解决我们在开发中遇到无数据需要自己造数据的痛处,faker.js很好的帮助我们解决这个问题!这一个小小的库在Github上高达24k 接近25k的stars,说明对于开发者来说却是帮助很大,得到开发者的认可。对于我们来说最重要的是它支持中文!
安装使用https://github.com/Marak/faker.js
<script src = "faker.js" type = "text/javascript"></script>
<script>
var randomName = faker.name.findName(); // Caitlyn Kerluke
var randomEmail = faker.internet.email(); // Rusty@arne.info
var randomCard = faker.helpers.createCard(); //
</script>
var faker = require('faker');
var randomName = faker.name.findName(); // Rowan Nikolaus
var randomEmail = faker.internet.email(); // Kassandra.Haley@erich.biz
var randomCard = faker.helpers.createCard(); // random contact card containing many properties
支持的数据种类
zipCode
city
cityPrefix
citySuffix
streetName
streetAddress
streetSuffix
streetPrefix
secondaryAddress
county
country
countryCode
state
stateAbbr
latitude
longitude
color
department
productName
price
productAdjective
productMaterial
product
suffixes
companyName
companySuffix
catchPhrase
bs
catchPhraseAdjective
catchPhraseDescriptor
catchPhraseNoun
bsAdjective
bsBuzz
bsNoun
column
type
collation
engine
past
future
between
recent
month
weekday
account
accountName
mask
amount
transactionType
currencyCode
currencyName
currencySymbol
bitcoinAddress
iban
bic
abbreviation
adjective
noun
verb
ingverb
phrase
randomize
slugify
replaceSymbolWithNumber
replaceSymbols
shuffle
mustache
createCard
contextualCard
userCard
createTransaction
image
avatar
imageUrl
abstract
animals
business
cats
city
food
nightlife
fashion
people
nature
sports
technics
transport
dataUri
avatar
exampleEmail
userName
protocol
url
domainName
domainSuffix
domainWord
ip
ipv6
userAgent
color
mac
password
word
words
sentence
slug
sentences
paragraph
paragraphs
text
lines
firstName
lastName
findName
jobTitle
prefix
suffix
title
jobDescriptor
jobArea
jobType
phoneNumber
phoneNumberFormat
phoneFormats
number
arrayElement
objectElement
uuid
boolean
word
words
image
locale
alphaNumeric
国际化支持fileName
commonFileName
mimeType
commonFileType
commonFileExt
fileType
fileExt
directoryPath
filePath
semver
可以看出是支持咱们中文的
faker.locale="zh_CN";
varfaker=require('faker/locale/zh_CN');
总结
faker.js的出现能够在一定程度上提高我们的开发效率,特别是一个项目的开始阶段,不用为造数据而烦恼,着实是个不错的工具库!
Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved