faker-api
Version:
A fully customizible rest api faking package that allows you to mock , clone and fake Rest API with fake yet realistic data
60 lines • 2.41 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var _1 = require(".");
var __1 = require("../");
/**
* A Transformer that can generate a list of a given model or another transformer
*/
var ListTransformer = /** @class */ (function (_super) {
__extends(ListTransformer, _super);
/**
* The constructor of ListTransformer
* @param image The Model or transformer to apply the listTransformer
* @param count The number of `image` item to generate in the array
*/
function ListTransformer(model, count) {
if (count === void 0) { count = 10; }
var _this = _super.call(this) || this;
_this.model = model;
_this.count = count;
return _this;
}
/**
* Generates the data of the transform
* @param request - An Express Request object of the current request
* @param params - An Express response object for the current request
* @returns - Returns an array of the `image` with the length == the `count` property
*/
ListTransformer.prototype.transform = function (request, params) {
var copy = [];
if (this.model instanceof __1.AbstractModel) {
for (var index = 0; index < this.count; index++) {
copy.push(this.model.generate());
}
}
else {
for (var index = 0; index < this.count; index++) {
copy.push(this.model.transform(request, params));
}
}
return copy;
};
return ListTransformer;
}(_1.Transformer));
exports.default = ListTransformer;
//# sourceMappingURL=list-transformer.js.map
;