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

@kiwilan/typescriptable-laravel

v2.4.36

Published

Add some helpers for your Inertia app with TypeScript.

Downloads

339

Readme

@kiwilan/typescriptable-laravel

Add some helpers for your Inertia app with TypeScript.

[!IMPORTANT]

Installation

# npm
npm install @kiwilan/typescriptable-laravel --save-dev
# pnpm
pnpm add @kiwilan/typescriptable-laravel -D
# yarn
yarn add @kiwilan/typescriptable-laravel -D

Features

  • 🦾 Add TypeScript experience into inertia
  • 💨 Vite plugin to execute automatically kiwilan/typescriptable-laravel's commands :' typescriptable:models, typescriptable:routes and typescriptable:routes with watch mode.
  • 📦 Vue composables
    • useRouter() composable with isRoute() method, currentRoute computed and route() method
    • useInertia() composable for page computed, component computed, props computed, url computed, version computed, auth computed, user computed and isDev computed
    • useFetch() with http group methods, laravel group methods and inertia group methods. Each group has get(), post(), put(), patch() and delete() methods
      • http is for anonymous HTTP requests with native fetch
      • laravel is for Laravel HTTP requests with route name (works for internal API) with native fetch
      • inertia is for Inertia HTTP requests with route name
  • 💚 Vue plugin to use global methods for template into Vue components:
    • $route transform route to string with Laravel route name and parameters
    • $isRoute transform route name or path to boolean
    • $currentRoute give current route
    • Auto-import : Head from @inertiajs/vue3, Link from @inertiajs/vue3

Setup

Vite plugin

In your vite.config.ts:

import { defineConfig } from "vite";
import typescriptable from "@kiwilan/typescriptable-laravel/vite";

export default defineConfig({
    plugins: [
        typescriptable({
            autoreload: true,
            inertia: true,
            inertiaPaths: {
                base: "resources/js",
                pageType: "types-inertia.d.ts",
                globalType: "types-inertia-global.d.ts",
            },
            models: true,
            routes: true,
            settings: true,
        }),
    ],
});

Inertia

In your resources/js/app.ts:

import "./bootstrap";
import "../css/app.css";

import type { DefineComponent } from "vue";
import { createApp, h } from "vue";
import { createInertiaApp, router } from "@inertiajs/vue3";
import { resolvePageComponent } from "laravel-vite-plugin/inertia-helpers";
import { ZiggyVue } from "../../vendor/tightenco/ziggy/dist/vue.m";
import { VueTypescriptable } from "@kiwilan/typescriptable-laravel"; // Import VueTypescriptable
import "./routes"; // Import routes

createInertiaApp({
    title: (title) => `${title} - Laravel`,
    resolve: (name) =>
        resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob("./Pages/**/*.vue")) as Promise<DefineComponent>,
    setup({ el, App, props, plugin }) {
        createApp({ render: () => h(App, props) })
            .use(plugin)
            .use(ZiggyVue)
            .use(VueTypescriptable); // Add Vue plugin
            .mount(el)
    },
});

Usage

Many options are available into composables

<script lang="ts" setup>
import {
    useRouter,
    useInertia,
    useFetch,
} from "@kiwilan/typescriptable-laravel";

const { route, isRoute, currentRoute } = useRouter();
const { page, component, props, url, version, auth, user, isDev } =
    useInertia();
// HTTP requests, each group has get(), post(), put(), patch() and delete() methods
const { http, laravel, inertia } = useFetch();
</script>

With Vue plugin, you can use global methods into your template:

<template>
    <IHead title="Home" />
    <ILink :href="$route('home')">Home</ILink>
    <ILink :href="$route('user.show', { id: 1 })">User</ILink>
</template>

Tests

Local test

pnpm package

In package.json

{
    "devDependencies": {
        "@kiwilan/typescriptable-laravel": "file:~/kiwilan-typescriptable-laravel.tgz"
    }
}