UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

20 lines (18 loc) 799 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const errors = require("./../errors"); /** * Verifies to see if an index or negative index exists within a specified length. * @param index - Index. * @param length - Length index could be in. */ function verifyAndGetIndex(index, length) { const newIndex = index < 0 ? length + index : index; if (newIndex < 0) throw new errors.InvalidOperationError(`Invalid index: The max negative index is ${length * -1}, but ${index} was specified.`); if (index > length) throw new errors.InvalidOperationError(`Invalid index: The max index is ${length}, but ${index} was specified.`); return newIndex; } exports.verifyAndGetIndex = verifyAndGetIndex; //# sourceMappingURL=verifyAndGetIndex.js.map