blob: df1e5d44b5ee7241a0e62728a042cd45e571fbba [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/* Built-in method references for those with the same name as other `lodash` methods. */
2var nativeMax = Math.max,
3 nativeMin = Math.min;
4
5/**
6 * Gets the view, applying any `transforms` to the `start` and `end` positions.
7 *
8 * @private
9 * @param {number} start The start of the view.
10 * @param {number} end The end of the view.
11 * @param {Array} transforms The transformations to apply to the view.
12 * @returns {Object} Returns an object containing the `start` and `end`
13 * positions of the view.
14 */
15function getView(start, end, transforms) {
16 var index = -1,
17 length = transforms.length;
18
19 while (++index < length) {
20 var data = transforms[index],
21 size = data.size;
22
23 switch (data.type) {
24 case 'drop': start += size; break;
25 case 'dropRight': end -= size; break;
26 case 'take': end = nativeMin(end, start + size); break;
27 case 'takeRight': start = nativeMax(start, end - size); break;
28 }
29 }
30 return { 'start': start, 'end': end };
31}
32
33module.exports = getView;