gpt4 book ai didi

javascript - Faker.js 生成随机路径不起作用

转载 作者:行者123 更新时间:2023-11-30 15:46:38 35 4
gpt4 key购买 nike

我正在使用 faker.js https://www.npmjs.com/package/faker生成随机数据。虽然当我尝试像这样创建一个路径

时它工作正常
faker.system.directoryPath() + '/' + faker.system.filePath()

我总是在两者中得到 undefined,所以它似乎存在但不返回任何东西。

以前有人用过这些方法吗?

在此先致谢,我们将不胜感激。

再见

最佳答案

这些功能未实现 - 查看 https://github.com/Marak/faker.js/blob/master/lib/system.js#L132https://github.com/Marak/faker.js/blob/master/lib/system.js#L141

  /**
* not yet implemented
*
* @method faker.system.filePath
*/
this.filePath = function () {
// TODO
};

关于如何实现的一些概念证明:

var faker = require('faker');
var path = require('path');

faker.directoryPath = function() {
return path.format({base: faker.fake("{{random.words}}").replace(/ /g, path.sep).toLowerCase()})
}

console.log(faker.directoryPath() + path.sep + faker.system.fileName()) // e.g. avon\re-engineered\strategist_gorgeous_wooden_fish_cambridgeshire.sm

关于javascript - Faker.js 生成随机路径不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960242/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com