New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@darkwolf/code-error

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@darkwolf/code-error - npm Package Compare versions

Comparing version 2.0.6 to 2.0.7

168

index.js

@@ -1,2 +0,3 @@

const validator = require('./utils/validator')
const validator = require('@darkwolf/validator')
const { Validator } = validator

@@ -7,38 +8,94 @@ class CodeError extends Error {

if (args.length <= 1) {
const [options] = args
switch (args.length) {
case 1: {
const [options] = args
validator.isValidOptions(options)
new Validator(options)
.isExists()
.throw(new Error('"options" argument is required'))
.isObject()
.throw(new TypeError('"options" argument must be an object'))
const {
namespace,
code,
type,
message,
state
} = options
const {
namespace,
code,
type,
message,
state
} = options
this.namespace = namespace
this.code = code
this.type = type
this.message = message
this.state = state
} else if (args.length === 2) {
const [code, message] = args
new Validator(namespace)
.isNotExists()
.or
.isString()
.throw(new TypeError('"namespace" property must be a string'))
new Validator(code)
.isExists()
.throw(new Error('"code" property is required'))
.isString()
.throw(new TypeError('"code" property must be a string'))
new Validator(type)
.isNotExists()
.or
.isString()
.throw(new TypeError('"type" property must be a string'))
new Validator(message)
.isExists()
.throw(new Error('"message" property is required'))
.isString()
.throw(new TypeError('"message" property must be a string'))
new Validator(state)
.isNotExists()
.or
.isObject()
.throw(new TypeError('"state" property must be an object'))
validator.isValidCodeArgument(code)
validator.isValidMessageArgument(message)
this.namespace = namespace
this.code = code
this.type = type
this.message = message
this.state = state
break
}
case 3: {
const [code, type, message] = args
this.code = code
this.message = message
} else {
const [code, type, message] = args
new Validator(code)
.isExists()
.throw(new Error('"code" argument is required'))
.isString()
.throw(new TypeError('"code" argument must be a string'))
new Validator(type)
.isExists()
.throw(new Error('"type" argument is required'))
.isString()
.throw(new TypeError('"type" argument must be a string'))
new Validator(message)
.isExists()
.throw(new Error('"message" argument is required'))
.isString()
.throw(new TypeError('"message" argument must be a string'))
validator.isValidCodeArgument(code)
validator.isValidTypeArgument(type)
validator.isValidMessageArgument(message)
this.code = code
this.type = type
this.message = message
break
}
default: {
const [code, message] = args
this.code = code
this.type = type
this.message = message
new Validator(code)
.isExists()
.throw(new Error('"code" argument is required'))
.isString()
.throw(new TypeError('"code" argument must be a string'))
new Validator(message)
.isExists()
.throw(new Error('"message" argument is required'))
.isString()
.throw(new TypeError('"message" argument must be a string'))
this.code = code
this.message = message
}
}

@@ -54,3 +111,7 @@

setNamespace(namespace) {
validator.isValidNamespaceArgument(namespace)
new Validator(namespace)
.isExists()
.throw(new Error('"namespace" argument is required'))
.isString()
.throw(new TypeError('"namespace" argument must be a string'))
this.namespace = namespace

@@ -61,3 +122,7 @@ return this

setCode(code) {
validator.isValidCodeArgument(code)
new Validator(code)
.isExists()
.throw(new Error('"code" argument is required'))
.isString()
.throw(new TypeError('"code" argument must be a string'))
this.code = code

@@ -68,3 +133,7 @@ return this

setType(type) {
validator.isValidTypeArgument(type)
new Validator(type)
.isExists()
.throw(new Error('"type" argument is required'))
.isString()
.throw(new TypeError('"type" argument must be a string'))
this.type = type

@@ -75,3 +144,7 @@ return this

setMessage(message) {
validator.isValidMessageArgument(message)
new Validator(message)
.isExists()
.throw(new Error('"message" argument is required'))
.isString()
.throw(new TypeError('"message" argument must be a string'))
this.message = message

@@ -82,14 +155,17 @@ return this

setState(newState) {
validator.isValidNewStateArgument(newState)
switch (typeof newState) {
case 'object': {
this.state = newState
break
}
case 'function': {
const state = newState(this.state)
validator.isValidNewStateCallback(state)
this.state = state
break
}
new Validator(newState)
.isExists()
.throw(new Error('"newState" argument is required'))
.isObject()
.or
.isFunction()
.throw(new TypeError('"newState" argument must be an object or a callback function'))
if (validator.isFunction(newState)) {
const state = newState(this.state)
new Validator(state)
.isObject()
.throw(new TypeError('"newState" callback function must return an object'))
this.state = state
} else {
this.state = newState
}

@@ -96,0 +172,0 @@ return this

{
"name": "@darkwolf/code-error",
"version": "2.0.6",
"version": "2.0.7",
"description": "Code Error Utility",

@@ -26,4 +26,4 @@ "main": "index.js",

"dependencies": {
"@darkwolf/state": "^1.0.1"
"@darkwolf/validator": "^2.0.2"
}
}
# Code Error Utility
## Contact Me
### Telegram: @PavelWolfDark or https://t.me/PavelWolfDark
## Donation
#### You can donate to the development of open source projects
#### BTC Address
### 15sjjAUtJdB1ncsxKK7KtyJPtF46UhXWo4
#### Thanks!:3
## Install

@@ -67,10 +60,2 @@ ```sh

### setMessage(message)
### setState(state || callback(state => newState))
## Error Codes
#### invalid-options
#### invalid-namespace
#### invalid-code
#### invalid-type
#### invalid-message
#### invalid-state
#### invalid-new-state
### setState(newState || callback(state => newState))
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