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

simple-vue-regex-directive

v1.1.1

Published

Generate simple regex directives to apply styles to inputs or custom component with a single inner input in Vue

Downloads

12

Readme

simple-vue-regex-directive

Package on NPM Package on GitHub

Simple, no-dependency way to validate textual <input> fields (including email and number) with Vue directives. This system works on custom components as well, so long as the custom component only has one text input within the custom definition. Has no dependencies, but must be using ES6 for the project (use Babel or comparable, which ships with Vue CLI projects).

Use

JS Use
Globally
//
import Vue from 'vue'
import SimpleVueRegexDirective from 'simple-vue-regex-directive'
// You can name it anything you like, will be usable with: v-regex with this val
Vue.directive('regex', SimpleVueRegexDirective({
  // Arbitrary key-value pairs for input's style. See "Locally" for the default.
  color: 'red'
}))
Locally:
export default {
  name: 'YourComponent',
  directives: {
    // name within component, usable in component with v-regex with this value
    regex: SimpleVueRegexDirective({
      // Arbitrary styles to apply on error. This value here is the default.
      'box-shadow': '0 0 5px 5px red inset'
    })
  }
}
HTML Use:
Static value, only numbers

Note quad-backslash and single quotes, to escape to \d in RegExp:

<input v-regex="'^\\\\d+$'"/>
Dynamic values, only numbers, as String:
export default {
  data () {
    return {
      stringPattern: '^\\d+$',
      regexpPattern: /^\d+$/
    }
  }
}
<input v-regex="stringPattern"/>
<any-component-with-only-one-inner-input v-regex="regexpPattern"/>
Notes:
  • Passing anything but an Object for error styles makes it use the default val
  • Only string values can be used as the values in the error styles object

License: MIT