1 个不稳定版本
0.1.0 | 2022年4月12日 |
---|
#21 in #fake-data
155KB
255 代码行数(不含注释)
faker-cli
通过命令行生成假数据。
faker-cli 0.1.0
Ahmad Rosid <[email protected]>
Generate fake data.
USAGE:
faker-cli [OPTION] [QUERY]
OPTION:
-l --len Total length
QUERY:
Example: "{ username, email }"
Output: { "username": "jhondoe", "email": "[email protected]" }
Supported data.
- username
- email
- password
- full_name
- first_name
- last_name
- zip_code
- phone_number
- text
示例
faker-cli -l 3 "{ username, email, password }"
结果
{"username": "mossie_et","email": "[email protected]","password": "eVJalW9no4O"}
{"username": "clotilde_qui","email": "[email protected]","password": "DxOhky"}
{"username": "nella_maiores","email": "[email protected]","password": "RY4L5Ck"}
自定义属性名称。
faker-cli -l 3 "{ my_email(email), nickname(username), kode_pos(zip_code), rahasia(password), what_ever(1) }"
结果
{"my_email": "[email protected]","nickname": "blaze_autem","kode_pos": "134","rahasia": "Jr9TvZHQ4","what_ever": "1"}
{"my_email": "[email protected]","nickname": "tyler_ad","kode_pos": "4718","rahasia": "xCKsOVqYp","what_ever": "1"}
{"my_email": "[email protected]","nickname": "oswald_vel","kode_pos": "3206","rahasia": "BjM8uNGFS5","what_ever": "1"}
示例
您可以使用它与 nodejs 为数据库生成种子。
const child = require('child_process');
...
const cmd = `faker-cli -l 100 "{ username, email }"`;
child.exec(`${cmd}`, (err, stdout, stderr) => {
if (stdout.length > 0) {
stdout.split("\n").forEach(item => storeData(item))
}
});
function storeData(data) {
db.user.create({
data: JSON.parse(data)
}).then(res => console.log(res))
.catch(err => {})
}
或者您也可以用它来自动化 curl。
faker-cli -l 100 "{ username, email, password }" | xargs -I % sh -c 'curl -X POST https://127.0.0.1:8080/register -d "%s"'
依赖项
~1MB
~13K SLoC