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

normalize-exception

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-exception - npm Package Compare versions

Comparing version 1.1.5 to 1.2.0

build/src/create/copy.js

18

build/src/create/main.js
import isPlainObj from"is-plain-obj";
import{isNonModifiableError}from"../descriptors.js";
import{isNonModifiableError}from"./modifiable.js";
import{objectifyError}from"./object.js";
import{stringifyError}from"./string.js";
const{toString:objectToString}=Object.prototype;
export const createError=function(value){

@@ -15,3 +16,3 @@ if(isPlainObj(value)){

if(!isError(value)){
return stringifyError(value);
return handleNonError(value);
}

@@ -35,4 +36,13 @@

const{toString:objectToString}=Object.prototype;
const handleNonError=function(value){
return isProxy(value)?objectifyError(value):stringifyError(value);
};
const isProxy=function(value){
return value instanceof Error;
};
const isInvalidError=function(value){

@@ -39,0 +49,0 @@ return isNonModifiableError(value)||hasInvalidConstructor(value);

import{setErrorProperty}from"../descriptors.js";
import{setFullStack}from"../stack.js";
import{copyObject}from"./copy.js";
export const objectifyError=function({
name,
message,
stack,
cause,
errors,
...object})
{
const messageA=getMessage(message,object);
export const objectifyError=function(object){
const{name,message,stack,cause,errors,...objectA}=copyObject(object);
const messageA=getMessage(message,objectA);
const error=newError(name,messageA);
if(message===messageA){
assignObjectProps(error,object);
assignObjectProps(error,objectA);
}

@@ -19,0 +15,0 @@

export const isNonModifiableError=function(error){
return(
!Object.isExtensible(error)||
CORE_ERROR_PROPS.some((propName)=>isNonConfigurableProp(error,propName)));
};
const isNonConfigurableProp=function(error,propName){
const descriptor=Object.getOwnPropertyDescriptor(error,propName);
return descriptor!==undefined&&!descriptor.configurable;
};
export const normalizeDescriptors=function(error){

@@ -23,3 +8,3 @@ CORE_ERROR_PROPS.forEach((propName)=>{

const CORE_ERROR_PROPS=["name","message","stack","cause","errors"];
export const CORE_ERROR_PROPS=["name","message","stack","cause","errors"];

@@ -44,3 +29,3 @@ const normalizeDescriptor=function(error,propName){

const getDescriptor=function(value,propName){
export const getDescriptor=function(value,propName){
const descriptor=Object.getOwnPropertyDescriptor(value,propName);

@@ -47,0 +32,0 @@

{
"name": "normalize-exception",
"version": "1.1.5",
"version": "1.2.0",
"type": "module",

@@ -49,5 +49,5 @@ "exports": "./build/src/main.js",

"devDependencies": {
"@ehmicky/dev-tasks": "^1.0.77",
"@ehmicky/dev-tasks": "^1.0.78",
"test-each": "^5.0.0",
"tsd": "^0.20.0"
"tsd": "^0.21.0"
},

@@ -54,0 +54,0 @@ "engines": {

[![Codecov](https://img.shields.io/codecov/c/github/ehmicky/normalize-exception.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/normalize-exception)
[![Build](https://github.com/ehmicky/normalize-exception/workflows/Build/badge.svg)](https://github.com/ehmicky/normalize-exception/actions)
[![Node](https://img.shields.io/node/v/normalize-exception.svg?logo=node.js)](https://www.npmjs.com/package/normalize-exception)
[![Twitter](https://img.shields.io/badge/%E2%80%8B-twitter-4cc61e.svg?logo=twitter)](https://twitter.com/intent/follow?screen_name=ehmicky)
[![Medium](https://img.shields.io/badge/%E2%80%8B-medium-4cc61e.svg?logo=medium)](https://medium.com/@ehmicky)
[![TypeScript](https://img.shields.io/badge/-typed-brightgreen?logo=typescript&colorA=gray)](/src/main.d.ts)
[![Twitter](https://img.shields.io/badge/%E2%80%8B-twitter-brightgreen.svg?logo=twitter)](https://twitter.com/intent/follow?screen_name=ehmicky)
[![Medium](https://img.shields.io/badge/%E2%80%8B-medium-brightgreen.svg?logo=medium)](https://medium.com/@ehmicky)

@@ -92,2 +92,13 @@ Normalize exceptions/errors.

# Related projects
- [`modern-errors`](https://github.com/ehmicky/modern-errors): Handle errors
like it's 2022 🔮
- [`error-type`](https://github.com/ehmicky/error-type): Create custom error
types
- [`merge-error-cause`](https://github.com/ehmicky/merge-error-cause): Merge an
error with its `cause`
- [`error-cause-polyfill`](https://github.com/ehmicky/error-cause-polyfill):
Polyfill `error.cause`
# Support

@@ -94,0 +105,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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