randexp vs faker vs chance vs casual
データ生成ライブラリ
randexpfakerchancecasual類似パッケージ:
データ生成ライブラリ

データ生成ライブラリは、テストや開発の目的でランダムなデータを生成するためのツールです。これらのライブラリは、ユーザーが必要とするさまざまなデータタイプ(名前、住所、日付など)を簡単に生成できるように設計されています。これにより、開発者はリアルなデータを模倣し、アプリケーションの動作をテストすることができます。

npmのダウンロードトレンド
3 年
GitHub Starsランキング
統計詳細
パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
randexp5,670,6031,865-147年前MIT
faker2,010,374-10.1 MB--MIT
chance1,732,6926,5542.13 MB1776ヶ月前MIT
casual187,4223,019-417年前MIT
機能比較: randexp vs faker vs chance vs casual

データ生成の柔軟性

  • randexp:

    Randexpは、正規表現を使用してデータを生成するため、特定のパターンに従ったデータ生成が可能です。特に、カスタムデータが必要な場合に役立ちます。

  • faker:

    Fakerは、国際化されたデータを生成するための多言語サポートがあり、特にリアルなデータが必要な場合に優れています。

  • chance:

    Chanceは、さまざまなデータタイプ(名前、住所、日付など)を生成でき、非常に柔軟です。特に、複雑なデータが必要な場合に適しています。

  • casual:

    Casualは、基本的なデータ生成機能を提供し、簡単なテストデータを迅速に生成できます。特に、シンプルなデータが必要な場合に便利です。

APIの使いやすさ

  • randexp:

    Randexpは、正規表現を理解している必要があるため、他のライブラリに比べて学習曲線が急です。特定のパターンに従ったデータが必要な場合に選択すると良いでしょう。

  • faker:

    Fakerは、さまざまなロケールに対応したデータ生成が可能ですが、APIはやや複雑です。特に、特定の国のデータが必要な場合に便利です。

  • chance:

    Chanceは、豊富な機能を持ちながらも、比較的直感的なAPIを提供しています。多様なデータ生成が可能ですが、学習曲線は緩やかです。

  • casual:

    Casualは、シンプルなAPIを提供しており、初心者でも簡単に使用できます。特に、迅速なプロトタイピングに適しています。

データの一貫性

  • randexp:

    Randexpは、正規表現に基づいてデータを生成するため、一貫性のあるパターンに従ったデータが得られます。特に、カスタムパターンが必要な場合に便利です。

  • faker:

    Fakerは、リアルなデータを模倣するため、一貫性が高いデータを生成します。特に、実際のデータに近いデータが必要な場合に適しています。

  • chance:

    Chanceは、生成されるデータの一貫性が高く、特にユニークなデータが必要な場合に強力です。

  • casual:

    Casualは、生成されるデータの一貫性が比較的高いですが、特に複雑なデータ構造には向いていません。

パフォーマンス

  • randexp:

    Randexpは、正規表現を使用するため、複雑なパターンのデータ生成には時間がかかることがありますが、特定のニーズに応じたデータが得られます。

  • faker:

    Fakerは、リアルなデータを生成するため、ややパフォーマンスが低下することがありますが、必要なデータの質を重視する場合に選択できます。

  • chance:

    Chanceは、豊富な機能を持ちながらも、パフォーマンスは良好です。特に、大量のデータを生成する場合に適しています。

  • casual:

    Casualは、軽量で高速なデータ生成が可能ですが、機能は限られています。

ユースケース

  • randexp:

    Randexpは、特定のパターンに従ったデータが必要な場合に最適です。特に、カスタムなデータ形式が必要な場合に役立ちます。

  • faker:

    Fakerは、国際化されたアプリケーションや、リアルなデータが必要な場合に最適です。特に、ユーザー情報や製品情報の生成に適しています。

  • chance:

    Chanceは、さまざまなデータタイプが必要な場合に適しており、特にユニークなデータを生成する際に便利です。

  • casual:

    Casualは、シンプルなテストデータが必要な場合に最適です。特に、軽量なアプリケーションやプロトタイプに適しています。

