hadron-type-checker
Advanced tools
Comparing version 4.0.4 to 5.0.0
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
module.exports = require('./lib/type-checker'); | ||
module.exports = require('./src/type-checker'); |
@@ -7,3 +7,3 @@ { | ||
"homepage": "https://github.com/mongodb-js/hadron-type-checker", | ||
"version": "4.0.4", | ||
"version": "5.0.0", | ||
"repository": { | ||
@@ -19,37 +19,15 @@ "type": "git", | ||
"ci": "npm test", | ||
"fmt": "mongodb-js-fmt ./*.js ./test/*.js", | ||
"test": "mocha --recursive", | ||
"check": "mongodb-js-precommit", | ||
"prepublish": "babel ./src --out-dir ./lib", | ||
"pretest": "babel ./src --out-dir ./lib" | ||
"test": "mocha", | ||
"check": "mongodb-js-precommit" | ||
}, | ||
"precommit": [ | ||
"check" | ||
], | ||
"dependencies": { | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-react": "^6.5.0", | ||
"babel-register": "^6.5.2", | ||
"bson": "^1.0.1", | ||
"lodash.has": "^4.4.0", | ||
"lodash.includes": "^4.3.0", | ||
"lodash.isarray": "^4.0.0", | ||
"lodash.isinteger": "^4.0.4", | ||
"lodash.isnumber": "^3.0.3", | ||
"lodash.isplainobject": "^4.0.4", | ||
"lodash.isstring": "^4.0.1", | ||
"lodash.keys": "^4.2.0", | ||
"lodash.tonumber": "^4.0.2", | ||
"lodash.tostring": "^4.1.3", | ||
"lodash.without": "^4.4.0" | ||
"bson": "^4.0.3", | ||
"lodash": "^4.17.15" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.9.0", | ||
"chai": "^3.4.1", | ||
"eslint-config-mongodb-js": "^2.2.0", | ||
"mocha": "^3.1.2", | ||
"mongodb-js-fmt": "^0.0.3", | ||
"mongodb-js-precommit": "^0.2.9", | ||
"pre-commit": "^1.1.2" | ||
"chai": "^4.2.0", | ||
"eslint-config-mongodb-js": "^5.0.3", | ||
"mocha": "^7.0.1", | ||
"mongodb-js-precommit": "^2.1.0" | ||
} | ||
} |
@@ -1,26 +0,29 @@ | ||
'use strict'; | ||
const { | ||
isPlainObject, | ||
isArray, | ||
isString, | ||
isNumber, | ||
hasIn, | ||
keys, | ||
without, | ||
toNumber, | ||
toString, | ||
includes, | ||
} = require('lodash'); | ||
const isPlainObject = require('lodash.isplainobject'); | ||
const isArray = require('lodash.isarray'); | ||
const isString = require('lodash.isstring'); | ||
const isNumber = require('lodash.isnumber'); | ||
const has = require('lodash.has'); | ||
const keys = require('lodash.keys'); | ||
const without = require('lodash.without'); | ||
const toNumber = require('lodash.tonumber'); | ||
const toString = require('lodash.tostring'); | ||
const includes = require('lodash.includes'); | ||
const bson = require('bson'); | ||
const MinKey = bson.MinKey; | ||
const MaxKey = bson.MaxKey; | ||
const Long = bson.Long; | ||
const Double = bson.Double; | ||
const Int32 = bson.Int32; | ||
const Decimal128 = bson.Decimal128; | ||
const Binary = bson.Binary; | ||
const BSONRegExp = bson.BSONRegExp; | ||
const Code = bson.Code; | ||
const Symbol = bson.Symbol; | ||
const Timestamp = bson.Timestamp; | ||
const { | ||
ObjectId, | ||
MinKey, | ||
MaxKey, | ||
Long, | ||
Double, | ||
Int32, | ||
Decimal128, | ||
Binary, | ||
BSONRegExp, | ||
Code, | ||
BSONSymbol, | ||
Timestamp, | ||
BSONMap | ||
} = require('bson'); | ||
/** | ||
@@ -72,3 +75,3 @@ * The object string. | ||
*/ | ||
const BSON_INT32_MAX = 0x7FFFFFFF; | ||
const BSON_INT32_MAX = 0x7fffffff; | ||
@@ -81,3 +84,3 @@ /** | ||
const BSON_INT64_MAX = Math.pow(2, 63) - 1; | ||
const BSON_INT64_MIN = -(BSON_INT64_MAX); | ||
const BSON_INT64_MIN = -BSON_INT64_MAX; | ||
@@ -92,8 +95,3 @@ /** | ||
*/ | ||
const NUMBER_TYPES = [ | ||
'Long', | ||
'Int32', | ||
'Double', | ||
'Decimal128' | ||
]; | ||
const NUMBER_TYPES = ['Long', 'Int32', 'Double', 'Decimal128']; | ||
@@ -149,3 +147,3 @@ const toDate = (object) => { | ||
} | ||
return [ object ]; | ||
return [object]; | ||
}; | ||
@@ -190,6 +188,6 @@ | ||
*/ | ||
if (has(object, BSON_TYPE) && includes(NUMBER_TYPES, object._bsontype)) { | ||
if (hasIn(object, BSON_TYPE) && includes(NUMBER_TYPES, object._bsontype)) { | ||
object = object._bsontype === LONG ? object.toNumber() : object.valueOf(); | ||
} | ||
return Decimal128.fromString(String(object)); | ||
return Decimal128.fromString('' + object); | ||
}; | ||
@@ -199,21 +197,21 @@ | ||
if (!isString(object) || object === '') { | ||
return new bson.ObjectID(); | ||
return new ObjectId(); | ||
} | ||
return bson.ObjectID.createFromHexString(object); | ||
return ObjectId.createFromHexString(object); | ||
}; | ||
const toBinary = (object) => { | ||
return new Binary(String(object), Binary.SUBTYPE_DEFAULT); | ||
return new Binary('' + object, Binary.SUBTYPE_DEFAULT); | ||
}; | ||
const toRegex = (object) => { | ||
return new BSONRegExp(String(object)); | ||
return new BSONRegExp('' + object); | ||
}; | ||
const toCode = (object) => { | ||
return new Code(String(object), {}); | ||
return new Code('' + object, {}); | ||
}; | ||
const toSymbol = (object) => { | ||
return new Symbol(String(object)); | ||
return new BSONSymbol('' + object); | ||
}; | ||
@@ -226,2 +224,6 @@ | ||
const toMap = (object) => { | ||
return new BSONMap(object); | ||
}; | ||
/** | ||
@@ -231,21 +233,22 @@ * The functions to cast to a type. | ||
const CASTERS = { | ||
'Array': toArray, | ||
'Binary': toBinary, | ||
'Boolean': toBoolean, | ||
'Code': toCode, | ||
'Date': toDate, | ||
'Decimal128': toDecimal128, | ||
'Double': toDouble, | ||
'Int32': toInt32, | ||
'Int64': toInt64, | ||
'MaxKey': toMaxKey, | ||
'MinKey': toMinKey, | ||
'Null': toNull, | ||
'Object': toObject, | ||
'ObjectId': toObjectID, | ||
'BSONRegexp': toRegex, | ||
'String': toString, | ||
'Symbol': toSymbol, | ||
'Timestamp': toTimestamp, | ||
'Undefined': toUndefined | ||
Array: toArray, | ||
Binary: toBinary, | ||
Boolean: toBoolean, | ||
Code: toCode, | ||
Date: toDate, | ||
Decimal128: toDecimal128, | ||
Double: toDouble, | ||
Int32: toInt32, | ||
Int64: toInt64, | ||
MaxKey: toMaxKey, | ||
MinKey: toMinKey, | ||
Null: toNull, | ||
Object: toObject, | ||
ObjectId: toObjectID, | ||
BSONRegexp: toRegex, | ||
String: toString, | ||
BSONSymbol: toSymbol, | ||
BSONMap: toMap, | ||
Timestamp: toTimestamp, | ||
Undefined: toUndefined | ||
}; | ||
@@ -307,3 +310,2 @@ | ||
class TypeChecker { | ||
/** | ||
@@ -334,2 +336,11 @@ * Cast the provided object to the desired type. | ||
type(object) { | ||
if (hasIn(object, BSON_TYPE)) { | ||
if (object._bsontype === LONG) { | ||
return INT_64; | ||
} | ||
if (object._bsontype === OBJECT_ID) { | ||
return 'ObjectId'; | ||
} | ||
return object._bsontype; | ||
} | ||
if (isNumber(object)) { | ||
@@ -344,11 +355,2 @@ return numberToBsonType(object); | ||
} | ||
if (has(object, BSON_TYPE)) { | ||
if (object._bsontype === LONG) { | ||
return INT_64; | ||
} | ||
if (object._bsontype === OBJECT_ID) { | ||
return 'ObjectId'; | ||
} | ||
return object._bsontype; | ||
} | ||
return Object.prototype.toString.call(object).replace(MATCH, '$1'); | ||
@@ -355,0 +357,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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
4
22006
9
322
2
+ Addedlodash@^4.17.15
+ Addedbase64-js@1.5.1(transitive)
+ Addedbson@4.7.2(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedieee754@1.2.1(transitive)
- Removedbabel-preset-es2015@^6.24.1
- Removedbabel-preset-react@^6.5.0
- Removedbabel-register@^6.5.2
- Removedlodash.has@^4.4.0
- Removedlodash.includes@^4.3.0
- Removedlodash.isarray@^4.0.0
- Removedlodash.isinteger@^4.0.4
- Removedlodash.isnumber@^3.0.3
- Removedlodash.isplainobject@^4.0.4
- Removedlodash.isstring@^4.0.1
- Removedlodash.keys@^4.2.0
- Removedlodash.tonumber@^4.0.2
- Removedlodash.tostring@^4.1.3
- Removedlodash.without@^4.4.0
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedbabel-code-frame@6.26.0(transitive)
- Removedbabel-core@6.26.3(transitive)
- Removedbabel-generator@6.26.1(transitive)
- Removedbabel-helper-builder-react-jsx@6.26.0(transitive)
- Removedbabel-helper-call-delegate@6.24.1(transitive)
- Removedbabel-helper-define-map@6.26.0(transitive)
- Removedbabel-helper-function-name@6.24.1(transitive)
- Removedbabel-helper-get-function-arity@6.24.1(transitive)
- Removedbabel-helper-hoist-variables@6.24.1(transitive)
- Removedbabel-helper-optimise-call-expression@6.24.1(transitive)
- Removedbabel-helper-regex@6.26.0(transitive)
- Removedbabel-helper-replace-supers@6.24.1(transitive)
- Removedbabel-helpers@6.24.1(transitive)
- Removedbabel-messages@6.23.0(transitive)
- Removedbabel-plugin-check-es2015-constants@6.22.0(transitive)
- Removedbabel-plugin-syntax-flow@6.18.0(transitive)
- Removedbabel-plugin-syntax-jsx@6.18.0(transitive)
- Removedbabel-plugin-transform-es2015-arrow-functions@6.22.0(transitive)
- Removedbabel-plugin-transform-es2015-block-scoped-functions@6.22.0(transitive)
- Removedbabel-plugin-transform-es2015-block-scoping@6.26.0(transitive)
- Removedbabel-plugin-transform-es2015-classes@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-computed-properties@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-destructuring@6.23.0(transitive)
- Removedbabel-plugin-transform-es2015-duplicate-keys@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-for-of@6.23.0(transitive)
- Removedbabel-plugin-transform-es2015-function-name@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-literals@6.22.0(transitive)
- Removedbabel-plugin-transform-es2015-modules-amd@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-modules-commonjs@6.26.2(transitive)
- Removedbabel-plugin-transform-es2015-modules-systemjs@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-modules-umd@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-object-super@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-parameters@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-shorthand-properties@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-spread@6.22.0(transitive)
- Removedbabel-plugin-transform-es2015-sticky-regex@6.24.1(transitive)
- Removedbabel-plugin-transform-es2015-template-literals@6.22.0(transitive)
- Removedbabel-plugin-transform-es2015-typeof-symbol@6.23.0(transitive)
- Removedbabel-plugin-transform-es2015-unicode-regex@6.24.1(transitive)
- Removedbabel-plugin-transform-flow-strip-types@6.22.0(transitive)
- Removedbabel-plugin-transform-react-display-name@6.25.0(transitive)
- Removedbabel-plugin-transform-react-jsx@6.24.1(transitive)
- Removedbabel-plugin-transform-react-jsx-self@6.22.0(transitive)
- Removedbabel-plugin-transform-react-jsx-source@6.22.0(transitive)
- Removedbabel-plugin-transform-regenerator@6.26.0(transitive)
- Removedbabel-plugin-transform-strict-mode@6.24.1(transitive)
- Removedbabel-preset-es2015@6.24.1(transitive)
- Removedbabel-preset-flow@6.23.0(transitive)
- Removedbabel-preset-react@6.24.1(transitive)
- Removedbabel-register@6.26.0(transitive)
- Removedbabel-runtime@6.26.0(transitive)
- Removedbabel-template@6.26.0(transitive)
- Removedbabel-traverse@6.26.0(transitive)
- Removedbabel-types@6.26.0(transitive)
- Removedbabylon@6.18.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedbson@1.1.6(transitive)
- Removedchalk@1.1.3(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedconvert-source-map@1.9.0(transitive)
- Removedcore-js@2.6.12(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddetect-indent@4.0.0(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedesutils@2.0.3(transitive)
- Removedglobals@9.18.0(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhome-or-tmp@2.0.0(transitive)
- Removedinvariant@2.2.4(transitive)
- Removedis-finite@1.1.0(transitive)
- Removedjs-tokens@3.0.2(transitive)
- Removedjsesc@0.5.01.3.0(transitive)
- Removedjson5@0.5.1(transitive)
- Removedlodash.has@4.5.2(transitive)
- Removedlodash.includes@4.3.0(transitive)
- Removedlodash.isarray@4.0.0(transitive)
- Removedlodash.isinteger@4.0.4(transitive)
- Removedlodash.isnumber@3.0.3(transitive)
- Removedlodash.isplainobject@4.0.6(transitive)
- Removedlodash.isstring@4.0.1(transitive)
- Removedlodash.keys@4.2.0(transitive)
- Removedlodash.tonumber@4.0.3(transitive)
- Removedlodash.tostring@4.1.4(transitive)
- Removedlodash.without@4.4.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedminimist@1.2.8(transitive)
- Removedmkdirp@0.5.6(transitive)
- Removedms@2.0.0(transitive)
- Removedos-homedir@1.0.2(transitive)
- Removedos-tmpdir@1.0.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedprivate@0.1.8(transitive)
- Removedregenerate@1.4.2(transitive)
- Removedregenerator-runtime@0.11.1(transitive)
- Removedregenerator-transform@0.10.1(transitive)
- Removedregexpu-core@2.0.0(transitive)
- Removedregjsgen@0.2.0(transitive)
- Removedregjsparser@0.1.5(transitive)
- Removedrepeating@2.0.1(transitive)
- Removedslash@1.0.0(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-support@0.4.18(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
- Removedto-fast-properties@1.0.3(transitive)
- Removedtrim-right@1.0.1(transitive)
Updatedbson@^4.0.3