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

时间:2016-10-10 14:09:02

标签: javascript node.js protractor karma-jasmine angularjs-e2e

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

faker.system.directoryPath() + '/' + faker.system.filePath()

我在这两者中总是有未定义,因此它似乎存在但不会返回任何内容。

之前有没有人使用过这些方法之一?

在此先感谢,任何帮助都会非常感激。

再见

1 个答案:

答案 0 :(得分:2)

这些功能未实现 - 请查看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
相关问题