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

@darkwolf/validator

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@darkwolf/validator - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

utils/errors.js

168

index.js
const CodeError = require('@darkwolf/code-error')
const errors = require('@darkwolf/errors')
const errors = require('./utils/errors')
class Validator {
constructor() {
this.isBoolean = this.isBoolean.bind(this)
this.isNumber = this.isNumber.bind(this)
this.isString = this.isString.bind(this)
this.isObject = this.isObject.bind(this)
this.isFunction = this.isFunction.bind(this)
this.isArray = this.isArray.bind(this)
this.isUsername = this.isUsername.bind(this)
this.isEmail = this.isEmail.bind(this)
this.isPhoneNumber = this.isPhoneNumber.bind(this)
this.isDarkwolfId = this.isDarkwolfId.bind(this)
this.isPassword = this.isPassword.bind(this)
this.isVerificationCode = this.isVerificationCode.bind(this)
this.isUid = this.isUid.bind(this)
}
this.isUrl = this.isUrl.bind(this)
isBoolean(value) {
return typeof value === 'boolean'
this.Validator = Validator
}
isNumber(value) {
return typeof value === 'number'
}
isString(value) {
return typeof value === 'string'
}
isObject(value) {
return typeof value === 'object'
}
isFunction(value) {
return typeof value === 'function'
}
isObjectExact(value) {
return Object.prototype.toString.call(value) === '[object Object]'
}
isArray(value) {
return Array.isArray(value)
}
isBuffer(value) {
return Buffer.isBuffer(value)
}
isRegExp(value) {
return value instanceof RegExp
}
isPromise(value) {
return value instanceof Promise
}
isError(value) {
return value instanceof Error
}
isCodeError(value) {

@@ -69,10 +18,2 @@ return value instanceof CodeError

isTypeError(value) {
return value instanceof TypeError
}
isUsername(value) {
return /^(?!.*_{2,}.*)[a-z][a-z\d_]{3,30}[a-z\d]$/.test(value)
}
isEmail(value) {

@@ -82,10 +23,7 @@ return /^(?![^A-Z]*[A-Z])\S+@\S+\.\S+$/.test(value)

isPhoneNumber(value) {
return /^\+\d{5,15}$/.test(value)
isValidEmail(value) {
if (!this.isEmail(value)) throw errors.INVALID_EMAIL
return true
}
isDarkwolfId(value) {
return this.isUsername(value) || this.isEmail(value) || this.isPhoneNumber(value)
}
isPassword(value) {

@@ -95,100 +33,26 @@ return /^(?=[^A-Z]*[A-Z])(?=[^a-z]*[a-z])(?=\D*\d)(?=[^!@#$%^&*]*[!@#$%^&*])[\w!@#$%^&*]{6,20}$/.test(value)

isVerificationCode(value) {
return /^\d{6}$/.test(value)
isValidPassword(value) {
if (!this.isPassword(value)) throw errors.INVALID_PASSWORD
return true
}
isUid(value) {
return /^[1-9]\d{8}$/.test(value)
return /^\d{9}$/.test(value)
}
isValidBoolean(value, name, code, data) {
if (!this.isBoolean(value)) {
const message = `${name || 'Value'} must be a boolean`
if (code) throw new CodeError(code, message, data)
throw new TypeError(message)
}
isValidUid(value) {
if (!this.isUid(value)) throw errors.INVALID_UID
return true
}
isValidNumber(value, name, code, data) {
if (!this.isNumber(value)) {
const message = `${name || 'Value'} must be a number`
if (code) throw new CodeError(code, message, data)
throw new TypeError(message)
}
return true
isUrl(value) {
return /^https?:\/\/\S+\.\S+$/.test(value)
}
isValidString(value, name, code, data) {
if (!this.isString(value)) {
const message = `${name || 'Value'} must be a string`
if (code) throw new CodeError(code, message, data)
throw new TypeError(message)
}
isValidUrl(value) {
if (!this.isUrl(value)) throw errors.INVALID_URL
return true
}
isValidObject(value, name, code, data) {
if (!this.isObject(value)) {
const message = `${name || 'Value'} must be an object`
if (code) throw new CodeError(code, message, data)
throw new TypeError(message)
}
return true
}
isValidFunction(value, name, code, data) {
if (!this.isFunction(value)) {
const message = `${name || 'Value'} must be a function`
if (code) throw new CodeError(code, message, data)
throw new TypeError(message)
}
return true
}
isValidArray(value, name, code, data) {
if (!this.isArray(value)) {
const message = `${name || 'Value'} must be an array`
if (code) throw new CodeError(code, message, data)
throw new TypeError(message)
}
return true
}
isValidUsername(value) {
if (!this.isUsername(value)) throw errors.INVALID_USERNAME
return true
}
isValidEmail(value) {
if (!this.isEmail(value)) throw errors.INVALID_EMAIL
return true
}
isValidPhoneNumber(value) {
if (!this.isPhoneNumber(value)) throw errors.INVALID_PHONE_NUMBER
return true
}
isValidDarkwolfId(value) {
if (!this.isDarkwolfId(value)) throw errors.INVALID_DARKWOLF_ID
return true
}
isValidPassword(value) {
if (!this.isPassword(value)) throw errors.INVALID_PASSWORD
return true
}
isValidVerificationCode(value) {
if (!this.isVerificationCode(value)) throw errors.INVALID_VERIFICATION_CODE
return true
}
isValidUid(value) {
if (!this.isUid(value)) throw errors.INVALID_UID
return true
}
}
module.exports = new Validator()
{
"name": "@darkwolf/validator",
"version": "1.1.4",
"description": "Darkwolf Validator",
"version": "1.1.5",
"description": "Validator",
"main": "index.js",

@@ -14,3 +14,2 @@ "scripts": {

"keywords": [
"darkwolf",
"validator"

@@ -23,7 +22,3 @@ ],

},
"homepage": "https://github.com/darkwolf/validator#readme",
"dependencies": {
"@darkwolf/code-error": "^1.0.2",
"@darkwolf/errors": "^1.1.8"
}
"homepage": "https://github.com/darkwolf/validator#readme"
}
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