UNPKG

942 BJavaScriptView Raw
1var strict = require('./modes/strict');
2
3var OBJECT_REGEX = /\[object (\w+)\]/;
4/**
5 * Gets the BSON or JS type of a value.
6 *
7 * @param {Any} value - Value to check.
8 * @return {String}
9 * @api private
10 */
11module.exports.type = function type(value) {
12 if (value && value._bsontype) {
13 return value._bsontype;
14 }
15 return OBJECT_REGEX.exec(Object.prototype.toString.call(value))[1];
16};
17
18/**
19 * @api private
20 */
21module.exports.special = {
22 types: Object.keys(strict.serialize),
23 keys: Object.keys(strict.deserialize)
24};
25
26/**
27 * @param {Any} value - Value to check.
28 * @return {Boolean}
29 * @api private
30 */
31module.exports.isSpecial = function isSpecial(value) {
32 return module.exports.special.types.indexOf(module.exports.type(value)) > -1;
33};
34
35/**
36 * @param {Any} value - Value to check.
37 * @return {Boolean}
38 * @api private
39 */
40module.exports.isObject = function isObject(value) {
41 return module.exports.type(value) === 'Object';
42};