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

vue2-migration-helper

v0.3.12

Published

Updates vue2 sfc components to vue3 composition api syntax.

Downloads

25

Readme

vue2-migration-helper

Transforms Vue.js SFCs to composition api syntax.

Build Status Codacy Badge codecov Netlify Status All Contributors

NPM

Install

npm i vue2-migration-helper

CLI

# convert all .vue files in source directory and outputs in target directory
vue2-migration-helper --source="source" --target="target"

# displays help
vue2-migration-helper --help

Programatically use

import { vue2MigrationHelper } from 'vue2-migration-helper'

vue2MigrationHelper({
  source: 'source/',
  target: 'target/',
})

Features

  • [x] add setup method
    • with props and context arguments
  • [x] add required vue imports
    • only adds required imports after traversing code
  • [x] update data properties
    • Uses data variable using reactive
    • Return reactive references using ref
    • updates usage of these varaiables
  • [x] update computed syntax
    • defines variable for each property using new syntax computed
  • [x] update watch syntax
    • updates watch syntax
  • [x] integrate methods directly into setup
    • defines methods into the setup body
    • updates method calls
  • [x] update template ref usage
    • adds a new variable for each templateRef using ref(null)
    • add new defined templateRefs to return statement
  • [x] convert props syntax
  • [x] update lifecycle hooks and remove deperecated lifecycle hooks
    • removes depracted life cycle hooks, injects deprecated hooks code into setup method.
    • copies other hooks into the setup method
  • [x] component registration
  • [x] replace this usage with new context parameter for $events etc
    • replaces this keyword usage as this no longer refers to vue component itself.

missing something?

Example

For a Vue.js SFC (single file component) like this:

import SomeComponent from './SomeComponent'
const zero = {}

export default {
  props: {
    title: String,
    likes: Number,
    callback: Function,
  },

  components: {
    SomeComponent,
  },

  data() {
    return {
      one: true,
      two: 2,
      three: 'three',
    }
  },

  watch: {
    one(val) {
      console.log(val)
    },
    two: (val) => {
      console.log(val)
    },
    three: function (a, b) {
      console.log(a, b)
    },
  },

  computed: {
    oneComputed() {
      return !this.one
    },
    twoComputed: () => {
      return !this.one
    },
    threeComputed: function () {
      return !this.one
    },
  },

  created() {
    console.log('created')
  },

  mounted() {
    console.log('mounted')
  },

  methods: {
    ...[
      function fourMethod() {
        console.log('fourMethod')
      },
      function fiveMethod() {
        console.log('fiveMethod')
      },
    ],

    oneMethod() {
      const html = this.$refs.templateRef.innerHTML
      console.log('oneMethod')
      console.log(this.oneComputed)
    },

    twoMethod: function () {
      this.$refs.templateRef.innerHTML = 'html'
      console.log('twoMethod')
      console.log(this.twoComputed)
      this.oneMethod()
      console.log(this.$router)
    },

    threeMethod: () => {
      console.log('threeMethod')
      console.log(this.threeComputed)
      this.twoMethod()

      console.log(this.$store)
    },
  },
}

this script generates Vue SFC using composition API:

import {
  ref,
  reacted,
  toRefs,
  watch,
  computed,
  onCreated,
  onMounted,
} from 'vue'

import SomeComponent from './SomeComponent'
const zero = {}

export default {
  components: {
    SomeComponent,
  },
  props: {
    title: String,
    likes: Number,
    callback: Function,
  },

  setup(props, context) {
    const data = reactive({
      one: true,
      two: 2,
      three: 'three',
    })
    const templateRef = ref(null)
    watch(three, (a, b) => {
      console.log(a, b)
    })
    watch(two, (val) => {
      console.log(val)
    })
    watch(one, (val) => {
      console.log(val)
    })
    const oneComputed = computed(() => {
      return !data.one
    })
    const twoComputed = computed(() => {
      return data.two + 5
    })
    const threeComputed = computed(() => {
      return data.three.toUpperCase()
    })

    ;(() => {
      console.log('created')
    })()

    onMounted(() => {
      console.log('mounted')
    })

    function fourMethod() {
      console.log('fourMethod')
    }

    function fiveMethod() {
      console.log('fiveMethod')
    }

    function oneMethod() {
      const html = templateRef.innerHTML
      console.log('oneMethod')
      console.log(oneComputed)
      console.log(context.$data)
    }

    function twoMethod() {
      templateRef.innerHTML = 'html'
      console.log('twoMethod')
      console.log(twoComputed)
      oneMethod()
      console.log(context.$router)
    }

    function threeMethod() {
      console.log('threeMethod')
      console.log(threeComputed)
      twoMethod()
      console.log(fourMethod)
      console.log(context.$store)
    }

    return {
      ...ref(data),
      oneComputed,
      twoComputed,
      threeComputed,
      fourMethod,
      fiveMethod,
      oneMethod,
      twoMethod,
      threeMethod,
      templateRef,
    }
  },
}