typescript-is
Advanced tools
Comparing version 0.16.0 to 0.16.1
@@ -170,2 +170,3 @@ /** | ||
public readonly reason: Reason; | ||
public readonly input: unknown; | ||
} | ||
@@ -172,0 +173,0 @@ |
23
index.js
@@ -11,8 +11,23 @@ let defaultGetErrorObject = undefined; | ||
function inputObjectAtPath(path, inputObject) { | ||
let subField = inputObject; | ||
for (const key of path.slice(1)) { | ||
subField = subField[ | ||
key.startsWith("[") ? parseInt(key.replace("[", "").replace("]", "")) : key | ||
]; | ||
} | ||
return subField; | ||
} | ||
function appendInputToErrorMessage(message, path, inputObject) { | ||
return message + ', found: ' + JSON.stringify(inputObjectAtPath(path, inputObject)); | ||
} | ||
class TypeGuardError extends Error { | ||
constructor(errorObject) { | ||
super(errorObject.message); | ||
constructor(errorObject, inputObject) { | ||
super(appendInputToErrorMessage(errorObject.message, errorObject.path, inputObject)); | ||
this.name = 'TypeGuardError'; | ||
this.path = errorObject.path; | ||
this.reason = errorObject.reason; | ||
this.input = inputObject | ||
} | ||
@@ -41,3 +56,3 @@ } | ||
if (errorObject !== null) { | ||
throw new errorConstructor(errorObject); | ||
throw new errorConstructor(errorObject, args[i]); | ||
} | ||
@@ -64,3 +79,3 @@ } | ||
} else { | ||
throw new TypeGuardError(errorObject); | ||
throw new TypeGuardError(errorObject, obj); | ||
} | ||
@@ -67,0 +82,0 @@ } |
@@ -44,3 +44,3 @@ "use strict"; | ||
function extractVariableName(node) { | ||
return node != null && ts.isIdentifier(node) ? node.escapedText.toString() : '$'; | ||
return node !== undefined && ts.isIdentifier(node) ? node.escapedText.toString() : '$'; | ||
} | ||
@@ -47,0 +47,0 @@ function transformNode(node, visitorContext) { |
{ | ||
"name": "typescript-is", | ||
"version": "0.16.0", | ||
"version": "0.16.1", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=6.14.4" |
Sorry, the diff of this file is not supported yet
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
221122
2706