/
1Rrd0
/
Course
Обзор
Документация
Войти
/
1Rrd0
/
Course
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/mongoose/lib/helpers/projection/parseProjection.js
33 строки
686 B
dima
2
13 дек 2025, 10:58
13 дек 2025, 10:58
ce5a48e
Код
Авторство
О чём код?
'use strict'; /** * Convert a string or array into a projection object, retaining all * `-` and `+` paths. */ module.exports = function parseProjection(v, retainMinusPaths) { const type = typeof v; if (type === 'string') { v = v.split(/\s+/); } if (!Array.isArray(v) && Object.prototype.toString.call(v) !== '[object Arguments]') { return v; } const len = v.length; const ret = {}; for (let i = 0; i < len; ++i) { let field = v[i]; if (!field) { continue; } const include = '-' == field[0] ? 0 : 1; if (!retainMinusPaths && include === 0) { field = field.substring(1); } ret[field] = include; } return ret; };