Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hadron-type-checker

Package Overview
Dependencies
Maintainers
1
Versions
497
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hadron-type-checker - npm Package Compare versions

Comparing version 0.9.1 to 0.10.0

40

lib/type-checker.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc