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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@linxs/toolkit-vue

v0.2.0

Published

Vue 3 组合式函数 (Composables) 和指令 (Directives) 工具包

Readme

@linxs/toolkit-vue

Vue 3 Composables and Directives toolkit for common use cases.

中文文档:中文文档

Features

  • 🎣 Composables - Powerful and type-safe Vue 3 composable functions
    • useEventListener - Auto-managed event listeners with cleanup
    • useScrollNavigation - Scroll-based navigation with anchor highlighting
  • Directives - Essential Vue 3 directives for common scenarios
    • v-trim - Automatic input trimming with multiple modes
    • v-auth - Authentication and role-based visibility control
  • 📦 Full TypeScript support with strict type safety
  • 🔄 Reactive and auto-cleanup - No memory leaks
  • 🛠️ Flexible configuration options
  • 🎨 Works with Naive UI components (NScrollbar, etc.)

Installation

# Using npm
npm install @linxs/toolkit-vue

# Using yarn
yarn add @linxs/toolkit-vue

# Using pnpm
pnpm add @linxs/toolkit-vue

Documentation

📖 Complete guides and API references:

Quick Start

Composables

useEventListener

Auto-managed event listeners that cleanup on component unmount:

<script setup>
import { ref } from 'vue';
import { useEventListener } from '@linxs/toolkit-vue';

const buttonRef = ref(null);

// Window events
useEventListener(window, 'resize', () => {
  console.log('Window resized');
});

// Element events with ref
useEventListener(buttonRef, 'click', () => {
  console.log('Button clicked');
});

// Document events with options
useEventListener(
  document,
  'scroll',
  () => console.log('Scrolled'),
  { passive: true }
);
</script>

<template>
  <button ref="buttonRef">Click me</button>
</template>

useScrollNavigation

Scroll-based navigation with menu highlighting:

<script setup>
import { ref, onMounted } from 'vue';
import { useScrollNavigation } from '@linxs/toolkit-vue';

const menus = [
  { id: 1, name: 'Introduction' },
  { id: 2, name: 'Features' },
  { id: 3, name: 'Installation' }
];

const contentRef = ref(null);
const currentMenu = ref(1);

const { scrollToSection, calculateSectionPositions, handleScroll } =
  useScrollNavigation(contentRef, {
    menus,
    onScroll: (menuId) => {
      currentMenu.value = menuId;
    }
  });

onMounted(() => {
  setTimeout(() => calculateSectionPositions(), 100);
});
</script>

<template>
  <div class="container">
    <nav>
      <div
        v-for="menu in menus"
        :key="menu.id"
        :class="{ active: currentMenu === menu.id }"
        @click="scrollToSection(menu.id)"
      >
        {{ menu.name }}
      </div>
    </nav>

    <div ref="contentRef" @scroll="handleScroll">
      <section
        v-for="menu in menus"
        :key="menu.id"
        :id="`section-${menu.id}`"
      >
        <h2>{{ menu.name }}</h2>
        <p>Content...</p>
      </section>
    </div>
  </div>
</template>

Directives

v-trim

Automatic input trimming with multiple modes:

<script setup>
import { createApp } from 'vue';
import { trimDirective } from '@linxs/toolkit-vue';

// Register directive
const app = createApp(App);
app.directive('trim', trimDirective);
</script>

<template>
  <!-- Default: trim start and end whitespace -->
  <input v-trim v-model="username" />

  <!-- Remove all whitespace -->
  <input v-trim.all v-model="username" />

  <!-- Collapse multiple spaces to single space -->
  <input v-trim.collapse v-model="realName" />

  <!-- Real-time trimming -->
  <input v-trim.all.realtime v-model="phone" />
</template>

v-auth

Role-based visibility control:

<script setup>
import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { createAuthDirective } from '@linxs/toolkit-vue';
import { useUserStore } from './stores/user';

const app = createApp(App);
const pinia = createPinia();

app.use(pinia);

// Register auth directive
const authDirective = createAuthDirective(() => useUserStore(pinia));
app.directive('auth', authDirective);
</script>

<template>
  <!-- Show for authenticated users -->
  <div v-auth>Member Area</div>

  <!-- Show for guests only -->
  <div v-auth.guest>Please login</div>

  <!-- Require specific role -->
  <button v-auth="'admin'">Admin Panel</button>

  <!-- Require one of multiple roles -->
  <button v-auth="['admin', 'moderator']">Manage Content</button>

  <!-- Require all roles -->
  <div v-auth.all="['admin', 'vip']">VIP Admin Area</div>
</template>

API Overview

Composables

  • useEventListener(target, event, handler, options?) - Auto-managed event listeners
  • useScrollNavigation(contentRef, options) - Scroll navigation with highlighting

Directives

  • v-trim - Input trimming with modifiers: .all, .collapse, .strict, .realtime
  • v-auth - Auth control with modifiers: .guest, .all

Configuration

useScrollNavigation Options

interface ScrollNavigationOptions {
  menus: MenuItem[];                                    // Menu items
  onScroll: (menuId: string | number) => void;        // Scroll callback
  scrollContainerRef?: HTMLElement | Ref | string;     // Custom scroll container
  offset?: number;                                      // Trigger offset (default: 50px)
}

v-auth Store Requirements

interface UserStore {
  isAuthenticated: boolean;      // Required: login status
  roles?: string[];              // Optional: user roles
  $subscribe?: (callback) => void;  // Optional: for reactivity
}

TypeScript

Fully typed with TypeScript. All types are exported:

import type {
  // Hook types
  MenuItem,
  ScrollNavigationOptions,
  ScrollNavigationReturn,

  // Directive types
  TrimModifiers,
  AuthDirectiveOptions,
  UserStore
} from '@linxs/toolkit-vue';

Browser Support

Supports Vue 3.4+ and all modern browsers.


Why @linxs/toolkit-vue?

This toolkit provides battle-tested Vue 3 utilities that solve common pain points:

  • Auto Cleanup: No more manual event listener cleanup or memory leaks
  • Type Safety: Full TypeScript support with comprehensive type definitions
  • Flexible: Works with standard HTML elements and UI libraries (Naive UI, etc.)
  • Developer Experience: Clean APIs with sensible defaults
  • Production Ready: Thoroughly tested and used in production applications

Perfect for Vue 3 applications that need reliable composables and directives without the overhead of full libraries.

License

MIT © Lin.xs