test-data-printer
v0.3.24
Published
日本語のそれっぽいテストデータを生成します。
Downloads
43
Readme
test-data-printer
テストデータの自動生成ツールです。 式言語風にデータ型を指定すると、それっぽいデータを吐き出してくれます。
why this?
ダミー生成ツールは世にたくさんありますが、 生成したデータをDBに入れるための整形が手間でしかたない!ということでこれを作りました。
- EDMファイルからの列定義取得
- 式言語でのダミーデータ指定
ができます。
requirements
install
npm install test-data-printer -g
quick start
step1
EDMファイルをもとにして、ダミーデータ指定のためのseedファイルを作成します。 seedファイルはテーブルの数だけ作成されます。
csvprint seed <edm_file> <seed_dir>
step2 自動生成されたseedファイルに、ダミーデータの指定を書き込みます。
各列にどのようなデータを入れるかを、埋め込みます。 ${}の中に自由にJavaScriptを埋め込めます。 個人情報などのダミーデータは事前に変数・関数として用意されています。
vi <seed_file>
/** example **/
Object.prototype.repeat = function (count) {
this._repeat = count;
return this;
};
module.exports = {
/** CSVヘッダー **/
headers: ["CUST_CODE", "CUST_NAME", "ZIP_CODE", "ADDRESS1", "ADDRESS2", "ADDRESS3", "LAST_UPDATE_DATE", "LAST_UPDATE_USER", ],
/** データ定義 **/
entries: [
{
//顧客コード
CUST_CODE: '${padZero(rownum, 4)}',
//顧客名
CUST_NAME: '${name.first()}',
//郵便番号
ZIP_CODE: '${postal.joiner("");}',
//住所1
ADDRESS1: '${address.prefecture()}',
//住所2
ADDRESS2: '${address.remain()}',
}.repeat(1000) //データ件数
]
};
functions
組み込み式の中で使える変数・関数の一覧です。
"${rownum}" //行番号
"${name.last()}" //姓
"${name.first()}" //名
"${name.last().kana()}" //セイ
"${name.first().kana()}" //メイ
"${age}" //年齢
"${email}" //Email
"${postal}" //郵便番号
"${postal.parent()}-${postal.branch()}" //郵便番号(上下個別指定)
"${address}" //住所
"${address.prefecture()}" //都道府県
"${address.detail()}" //以降の住所
"${address.other()}" //マンション名等
"${address.prefecture().kana()}" //都道府県カナ
"${birthday}" //誕生日
"${birthday.joiner('-')}" //誕生日(ハイフンつながり)
"${birthday.year}${birthday.month}${birthday.day}" //誕生日(年月日個別)
"${tel}" //電話番号
"${tel[0]}-${tel[1]}-${tel[2]}" //電話番号(ハイフンつながり)
"${toHiragana('カタカナへ')}" //カタカナへ変換
"${toHiragana('ひらがなへ')}" //ひらがなへ変換
"${toRomaji('ローマ字へ')}" //ローマ字へ変換
"${padZero(12, 5)}" //ゼロ埋め(左の例は'00012'となる)
"${randomInt(0, 100)}" //範囲内のランダムな整数