UNPKG

unmock-core

Version:

[![npm](https://img.shields.io/npm/v/unmock-core.svg)][npmjs] [![CircleCI](https://circleci.com/gh/unmock/unmock-js.svg?style=svg)](https://circleci.com/gh/unmock/unmock-js) [![codecov](https://codecov.io/gh/unmock/unmock-js/branch/dev/graph/badge.svg)](h

34 lines 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const debug_1 = __importDefault(require("debug")); const constants_1 = require("./constants"); const utils_1 = require("./utils"); const debugLog = debug_1.default("unmock:dsl:translators"); exports.translate$times = (times) => { if (typeof times !== "number") { throw new Error("Can't set response $times with non-numeric value!"); } const roundTimes = Math.round(times); if (roundTimes < 1) { throw new Error(`Can't set response $times to ${times}!`); } debugLog(`Rounded response $times to ${times}`); return utils_1.buildUnmockPropety(constants_1.SCHEMA_TIMES, times); }; exports.translate$size = (state, schema) => { if (schema.type === undefined || schema.type !== "array") { throw new Error("Can't set '$size' for non-array elements!"); } if (typeof state.$size !== "number") { throw new Error("Can't request a non-numeric size of array!"); } const nElements = Math.round(state.$size); if (nElements < 1) { throw new Error("Can't request a non-positive size of array!"); } return { minItems: nElements, maxItems: nElements }; }; //# sourceMappingURL=translators.js.map