UNPKG

vike

Version:

The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.

36 lines (35 loc) 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.slice = slice; const assert_js_1 = require("./assert.js"); function slice(thing, from, to) { if (typeof thing === 'string') { return sliceArray(thing.split(''), from, to).join(''); } else { return sliceArray(thing, from, to); } } function sliceArray(list, from, to) { const listSlice = []; let start = from >= 0 ? from : list.length + from; (0, assert_js_1.assert)(start >= 0 && start <= list.length); let end = to >= 0 ? to : list.length + to; (0, assert_js_1.assert)(end >= 0 && end <= list.length); while (true) { if (start === end) { break; } if (start === list.length) { start = 0; } if (start === end) { break; } const el = list[start]; (0, assert_js_1.assert)(el !== undefined); listSlice.push(el); start++; } return listSlice; }