選び方: randexp vs faker vs chance vs casual
  • randexp:

    Randexpは、正規表現を使用してデータを生成するため、特定のパターンに従ったデータが必要な場合に選択すると良いでしょう。特に、カスタムなデータ形式が必要な場合に便利です。

  • faker:

    Fakerは、特に国際化されたデータ生成に強みを持っています。多言語対応のデータが必要な場合や、リアルなデータを模倣したい場合に最適です。

  • chance:

    Chanceは、豊富な機能を持ち、より多様なデータ生成が可能です。特に、ユニークなデータや複雑なデータ構造が必要な場合におすすめです。

  • casual:

    Casualは、シンプルで使いやすいAPIを提供し、特に軽量なデータ生成が必要な場合に適しています。特定のデータ形式が必要ない場合や、簡単なテストデータを生成したい場合に選択すると良いでしょう。

randexp のREADME

randexp.js

randexp will generate a random string that matches a given RegExp Javascript object.

Build Status Dependency Status codecov

Usage

const RandExp = require('randexp');

// supports grouping and piping
new RandExp(/hello+ (world|to you)/).gen();
// => hellooooooooooooooooooo world

// sets and ranges and references
new RandExp(/<([a-z]\w{0,20})>foo<\1>/).gen();
// => <m5xhdg>foo<m5xhdg>

// wildcard
new RandExp(/random stuff: .+/).gen();
// => random stuff: l3m;Hf9XYbI [YPaxV>U*4-_F!WXQh9>;rH3i l!8.zoh?[utt1OWFQrE ^~8zEQm]~tK

// ignore case
new RandExp(/xxx xtreme dragon warrior xxx/i).gen();
// => xxx xtReME dRAGON warRiOR xXX

// dynamic regexp shortcut
new RandExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i');
// is the same as
new RandExp(new RegExp('(sun|mon|tue|wednes|thurs|fri|satur)day', 'i'));

If you're only going to use gen() once with a regexp and want slightly shorter syntax for it

const randexp = require('randexp').randexp;

randexp(/[1-6]/); // 4
randexp('great|good( job)?|excellent'); // great

If you miss the old syntax

require('randexp').sugar();

/yes|no|maybe|i don't know/.gen(); // maybe

Motivation

Regular expressions are used in every language, every programmer is familiar with them. Regex can be used to easily express complex strings. What better way to generate a random string than with a language you can use to express the string you want?

Thanks to String-Random for giving me the idea to make this in the first place and randexp for the sweet .gen() syntax.

Default Range

The default generated character range includes printable ASCII. In order to add or remove characters, a defaultRange attribute is exposed. you can subtract(from, to) and add(from, to)

const randexp = new RandExp(/random stuff: .+/);
randexp.defaultRange.subtract(32, 126);
randexp.defaultRange.add(0, 65535);
randexp.gen();
// => random stuff: 湐箻ໜ䫴␩⶛㳸長���邓蕲뤀쑡篷皇硬剈궦佔칗븛뀃匫鴔事좍ﯣ⭼ꝏ䭍詳蒂䥂뽭

You can also change the default range by changing RandExp.prototype.defaultRange.

Custom PRNG

The default randomness is provided by Math.random(). If you need to use a seedable or cryptographic PRNG, you can override RandExp.prototype.randInt or randexp.randInt (where randexp is an instance of RandExp). randInt(from, to) accepts an inclusive range and returns a randomly selected number within that range.

Infinite Repetitionals

Repetitional tokens such as *, +, and {3,} have an infinite max range. In this case, randexp looks at its min and adds 100 to it to get a useable max value. If you want to use another int other than 100 you can change the max property in RandExp.prototype or the RandExp instance.

const randexp = new RandExp(/no{1,}/);
randexp.max = 1000000;

With RandExp.sugar()

const regexp = /(hi)*/;
regexp.max = 1000000;

Bad Regular Expressions

There are some regular expressions which can never match any string.

  • Ones with badly placed positionals such as /a^/ and /$c/m. Randexp will ignore positional tokens.

  • Back references to non-existing groups like /(a)\1\2/. Randexp will ignore those references, returning an empty string for them. If the group exists only after the reference is used such as in /\1 (hey)/, it will too be ignored.

  • Custom negated character sets with two sets inside that cancel each other out. Example: /[^\w\W]/. If you give this to randexp, it will return an empty string for this set since it can't match anything.

Projects based on randexp.js

JSON-Schema Faker

Use generators to populate JSON Schema samples. See: jsf on github and jsf demo page.

Install

Node.js

npm install randexp

Browser

Download the minified version from the latest release.

Tests

Tests are written with mocha

npm test

Integration with TypeScript

RandExp includes TypeScript definitions.

import * as RandExp from "randexp";
const randexp = new RandExp(/[a-z]{6}/);
randexp.gen();

Use dtslint to check the definition file.

npm install -g dtslint
npm run dtslint