faker vs chance vs mockjs vs casual vs random-words
随机数据生成库
fakerchancemockjscasualrandom-words类似的npm包:

随机数据生成库

随机数据生成库用于生成各种类型的随机数据,通常用于测试、开发和模拟环境中。这些库可以帮助开发者快速生成假数据,以便在开发过程中进行测试,确保应用程序的功能正常。不同的库提供了不同的功能和灵活性,适用于不同的使用场景。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
faker2,553,097-10.1 MB--MIT
chance2,354,4146,5552.13 MB17710 个月前MIT
mockjs85,37119,653-3426 年前-
casual03,010-417 年前MIT
random-words025646.1 kB112 年前MIT

功能对比: faker vs chance vs mockjs vs casual vs random-words

数据生成能力

  • faker:

    Faker专注于生成与现实世界相关的假数据,支持多种语言和地区,能够生成姓名、公司、地址等真实感强的数据。

  • chance:

    Chance提供丰富的数据生成选项,包括随机数、日期、颜色、地址等,支持多种数据类型,适合复杂数据生成需求。

  • mockjs:

    Mock.js能够根据定义的规则生成复杂的JSON数据,支持模拟RESTful API,适合前端开发者进行接口测试。

  • casual:

    Casual提供简单的API来生成基本的随机数据,如姓名、地址、电话号码等,适合快速生成少量数据。

  • random-words:

    Random-words专注于生成随机单词,适合需要随机文本的场景,使用简单,功能单一。

灵活性与扩展性

  • faker:

    Faker支持多种语言和地区的自定义,灵活性高,适合多种应用场景。

  • chance:

    Chance具有较高的灵活性,支持自定义生成器,可以根据需求扩展功能。

  • mockjs:

    Mock.js允许用户自定义数据结构和API响应,灵活性强,适合复杂的前端开发需求。

  • casual:

    Casual的灵活性较低,主要用于简单的数据生成,不支持复杂的自定义。

  • random-words:

    Random-words功能简单,灵活性较低,主要用于生成随机单词,不支持复杂的扩展。

学习曲线

  • faker:

    Faker的学习曲线较为平缓,文档清晰,易于理解和使用。

  • chance:

    Chance的学习曲线相对平缓,但由于功能较多,可能需要一定时间来熟悉。

  • mockjs:

    Mock.js的学习曲线稍陡,需要理解如何定义规则和模拟API,但文档详细,易于掌握。

  • casual:

    Casual的学习曲线非常平缓,易于上手,适合初学者使用。

  • random-words:

    Random-words的学习曲线非常平缓,使用简单,几乎不需要学习成本。

社区支持与维护

  • faker:

    Faker拥有活跃的社区和频繁的更新,适合长期项目使用。

  • chance:

    Chance有较好的社区支持,更新频繁,适合长期使用。

  • mockjs:

    Mock.js有良好的社区支持,更新频繁,适合前端开发者的需求。

  • casual:

    Casual的社区支持相对较小,更新频率较低,可能不适合长期项目。

  • random-words:

    Random-words的社区支持较小,更新频率较低,适合简单项目。

如何选择: faker vs chance vs mockjs vs casual vs random-words

  • faker:

    选择Faker如果你需要生成大量的假数据,尤其是针对真实世界的模拟数据,如姓名、地址、公司等。它非常适合用于测试和填充数据库。

  • chance:

    选择Chance如果你需要更丰富的功能和灵活性,支持多种数据类型的生成。它适合需要生成复杂数据结构的项目。

  • mockjs:

    选择Mock.js如果你需要一个强大的工具来模拟API请求和响应,适合前端开发时进行接口调试。它可以轻松生成复杂的JSON数据结构。

  • casual:

    选择Casual如果你需要一个简单易用的库,快速生成随机数据,且不需要太多复杂的配置。它适合小型项目或快速原型开发。

  • random-words:

    选择Random-words如果你只需要生成随机单词,适合生成简单的文本数据,尤其是在需要随机字符串的场景中。

faker的README

faker.js - generate massive amounts of fake data in the browser and node.js

Faker.js

Build Status Coverage Status

npm version

OpenCollective OpenCollective Gitter chat

Demo

https://rawgit.com/Marak/faker.js/master/examples/browser/index.html

Faker Cloud

Don't have a local development setup ready?

Try our hosted version of Faker at https://fakercloud.com/api

https://github.com/faker/faker-cloud

Usage

Browser

    <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(); // random contact card containing many properties
    </script>

Node.js

    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

API

JSDoc API Browser

http://marak.github.io/faker.js/

