@websolute/faker.ts
Version:
Easy to Use, Powered by Decorators, Faker.js TypeScript Wrapper
35 lines • 1.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixtureFactory = void 0;
var faker_1 = __importDefault(require("faker"));
var class_processor_1 = require("../class-processor");
var class_reflector_1 = require("../class-reflector");
var FixtureFactory = /** @class */ (function () {
function FixtureFactory() {
}
/**
* Return one or many objects (array) with all the properties decorated
* by the Fixture decorator
*
* @param target
* @param options
*/
FixtureFactory.create = function (target, options) {
var _a = options || {}, _b = _a.count, count = _b === void 0 ? 1 : _b, _c = _a.locale, locale = _c === void 0 ? class_processor_1.ClassProcessor.DEFAULT_LOCALE : _c;
var factory = new class_processor_1.ClassProcessor(faker_1.default, new class_reflector_1.ClassReflector(), locale);
if (!count || count === 1) {
return factory.process(target);
}
var objects = [];
for (var i = 1; i <= count; i++) {
objects.push(factory.process(target));
}
return objects;
};
return FixtureFactory;
}());
exports.FixtureFactory = FixtureFactory;
//# sourceMappingURL=fixture-factory.js.map