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

laravel-vue2-validator

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

laravel-vue2-validator - npm Package Compare versions

Comparing version 0.0.9-beta-0 to 0.0.9-beta-1

179

index.js

@@ -1,44 +0,155 @@

import Validator from './Validator'
import ErrorComponent from './ErrorComponent.vue'
import axios from 'axios'
class Validator {
install (Vue) {
Vue.component('error', ErrorComponent);
if (Vue.http) {
Vue.http.interceptors.push((request, next) => {
next(response => {
if (response.status === 422) {
Validator.fill(response.body)
}
});
});
export default class Validator {
constructor () {
this.errors = {}
this.busy = false
this.success = false
}
/**
* Missed field method
* @param {string|null} field
*/
missed(field = null) {
return !this.has(field);
}
/**
* Missed field method
* @param {string|null} field
*/
nullState(field = null) {
return this.has(field) ? !this.has(field) : null;
}
/**
* Check if field has any error
* @param {string} key
* @return {boolean}
*/
has (key) {
return this.errors[key] !== undefined
}
/**
* Get first error message by key
* @param {string} key
* @return {*}
*/
first (key) {
if (this.has(key)) {
return this.errors[key][0]
}
if (axios) {
axios.interceptors.response.use((response) => {
return response;
}, (error) => {
const { response } = error
return null
}
/**
* Get all errors by key
* @param {string} key
* @return {*}
*/
get (key) {
if (this.has(key)) {
return this.errors[key]
}
}
/**
* Get all errors
* @return {{}}
*/
all () {
return this.errors
}
/**
* Fill errors object
* @param values
*/
fill (values) {
this.errors = values
}
/**
* Clear all errors
*/
flush () {
this.errors = {}
}
/**
* Clear one or all error fields.
*
* @param {String|undefined} field
*/
clear (field) {
const errors = {}
if (field) {
Object.keys(this.errors).forEach(key => {
if (key !== field) {
errors[key] = this.errors[key]
}
})
}
this.fill(errors)
}
/**
* Clear errors on keydown.
*
* @param {KeyboardEvent} event
*/
onKeydown (event) {
const { name } = event.target
if (name) {
this.clear(name)
}
}
}
export function install (Vue, options = {}) {
const defaults = { ...options }
const validator = new Validator(defaults);
Vue.component('error', ErrorComponent);
if (Vue.http) {
Vue.http.interceptors.push((request, next) => {
next(response => {
if (response.status === 422) {
const { data = {} } = response.data.errors
Validator.fill(data.errors)
validator.fill(response.body)
}
return Promise.reject(error);
});
}
Vue.mixin({
beforeCreate () {
this.$options.$errors = {};
Vue.util.defineReactive(this.$options, '$errors', Errors);
if (!this.$options.computed) {
this.$options.computed = {}
}
this.$options.computed["$errors"] = function () {
return this.$options.$errors;
};
},
})
});
}
if (axios) {
axios.interceptors.response.use((response) => {
return response;
}, (error) => {
const { response } = error
if (response.status === 422) {
const { data = {} } = response.data.errors
validator.fill(data.errors)
}
return Promise.reject(error);
});
}
Vue.mixin({
beforeCreate () {
this.$options.$errors = {};
Vue.util.defineReactive(this.$options, '$errors', Errors);
if (!this.$options.computed) {
this.$options.computed = {}
}
this.$options.computed["$errors"] = function () {
return this.$options.$errors;
};
},
})
}
export default new Validator()
Validator.install = install
const validator = new Validator();
export { validator as Validator }

2

package.json
{
"name": "laravel-vue2-validator",
"version": "0.0.9-beta-0",
"version": "0.0.9-beta-1",
"description": " Simple package to display error in vue from laravel validation",

@@ -5,0 +5,0 @@ "main": "index.js",

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