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

vue-render-if

v0.1.2

Published

Render Vue slots if properties are not undefined, null, empty strings, or a custom value. This helps avoid long and confusing v-ifs just to check if a property is valid.

Downloads

3

Readme

vue-render-if

The vue-render-if component makes checking against data in your template, easy. This component helps clean up your Vue template when checking for multiple "falsey" values of different types.

Before

<template>
  <div v-if="value1 !== '' && value1 !== undefined && value1 !== null && value2 !== undefined && value2 !== null && value3 !== undefined && value3 !== null">
    <p>I should only render if every value is not undefined, null, or an empty string.</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value1: 'Vue.js',
      value2: true,
      value3: 2018
    }
  }
}
</script>

After

<template>
  <render-if :defined="[value1, value, value3]">
    <p>I should only render if every value is not undefined, null, or an empty string.</p>
  </render-if>
</template>

<script>
import RenderIf from 'vue-render-if';

export default {
  components: {
    RenderIf,
  },
  data() {
    return {
      value1: 'Vue.js',
      value2: true,
      value3: 2018
    }
  }
}
</script>

By default, vue-render-if will render a div and will check if the values passed in the defined props array is either undefined, null, or an empty string ''. You can however, define your own invalid values.

Note: You can also pass in a single value if you are checking against one data or state property.

<template>
  <render-if :defined="value1">
    <p>I should only render if every value is not undefined, null, or an empty string.</p>
  </render-if>
</template>

Options

vue-render-if accepts three props, one of which is required (defined). The other two props are tag and not-valid.

| Prop Name | Required | Default Value | Accepts | Purpose | |-----------|----------|---------------|-------------------------------------|------------------------------------------------------------------------------------------| | defined | yes | N/A | Array (all types) or a single value | List all of the data items that should have a value of some kind for the slot to render. | | tag | no | 'div' | String | Defines the HTML tag render-if should render as. | | not-valid | no | N/A | Array (all types) or a single value | Defines all of the property values that should be considered invalid. |

<template>
  <render-if :defined="value1" tag="section" :not-valid="['foo, bar', undefined, null, '']">
    <p>I should only render if every value is not undefined, null, or an empty string.</p>
  </render-if>
</template>

This instance will...

  • Render if value1 is not 'foo', 'bar', undefined, `null, or empty.
  • Render a section tag.

Note: If you defined values for the not-valid prop, you will need to add undefined, null, and '' if you still want those to be falsy.

Usage

$ yarn add vue-render-if
# or
npm install --save vue-render-if

Add it Globally

main.ts

import RenderIf from 'vue-render-if';

Vue.component('render-if', RenderIf);

Using it in a Vue Component

<script>
import RenderIf from 'vue-render-if';

export default {
  components: {
    RenderIf
  }
}
</script>

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request!

Author

vue-render-if © Dave Berning, Released under the MIT License.

daveberning.io - GitHub - Twitter

Special thanks to Cory Kleiser, Lance Deters, and Craig Mullin.