normalize-exception
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -10,3 +10,3 @@ import{setErrorProperty}from"./descriptors.js"; | ||
export const setStack=function(error){ | ||
const stack=[getStackHeader(error),...getStackTrace()].join("\n"); | ||
const stack=getStack(error.message,error.name); | ||
setErrorProperty(error,"stack",stack); | ||
@@ -18,52 +18,36 @@ }; | ||
const getStackHeader=function(error){ | ||
return`${error.name}: ${error.message}`; | ||
}; | ||
const getStackTrace=function(){ | ||
const{stack=""}=new Error(" "); | ||
const lines=stack===""?[]:stack.split("\n"); | ||
const index=findInternalIndex(lines); | ||
return lines.slice(index); | ||
const getStack=function(message="",name="Error"){ | ||
const StackError=getErrorType(name); | ||
const{stack}=new StackError(message); | ||
return stack===undefined||stack===""? | ||
`${name}: ${message}`: | ||
stack.split("\n").filter(isNotInternalLine).join("\n"); | ||
}; | ||
const getErrorType=function(name){ | ||
class StackError extends Error{} | ||
const descriptor={ | ||
value:name, | ||
enumerable:true, | ||
writable:true, | ||
configurable:true}; | ||
const findInternalIndex=function(lines){ | ||
const index=findLastIndex(lines,isInternalStackLine); | ||
Object.defineProperty(StackError,"name",descriptor); | ||
if(index===-1){ | ||
return 1; | ||
} | ||
return lines.length-1===index?index:index+1; | ||
Object.defineProperty(StackError.prototype,"name",descriptor); | ||
return StackError; | ||
}; | ||
const findLastIndex=function(array,condition){ | ||
for(let index=array.length-1;index>=0;index-=1){ | ||
if(condition(array[index])){ | ||
return index; | ||
} | ||
} | ||
return-1; | ||
const isNotInternalLine=function(line){ | ||
return!line.includes(INTERNAL_LINE); | ||
}; | ||
const isInternalStackLine=function(line){ | ||
return line.includes(NORMALIZE_ERROR_LINE); | ||
}; | ||
const NORMALIZE_ERROR_LINE="normalizeException"; | ||
const INTERNAL_LINE="normalize-exception"; | ||
//# sourceMappingURL=stack.js.map |
{ | ||
"name": "normalize-exception", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "exports": "./build/src/main.js", |
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
33825
407