hadron-type-checker
Advanced tools
Comparing version 0.9.1 to 0.10.0
@@ -16,2 +16,3 @@ 'use strict'; | ||
const Double = bson.Double; | ||
const Int32 = bson.Int32; | ||
@@ -94,3 +95,7 @@ /** | ||
function toLong(object) { | ||
function toInt32(object) { | ||
return new Int32(toNumber(object)); | ||
} | ||
function toInt64(object) { | ||
return Long.fromNumber(toNumber(object)); | ||
@@ -107,4 +112,4 @@ } | ||
const CASTERS = { | ||
'Int32': toNumber, | ||
'Int64': toLong, | ||
'Int32': toInt32, | ||
'Int64': toInt64, | ||
'Double': toDouble, | ||
@@ -216,19 +221,2 @@ 'Date': toDate, | ||
/** | ||
* Gets the BSON type for a JS number. | ||
* | ||
* @param {Number} number - The number. | ||
* | ||
* @returns {String} The BSON type. | ||
*/ | ||
function numberToBsonType(number) { | ||
var string = toString(number); | ||
if (INT32_CHECK.test(string)) { | ||
return 'Int32'; | ||
} else if (INT64_CHECK.test(string)) { | ||
return 'Int64'; | ||
} | ||
return 'Double'; | ||
} | ||
/** | ||
* Checks the types of objects and returns them as readable strings. | ||
@@ -263,5 +251,2 @@ */ | ||
type(object) { | ||
if (isNumber(object)) { | ||
return numberToBsonType(object); | ||
} | ||
if (isPlainObject(object)) { | ||
@@ -294,4 +279,5 @@ return OBJECT; | ||
return this._stringTypes(String(object)); | ||
} else if (has(object, BSON_TYPE) && object._bsontype === 'Long') { | ||
return this._stringTypes(String(object.toNumber())); | ||
} else if (has(object, BSON_TYPE) && this._isNumberType(object._bsontype)) { | ||
var rawValue = object._bsontype === 'Double' ? object.valueOf() : object.toNumber(); | ||
return this._stringTypes(String(rawValue)); | ||
} | ||
@@ -301,2 +287,6 @@ return [ this.type(object), 'String', 'Object', 'Array' ]; | ||
_isNumberType(bsontype) { | ||
return bsontype === 'Long' || bsontype === 'Int32' || bsontype === 'Double'; | ||
} | ||
_stringTypes(string) { | ||
@@ -303,0 +293,0 @@ var passing = find(STRING_TESTS, (test) => { |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/hadron-type-checker", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"repository": { | ||
@@ -27,3 +27,3 @@ "type": "git", | ||
"dependencies": { | ||
"bson": "^0.4.23", | ||
"bson": "^0.5.4", | ||
"lodash.find": "^4.4.0", | ||
@@ -30,0 +30,0 @@ "lodash.has": "^4.4.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18586
260
+ Addedbson@0.5.7(transitive)
- Removedbson@0.4.23(transitive)
Updatedbson@^0.5.4