jest-get-type
Advanced tools
Comparing version 24.0.0 to 24.2.0
@@ -0,1 +1,3 @@ | ||
'use strict'; | ||
/** | ||
@@ -6,10 +8,14 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
'use strict'; | ||
const PRIMITIVES = new Set([ | ||
'string', | ||
'number', | ||
'boolean', | ||
'null', | ||
'undefined', | ||
'symbol' | ||
]); // get the type of a value with handling the edge cases like `typeof []` | ||
// and `typeof null` | ||
// get the type of a value with handling the edge cases like `typeof []` | ||
// and `typeof null` | ||
const getType = value => { | ||
function getType(value) { | ||
if (value === undefined) { | ||
@@ -30,13 +36,15 @@ return 'undefined'; | ||
} else if (typeof value === 'object') { | ||
if (value.constructor === RegExp) { | ||
return 'regexp'; | ||
} else if (value.constructor === Map) { | ||
return 'map'; | ||
} else if (value.constructor === Set) { | ||
return 'set'; | ||
} else if (value.constructor === Date) { | ||
return 'date'; | ||
if (value != null) { | ||
if (value.constructor === RegExp) { | ||
return 'regexp'; | ||
} else if (value.constructor === Map) { | ||
return 'map'; | ||
} else if (value.constructor === Set) { | ||
return 'set'; | ||
} else if (value.constructor === Date) { | ||
return 'date'; | ||
} | ||
} | ||
return 'object'; // $FlowFixMe https://github.com/facebook/flow/issues/1015 | ||
return 'object'; | ||
} else if (typeof value === 'symbol') { | ||
@@ -47,4 +55,6 @@ return 'symbol'; | ||
throw new Error(`value of unknown type: ${value}`); | ||
}; | ||
} | ||
getType.isPrimitive = value => PRIMITIVES.has(getType(value)); | ||
module.exports = getType; |
{ | ||
"name": "jest-get-type", | ||
"description": "A utility function to get the type of a value", | ||
"version": "24.0.0", | ||
"version": "24.2.0", | ||
"repository": { | ||
@@ -15,3 +15,4 @@ "type": "git", | ||
"main": "build/index.js", | ||
"gitHead": "634e5a54f46b2a62d1dc81a170562e6f4e55ad60" | ||
"types": "build/index.d.ts", | ||
"gitHead": "d23f1ef18567763ab0133372e376ae5026a23d4b" | ||
} |
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
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
4015
6
70
1