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

39 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const debug_1 = require("debug"); const constants_1 = require("./constants"); const utils_1 = require("./utils"); const debugLog = debug_1.default("unmock:dsl:translators"); const 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); }; const translate$size = (state, schema) => { if (schema.type === undefined || schema.type !== "array" || schema.items === undefined) { 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 }; }; exports.translators = { $size: (st, sc) => utils_1.throwOnErrorIfStrict(() => translate$size(st, sc)), }; exports.topTranslators = { $times: val => utils_1.throwOnErrorIfStrict(() => translate$times(val)), }; //# sourceMappingURL=translators.js.map