UNPKG

909 BJavaScriptView Raw
1/*!
2 * A MongoDB inspired ES6 Map() query language. - Copyright (c) 2017 Louis T. (https://lou.ist/)
3 * Licensed under the MIT license https://raw.githubusercontent.com/LouisT/MapQL/master/LICENSE
4 */
5'use strict';
6let Helpers = require('../../Helpers');
7
8module.exports = {
9 '$pop': {
10 fn: function (key, val, entry) {
11 if (Helpers.is(entry.value, 'Object')) {
12 Helpers.dotNotation(key, entry.value, {
13 value: (current) => {
14 if (Array.isArray(current)) {
15 current[(val == -1 ? 'pop' : 'shift')]();
16 }
17 return (current !== Helpers._null ? current : []);
18 }
19 });
20 } else if (Helpers.is(entry.value, 'Array')) {
21 entry.value[(val == -1 ? 'pop' : 'shift')]();
22 }
23 }
24 }
25};