UNPKG

@websolute/faker.ts

Version:

Easy to Use, Powered by Decorators, Faker.js TypeScript Wrapper

42 lines 1.99 kB
"use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PrimitiveValueHandler = void 0; var primitive_handler_abstract_1 = require("./primitive-handler-abstract"); var array_value_handler_1 = require("./array-value-handler"); var PrimitiveValueHandler = /** @class */ (function (_super) { __extends(PrimitiveValueHandler, _super); function PrimitiveValueHandler(faker) { var _this = _super.call(this, faker) || this; _this.faker = faker; return _this; } PrimitiveValueHandler.prototype.shouldHandle = function (propertyDto) { return this.isPrimitive(propertyDto); }; PrimitiveValueHandler.prototype.produceValue = function (propertyDto) { var value = propertyDto.value; if (typeof value !== 'undefined') { if (array_value_handler_1.ArrayValueHandler.hasTypeKey(propertyDto)) { throw new Error('Type mismatch. Properties decorated with @Fixture({ type: ClassType }) must be typed as array (e.g. prop: string[])'); } return value; } return _super.prototype.generateRandomValueFromPrimitive.call(this, propertyDto.constructorName); }; return PrimitiveValueHandler; }(primitive_handler_abstract_1.PrimitiveHandlerAbstract)); exports.PrimitiveValueHandler = PrimitiveValueHandler; //# sourceMappingURL=primitive-value-handler.js.map