npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@treacherous/vue

v0.5.0

Published

A vue plugin to use the treacherous validation system

Downloads

7

Readme

Treacherous-Vue

What is it?

It is a validation plugin for Vue that lets you validate on data, props, computed properties within your components.

  • For Vue 2.x support use 0.4.x versions
  • Version >= 0.5.x are for Vue 3.x

VIEW THE EXAMPLE/DEMO HERE

Treacherous info

This is the Vue wrapper for Treacherous, which is slightly different in usage than the knockout and aurelia ones as it follows existing paradigms set by vues existing validation libraries.

It is worth reading over the Treacherous libraries if you want to do more than basic validation scenarios, they can be found:

Usage

Installation

To use treacherous in vue you will need to install this module:

npm install @treacherous/vue

Then register the plugin with vue:

import Vue from "vue";
import TreacherousPlugin from "@treacherous/vue";

myApp.use(TreacherousPlugin);

Once you have done this you can use the ValidateWith(ruleset, options?) mixin.

HALP! I DONT USE MODULES

if you are living in the era before modules just grab the UMD module which adds you the TreacherousVue object, and you would do Vue.use(TreacherousVue.default);.

You will still need to include the treacherous UMD module which will provide Treacherous global for use.

Simple Use Case

import {createRuleset, ValidateWith} from "@treacherous/vue";

const ruleset = createRuleset()
        .forProperty("name")
            .addRule("required")
        .build();

myApp.component('my-component', {
    data: function() {
        name: "Bob"
    },
    template: '<input id="name" v-model="name" v-show-error validate-property="name" />',
    mixins: [ ValidateWith(ruleset) ]
});

So as seen above you can optionally provide for any component a ruleset property, which if used will pick up what rules you want to apply to the data contained within the component.

What does the mixin give me?

When you register the mixin you get:

  • modelErrors data object, which is kept up to date by the validation system
  • isValid computed, which monitors the modelErrors and gives a high level true/false accessor
  • model-state-changed event, which is raised whenever the validation state changes (passes out { isValid, modelErrors }
  • getValidationGroup() method, which gets the underlying validation group
  • refreshValidation() method, which manually refreshes the underlying validation state

What are the options I can provide?

  • withReactiveValidation: boolean makes the view react to validation changes without you progmatically validating
  • validateOnStart: boolean validates the model when the component is created and shows errors up front, rather than waiting for changes/progmatic validation calls
  • validateProps: boolean enables validation of props fields (by default only data fields are used)
  • validateComputed: boolean enables validation of computed fields (by default only data fields are used)

What are the directives

  • v-show-error this tells the element to display errors for validation elements (required you to set target property via validate-property="some-data-property")
  • v-validation-summary this should be passed the validation group/s you want to output a summary for

See examples for use cases on both of these directives.

Docs

There are docs on each subject within the docs folder, its worth reading them and viewing the example to see how to use the framework and how to make use of treacherous features.

VIEW THE DOCS HERE

VIEW THE EXAMPLE/DEMO HERE

Credits

"Mountains" Icon courtesy of The Noun Project, by Aleksandr Vector, under CC 3.0

"Vue" Icon courtesy of vue.js project