API Methods

  • address
    • zipCode
    • zipCodeByState
    • city
    • cityPrefix
    • citySuffix
    • cityName
    • streetName
    • streetAddress
    • streetSuffix
    • streetPrefix
    • secondaryAddress
    • county
    • country
    • countryCode
    • state
    • stateAbbr
    • latitude
    • longitude
    • direction
    • cardinalDirection
    • ordinalDirection
    • nearbyGPSCoordinate
    • timeZone
  • animal
    • dog
    • cat
    • snake
    • bear
    • lion
    • cetacean
    • horse
    • bird
    • cow
    • fish
    • crocodilia
    • insect
    • rabbit
    • type
  • commerce
    • color
    • department
    • productName
    • price
    • productAdjective
    • productMaterial
    • product
    • productDescription
  • company
    • suffixes
    • companyName
    • companySuffix
    • catchPhrase
    • bs
    • catchPhraseAdjective
    • catchPhraseDescriptor
    • catchPhraseNoun
    • bsAdjective
    • bsBuzz
    • bsNoun
  • database
    • column
    • type
    • collation
    • engine
  • datatype
    • number
    • float
    • datetime
    • string
    • uuid
    • boolean
    • hexaDecimal
    • json
    • array
  • date
    • past
    • future
    • between
    • betweens
    • recent
    • soon
    • month
    • weekday
  • fake
  • finance
    • account
    • accountName
    • routingNumber
    • mask
    • amount
    • transactionType
    • currencyCode
    • currencyName
    • currencySymbol
    • bitcoinAddress
    • litecoinAddress
    • creditCardNumber
    • creditCardCVV
    • ethereumAddress
    • iban
    • bic
    • transactionDescription
  • git
    • branch
    • commitEntry
    • commitMessage
    • commitSha
    • shortSha
  • hacker
    • abbreviation
    • adjective
    • noun
    • verb
    • ingverb
    • phrase
  • helpers
    • randomize
    • slugify
    • replaceSymbolWithNumber
    • replaceSymbols
    • replaceCreditCardSymbols
    • repeatString
    • regexpStyleStringParse
    • shuffle
    • mustache
    • createCard
    • contextualCard
    • userCard
    • createTransaction
  • image
    • image
    • avatar
    • imageUrl
    • abstract
    • animals
    • business
    • cats
    • city
    • food
    • nightlife
    • fashion
    • people
    • nature
    • sports
    • technics
    • transport
    • dataUri
    • lorempixel
    • unsplash
    • lorempicsum
  • internet
    • avatar
    • email
    • exampleEmail
    • userName
    • protocol
    • httpMethod
    • url
    • domainName
    • domainSuffix
    • domainWord
    • ip
    • ipv6
    • port
    • userAgent
    • color
    • mac
    • password
  • lorem
    • word
    • words
    • sentence
    • slug
    • sentences
    • paragraph
    • paragraphs
    • text
    • lines
  • mersenne
    • rand
    • seed
    • seed_array
  • music
    • genre
  • name
    • firstName
    • lastName
    • middleName
    • findName
    • jobTitle
    • gender
    • prefix
    • suffix
    • title
    • jobDescriptor
    • jobArea
    • jobType
  • phone
    • phoneNumber
    • phoneNumberFormat
    • phoneFormats
  • random
    • number
    • float
    • arrayElement
    • arrayElements
    • objectElement
    • uuid
    • boolean
    • word
    • words
    • image
    • locale
    • alpha
    • alphaNumeric
    • hexaDecimal
  • system
    • fileName
    • commonFileName
    • mimeType
    • commonFileType
    • commonFileExt
    • fileType
    • fileExt
    • directoryPath
    • filePath
    • semver
  • time
    • recent
  • unique
  • vehicle
    • vehicle
    • manufacturer
    • model
    • type
    • fuel
    • vin
    • color
    • vrm
    • bicycle

Faker.fake()

faker.js contains a super useful generator method Faker.fake for combining faker API methods using a mustache string format.

Example:

console.log(faker.fake("{{name.lastName}}, {{name.firstName}} {{name.suffix}}"));
// outputs: "Marks, Dean Sr."

This will interpolate the format string with the value of methods name.lastName(), name.firstName(), and name.suffix()

Localization

As of version v2.0.0 faker.js has support for multiple localities.

The default language locale is set to English.

Setting a new locale is simple:

// sets locale to de
faker.locale = "de";
  • az
  • ar
  • cz
  • de
  • de_AT
  • de_CH
  • en
  • en_AU
  • en_AU_ocker
  • en_BORK
  • en_CA
  • en_GB
  • en_IE
  • en_IND
  • en_US
  • en_ZA
  • es
  • es_MX
  • fa
  • fi
  • fr
  • fr_CA
  • fr_CH
  • ge
  • hy
  • hr
  • id_ID
  • it
  • ja
  • ko
  • nb_NO
  • ne
  • nl
  • nl_BE
  • pl
  • pt_BR
  • pt_PT
  • ro
  • ru
  • sk
  • sv
  • tr
  • uk
  • vi
  • zh_CN
  • zh_TW

Individual Localization Packages

faker.js supports incremental loading of locales.

By default, requiring faker will include all locale data.

In a production environment, you may only want to include the locale data for a specific set of locales.

// loads only de locale
var faker = require('faker/locale/de');

Setting a randomness seed

If you want consistent results, you can set your own seed:

faker.seed(123);

var firstRandom = faker.datatype.number();

// Setting the seed again resets the sequence.
faker.seed(123);

var secondRandom = faker.datatype.number();

console.log(firstRandom === secondRandom);

Tests

npm install .
make test

You can view a code coverage report generated in coverage/lcov-report/index.html.

Building faker.js

faker uses gulp to automate its build process. Each build operation is a separate task which can be run independently.

Browser Bundle

npm run browser

Building JSDocs

JSDOC v3 HTML API documentation

npm run jsdoc

Building ReadMe

The ReadMe.md file for faker.js is automatically generated and should not be modified directly. All updates to ReadMe.md should be performed in ./build/src/docs.md and then the build script should be run.

npm run readme

Version Release Schedule

faker.js is a popular project used by many organizations and individuals in production settings. Major and Minor version releases are generally on a monthly schedule. Bugs fixes are addressed by severity and fixed as soon as possible.

If you require the absolute latest version of faker.js the master branch @ http://github.com/marak/faker.js/ should always be up to date and working.

Maintainer

Marak Squires

faker.js - Copyright (c) 2020 Marak Squires www.marak.com http://github.com/marak/faker.js/

faker.js was inspired by and has used data definitions from:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Backers

Support us with a monthly donation and help us continue our activities. [Become a backer]

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]