ackuser
ackuser

Reputation: 5889

Faker.js Generating random paths doesn't work

I am using faker.js https://www.npmjs.com/package/faker to generate random data. It works fine although when I try to create a path like this

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

I have always got undefined in both, so it seems that it exists but doesn't return anything.

Did anyone use one of these methods before?

Thanks in advance, any help would be really appreciated.

Bye

Upvotes: 1

Views: 2678

Answers (1)

Krzysztof Safjanowski
Krzysztof Safjanowski

Reputation: 7438

Those functionalities are not implemented - take a look into https://github.com/Marak/faker.js/blob/master/lib/system.js#L132 and https://github.com/Marak/faker.js/blob/master/lib/system.js#L141

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

Some proof of concept how it can be implemented:

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

Upvotes: 2

Related Questions