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.8 to 2.0.9

125

index.js

@@ -8,5 +8,5 @@ const validator = require('@darkwolf/validator')

const [options] = args
const [params] = args
if (validator.isObject(options)) {
if (validator.isObjectExact(params)) {
const {

@@ -18,3 +18,3 @@ namespace,

state
} = options
} = params

@@ -24,12 +24,16 @@ if (validator.isExists(namespace)) {

.isString()
.throw(() => new TypeError('"namespace" property must be a string'))
.throw(() => new TypeError('"params.namespace" property must be a string'))
.isLength(2, 64)
.throw(() => new Error('"params.namespace" property must be between 2 and 64 characters long'))
this.namespace = namespace
}
new Validator(code)
.isExists()
.throw(() => new Error('"code" property is required'))
.isString()
.throw(() => new TypeError('"code" property must be a string'))
this.code = code
if (validator.isExists(code)) {
new Validator(code)
.isString()
.throw(() => new TypeError('"params.code" property must be a string'))
.isLength(1, 64)
.throw(() => new Error('"params.code" property must be between 1 and 64 characters long'))
this.code = code
}

@@ -39,59 +43,43 @@ if (validator.isExists(type)) {

.isString()
.throw(() => new TypeError('"type" property must be a string'))
.throw(() => new TypeError('"params.type" property must be a string'))
.isLength(1, 64)
.throw(() => new Error('"params.type" property must be between 1 and 64 characters long'))
this.type = type
}
new Validator(message)
.isExists()
.throw(() => new Error('"message" property is required'))
.isString()
.throw(() => new TypeError('"message" property must be a string'))
this.message = message
if (validator.isExists(message)) {
new Validator(message)
.isString()
.throw(() => new TypeError('"params.message" property must be a string'))
.isLength(0, 2048)
.throw(() => new Error('"params.message" property must be between 0 and 2048 characters long'))
this.message = message
}
if (validator.isExists(state)) {
new Validator(state)
.isObject()
.throw(() => new TypeError('"state" property must be an object'))
.isObjectExact()
.throw(() => new TypeError('"params.state" property must be an object'))
this.state = state
}
} else {
if (args.length > 2) {
const [code, type, message] = args
const [code, 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'))
new Validator(code)
.isRequired()
.throw(() => new Error('"code" argument is required'))
.isString()
.throw(() => new TypeError('"code" argument must be a string'))
.isLength(1, 64)
.throw(() => new Error('"code" argument must be between 1 and 64 characters long'))
this.code = code
this.code = code
this.type = type
this.message = message
} else {
const [code, 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(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
}
new Validator(message)
.isRequired()
.throw(() => new Error('"message" argument is required'))
.isString()
.throw(() => new TypeError('"message" argument must be a string'))
.isLength(0, 2048)
.throw(() => new Error('"message" argument must be between 0 and 2048 characters long'))
this.message = message
}

@@ -108,6 +96,8 @@

new Validator(namespace)
.isExists()
.isRequired()
.throw(() => new Error('"namespace" argument is required'))
.isString()
.throw(() => new TypeError('"namespace" argument must be a string'))
.isLength(2, 64)
.throw(() => new Error('"namespace" argument must be between 2 and 64 characters long'))
this.namespace = namespace

@@ -119,6 +109,8 @@ return this

new Validator(code)
.isExists()
.isRequired()
.throw(() => new Error('"code" argument is required'))
.isString()
.throw(() => new TypeError('"code" argument must be a string'))
.isLength(1, 64)
.throw(() => new Error('"code" argument must be between 1 and 64 characters long'))
this.code = code

@@ -130,6 +122,8 @@ return this

new Validator(type)
.isExists()
.isRequired()
.throw(() => new Error('"type" argument is required'))
.isString()
.throw(() => new TypeError('"type" argument must be a string'))
.isLength(1, 64)
.throw(() => new Error('"type" argument must be between 1 and 64 characters long'))
this.type = type

@@ -141,7 +135,8 @@ return this

new Validator(message)
.isExists()
.isRequired()
.throw(() => new Error('"message" argument is required'))
.isString()
.throw(() => new TypeError('"message" argument must be a string'))
this.message = message
.isLength(0, 2048)
.throw(() => new Error('"message" argument must be between 0 and 2048 characters long'))
return this

@@ -152,5 +147,5 @@ }

new Validator(newState)
.isExists()
.isRequired()
.throw(() => new Error('"newState" argument is required'))
if (validator.isObject(newState)) {
if (validator.isObjectExact(newState)) {
this.state = newState

@@ -160,4 +155,4 @@ } else if (validator.isFunction(newState)) {

new Validator(state)
.isObject()
.throw(() => new TypeError('"newState" callback function must return an object'))
.isObjectExact()
.throw(() => new TypeError('"newState" argument must return an object'))
this.state = state

@@ -164,0 +159,0 @@ } else {

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

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

"dependencies": {
"@darkwolf/validator": "^2.0.3"
"@darkwolf/validator": "^2.0.8"
}
}

@@ -7,8 +7,7 @@ # Code Error Utility

## Concept
#### Everything is an object!
#### There are only properties and arguments!
#### Custom error class instances must be called a namespace using PascalCase and end with 'Error' (ex. CustomNamespaceError)
#### Use kebab-case to name namespaces, codes, and error types
#### Use the following types for error types:
###### argument-required
###### invalid-argument-type
###### invalid-argument-value
###### property-required

@@ -18,4 +17,10 @@ ###### invalid-property-type

###### unknown-property
###### invalid-return-type
###### invalid-return-value
###### property-return-invalid-type
###### property-return-invalid-value
###### argument-required
###### invalid-argument-type
###### invalid-argument-value
###### unknown-argument
###### argument-return-invalid-type
###### argument-return-invalid-value
#### Pass state to error instance

@@ -29,4 +34,5 @@ #### Use a directory called 'utils' to store custom error class instances, errors and validators

class CustomNamespaceError extends CodeError {
constructor(code, message) {
super({namespace: 'custom-namespace', code, message})
constructor(...args) {
super(...args)
this.namespace = 'custom-namespace'
}

@@ -57,3 +63,3 @@ }

## Init
### new CodeError(options[namespace, code, type, message, state] || [code[, type?[, message]]])
### new CodeError(params[namespace, code, type, message, state] || ...[code, message])
## Methods

@@ -60,0 +66,0 @@ ### setNamespace(namespace)

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