mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-24 01:29:19 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
39
node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js
generated
vendored
Normal file
39
node_modules/mongoose/lib/helpers/path/flattenObjectWithDottedPaths.js
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
'use strict';
|
||||
|
||||
const MongooseError = require('../../error/mongooseError');
|
||||
const isMongooseObject = require('../isMongooseObject');
|
||||
const setDottedPath = require('../path/setDottedPath');
|
||||
const util = require('util');
|
||||
|
||||
/**
|
||||
* Given an object that may contain dotted paths, flatten the paths out.
|
||||
* For example: `flattenObjectWithDottedPaths({ a: { 'b.c': 42 } })` => `{ a: { b: { c: 42 } } }`
|
||||
*/
|
||||
|
||||
module.exports = function flattenObjectWithDottedPaths(obj) {
|
||||
if (obj == null || typeof obj !== 'object' || Array.isArray(obj)) {
|
||||
return;
|
||||
}
|
||||
// Avoid Mongoose docs, like docs and maps, because these may cause infinite recursion
|
||||
if (isMongooseObject(obj)) {
|
||||
return;
|
||||
}
|
||||
const keys = Object.keys(obj);
|
||||
for (const key of keys) {
|
||||
const val = obj[key];
|
||||
if (key.indexOf('.') !== -1) {
|
||||
try {
|
||||
delete obj[key];
|
||||
setDottedPath(obj, key, val);
|
||||
} catch (err) {
|
||||
if (!(err instanceof TypeError)) {
|
||||
throw err;
|
||||
}
|
||||
throw new MongooseError(`Conflicting dotted paths when setting document path, key: "${key}", value: ${util.inspect(val)}`);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
flattenObjectWithDottedPaths(obj[key]);
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue