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

multi-framework-component-transpiler

v1.0.2

Published

Transpile components to multiple frameworks

Downloads

61

Readme

Multi-Framework Component Transpiler

Transpile components to multiple frameworks with ease.
This tool converts your global JavaScript code or framework-specific files into compatible components for multiple frameworks, including React, Vue, Svelte, Angular, and vanilla JavaScript.


Features

  • Supports React, Vue, Svelte, Angular, and Vanilla JS.
  • Generates both JavaScript and TypeScript components.
  • Handles lifecycle hooks for each framework (e.g., useEffect, onMounted, onMount, etc.).
  • Works with .js, .ts, .jsx, .tsx, .vue, and .svelte input files.

Installation

Install via npm (Global)

npm install -g multi-framework-component-transpiler

Usage

After installation, use the multi-transpile command to transpile your input files.

Command Syntax

multi-transpile <inputFile> [outputDir]
  • <inputFile>: The path to the input file. Supported formats: .js, .jsx, .ts, .tsx, .vue, .svelte.
  • [outputDir]: (Optional) The directory where transpiled files will be saved. Defaults to ./transpiled-components.

Example

multi-transpile input.js ./output

This command reads input.js, processes the global and framework-specific code, and generates components in multiple frameworks in the ./output directory.


Output Files

The tool generates the following files:

React

  • file.jsx (React component in JavaScript)
  • file.tsx (React component in TypeScript)

Vue

  • file.vue (Vue component in JavaScript)
  • file.ts.vue (Vue component in TypeScript)

Svelte

  • file.svelte (Svelte component in JavaScript)
  • file.ts.svelte (Svelte component in TypeScript)

Angular

  • angular_folder/my-component.component.ts (Angular component in TypeScript)

Vanilla JavaScript

  • file.js (Vanilla JavaScript ESNext)
  • file.es5.js (Vanilla JavaScript ES5)
  • file.ts (Vanilla TypeScript)

Example Input and Output

Input (input.js)

// Some global code
console.log(window.location.href);
localStorage.setItem('key', 'value');

// A sample function
function greet() {
  alert('Hello, World!');
}

Example Output (output/ Directory)

React (JavaScript)

file.jsx

import React, { useEffect } from 'react';

function MyComponent() {
  useEffect(() => {
    console.log(window.location.href);
    localStorage.setItem('key', 'value');
  }, []);

  return <div>My Component</div>;
}

export default MyComponent;

Vue (TypeScript)

file.ts.vue

<template>
  <div>My Component</div>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';

onMounted((): void => {
  console.log(window.location.href);
  localStorage.setItem('key', 'value');
});
</script>

Angular

angular_folder/my-component.component.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-my-component',
  template: `<div>My Component</div>`,
})
export class MyComponent implements OnInit {
  ngOnInit(): void {
    console.log(window.location.href);
    localStorage.setItem('key', 'value');
  }
}

Supported Input Formats

  • JavaScript (.js)
  • TypeScript (.ts)
  • React (.jsx, .tsx)
  • Vue (.vue)
  • Svelte (.svelte)

Supported Frameworks

The following frameworks are supported, along with their respective lifecycle hooks:

| Framework | Lifecycle Hook | |-----------|------------------------------| | React | useEffect | | Vue | onMounted | | Svelte | onMount | | Angular | ngOnInit | | Vanilla | IIFE (Immediately Invoked Function Expression) |


Development

Prerequisites

Ensure you have the following installed:

  • Node.js (v14 or later)
  • npm (Node Package Manager)

Clone the Repository

git clone https://github.com/LuisArmando-TestCoder/multi-framework-component-transpiler.git
cd multi-framework-component-transpiler

Install Dependencies

npm install

Test Locally

To test the command locally without publishing:

npm link

You can now use the multi-transpile command globally on your system.


Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository.
  2. Create a new branch for your feature/bugfix.
  3. Commit your changes with clear messages.
  4. Submit a pull request.

Issues and Feedback

If you encounter any issues or have feedback, please submit an issue on GitHub:

Report an Issue


License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgments

Me, myself and I

PD: Still in progress, tho...