thoughts/node_modules/mongoose/lib/schema/operators/bitwise.js
node_modules/mongoose/lib/schema/operators/bitwise.jsRaw
1/*!
2 * Module requirements.
3 */
4
5var CastError = require('../../error/cast');
6
7/*!
8 * ignore
9 */
10
11function handleBitwiseOperator(val) {
12 var _this = this;
13 if (Array.isArray(val)) {
14 return val.map(function(v) {
15 return _castNumber(_this.path, v);
16 });
17 } else if (Buffer.isBuffer(val)) {
18 return val;
19 }
20 // Assume trying to cast to number
21 return _castNumber(_this.path, val);
22}
23
24/*!
25 * ignore
26 */
27
28function _castNumber(path, num) {
29 var v = Number(num);
30 if (isNaN(v)) {
31 throw new CastError('number', num, path);
32 }
33 return v;
34}
35
36module.exports = handleBitwiseOperator;