deno.land / x / mongoose@6.7.5 / lib / helpers / update / updatedPathsByArrayFilter.js

updatedPathsByArrayFilter.js
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
const modifiedPaths = require('./modifiedPaths');
module.exports = function updatedPathsByArrayFilter(update) { if (update == null) { return {}; } const updatedPaths = modifiedPaths(update);
return Object.keys(updatedPaths).reduce((cur, path) => { const matches = path.match(/\$\[[^\]]+\]/g); if (matches == null) { return cur; } for (const match of matches) { const firstMatch = path.indexOf(match); if (firstMatch !== path.lastIndexOf(match)) { throw new Error(`Path '${path}' contains the same array filter multiple times`); } cur[match.substring(2, match.length - 1)] = path. substring(0, firstMatch - 1). replace(/\$\[[^\]]+\]/g, '0'); } return cur; }, {});};
mongoose

Version Info

Tagged at
a year ago