UNPKG

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

252 lines 8.71 kB
"use strict"; /* tslint:disable:max-classes-per-file */ 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 }); exports.Field = exports.Fields = void 0; var faker_1 = require("@faker-js/faker"); /** * Field is the simples type of data of a model, it represent the type of data the model is ecpected to provide * @method generate This is used by a model to get the type of data the field is extected to provide */ var Field = /** @class */ (function () { function Field() { } return Field; }()); exports.Field = Field; var NameField = /** @class */ (function (_super) { __extends(NameField, _super); function NameField(_type) { if (_type === void 0) { _type = "FullName"; } var _this = _super.call(this) || this; _this._type = _type; return _this; } NameField.prototype.generate = function () { var name = faker_1.faker.name; if (this._type === "FirstName") return name.firstName(); if (this._type === "LastName") return name.lastName(); return name.fullName(); }; return NameField; }(Field)); var EmailField = /** @class */ (function (_super) { __extends(EmailField, _super); function EmailField(domain) { var _this = _super.call(this) || this; _this.domain = domain; return _this; } EmailField.prototype.generate = function () { return faker_1.faker.internet.email(); }; return EmailField; }(Field)); var TextField = /** @class */ (function (_super) { __extends(TextField, _super); function TextField(count) { if (count === void 0) { count = 50; } var _this = _super.call(this) || this; _this.count = 50; _this.count = count; return _this; } TextField.prototype.generate = function () { return faker_1.faker.random.words(this.count); }; return TextField; }(Field)); var PhoneNumberField = /** @class */ (function (_super) { __extends(PhoneNumberField, _super); function PhoneNumberField(format) { var _this = _super.call(this) || this; _this.format = format; return _this; } PhoneNumberField.prototype.generate = function () { if (this.format) return faker_1.faker.phone.number(this.format); return faker_1.faker.phone.number(); }; return PhoneNumberField; }(Field)); var AvatarField = /** @class */ (function (_super) { __extends(AvatarField, _super); function AvatarField() { return _super !== null && _super.apply(this, arguments) || this; } AvatarField.prototype.generate = function () { return faker_1.faker.image.avatar(); }; return AvatarField; }(Field)); var IDField = /** @class */ (function (_super) { __extends(IDField, _super); function IDField() { return _super !== null && _super.apply(this, arguments) || this; } IDField.prototype.generate = function () { return faker_1.faker.datatype.uuid(); }; return IDField; }(Field)); var GenderField = /** @class */ (function (_super) { __extends(GenderField, _super); function GenderField() { return _super !== null && _super.apply(this, arguments) || this; } GenderField.prototype.generate = function () { return faker_1.faker.name.gender(); }; return GenderField; }(Field)); var SexTypeField = /** @class */ (function (_super) { __extends(SexTypeField, _super); function SexTypeField() { return _super !== null && _super.apply(this, arguments) || this; } SexTypeField.prototype.generate = function () { return faker_1.faker.name.sexType(); }; return SexTypeField; }(Field)); var UsernameField = /** @class */ (function (_super) { __extends(UsernameField, _super); function UsernameField() { return _super !== null && _super.apply(this, arguments) || this; } UsernameField.prototype.generate = function () { return faker_1.faker.internet.userName(); }; return UsernameField; }(Field)); var ImageField = /** @class */ (function (_super) { __extends(ImageField, _super); function ImageField(height, width) { if (height === void 0) { height = 480; } if (width === void 0) { width = 640; } var _this = _super.call(this) || this; _this.width = width; _this.height = height; return _this; } ImageField.prototype.generate = function () { return faker_1.faker.image.image(); }; return ImageField; }(Field)); var CountryField = /** @class */ (function (_super) { __extends(CountryField, _super); function CountryField() { return _super !== null && _super.apply(this, arguments) || this; } CountryField.prototype.generate = function () { return faker_1.faker.address.country(); }; return CountryField; }(Field)); var CountryCodeField = /** @class */ (function (_super) { __extends(CountryCodeField, _super); function CountryCodeField() { return _super !== null && _super.apply(this, arguments) || this; } CountryCodeField.prototype.generate = function () { return faker_1.faker.address.countryCode(); }; return CountryCodeField; }(Field)); var StateField = /** @class */ (function (_super) { __extends(StateField, _super); function StateField() { return _super !== null && _super.apply(this, arguments) || this; } StateField.prototype.generate = function () { return faker_1.faker.address.state(); }; return StateField; }(Field)); var LocationField = /** @class */ (function (_super) { __extends(LocationField, _super); function LocationField() { return _super !== null && _super.apply(this, arguments) || this; } LocationField.prototype.generate = function () { return [faker_1.faker.address.latitude(), faker_1.faker.address.longitude()]; }; return LocationField; }(Field)); var FullAddressField = /** @class */ (function (_super) { __extends(FullAddressField, _super); function FullAddressField() { return _super !== null && _super.apply(this, arguments) || this; } FullAddressField.prototype.generate = function () { return faker_1.faker.address.streetAddress(); }; return FullAddressField; }(Field)); var NearByField = /** @class */ (function (_super) { __extends(NearByField, _super); function NearByField(location, distance) { if (distance === void 0) { distance = 5; } var _this = _super.call(this) || this; _this.location = location; _this.distance = distance; return _this; } NearByField.prototype.generate = function () { return faker_1.faker.address.nearbyGPSCoordinate(this.location, this.distance, true); }; return NearByField; }(Field)); var Fields = { NameField: NameField, EmailField: EmailField, PhoneNumberField: PhoneNumberField, TextField: TextField, IDField: IDField, GenderField: GenderField, SexTypeField: SexTypeField, AvatarField: AvatarField, UsernameField: UsernameField, ImageField: ImageField, CountryField: CountryField, CountryCodeField: CountryCodeField, StateField: StateField, LocationField: LocationField, FullAddressField: FullAddressField, NearByField: NearByField, Name: new NameField(), Email: new EmailField(), Avatar: new AvatarField(), Gender: new GenderField(), UserName: new UsernameField(), PhoneNumber: new PhoneNumberField(), Text: new TextField(), ID: new IDField(), SexType: new SexTypeField(), Image: new ImageField(), Country: new CountryField(), CountryCode: new CountryCodeField(), State: new StateField(), Location: new LocationField(), Address: new FullAddressField(), }; exports.Fields = Fields; //# sourceMappingURL=fields.js.map