UNPKG

ioredis-mock

Version:

This library emulates ioredis by performing all operations in-memory.

23 lines (21 loc) 517 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.slice = slice; function normalizeIndex(index, array) { if (index < 0) { return -index > array.length ? -1 : array.length + index; } return index; } function slice(arr, s, e) { var start = normalizeIndex(s, arr); var end = normalizeIndex(e, arr); if (end === -1) { return []; } else if (end - start < 0) { return Array.from(arr).reverse().slice(start, end + 1); } return arr.slice(start, end + 1); }