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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kne/fastify-shorten

v1.0.16

Published

Fastify Shorten 是一个专为 Fastify 框架设计的 URL 缩短服务插件,提供完整的短链接生成和管理功能

Readme

fastify-shorten

描述

Fastify Shorten 是一个专为 Fastify 框架设计的 URL 缩短服务插件,提供完整的短链接生成和管理功能

安装

npm i --save @kne/fastify-shorten

概述

功能概述

Fastify Shorten 是一个专为 Fastify 框架设计的 URL 缩短服务插件,提供完整的短链接生成和管理功能。

核心特性

  • 🚀 高性能短链生成:基于高效算法快速生成短码
  • 🔗 URL 重定向:自动将短链接重定向到原始 URL
  • 🛠️ 可配置选项:支持自定义短码长度、重试机制等
  • 🗃️ 数据库集成:自动管理短链接存储表

使用场景

  1. 营销活动链接追踪
  2. 社交媒体链接优化
  3. 企业内部链接管理
  4. 需要缩短长URL的任何应用

基本用法

const fastify = require('fastify')();
const shortenPlugin = require('@kne/fastify-shorten');

// 注册插件
fastify.register(shortenPlugin, {
  // 此处填写配置项
});

fastify.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log('服务器运行在 3000 端口');
});

注意事项

  1. 需要预先配置好数据库连接
  2. 确保数据库用户有创建表的权限
  3. 生产环境建议修改默认表名前缀

许可证

MIT

示例

示例代码

API

配置选项

| 选项 | 类型 | 默认值 | 说明 | |------|------|--------|------| | maxAttempts | number | 10 | 生成唯一短码的最大尝试次数 | | length | number | 6 | 生成的短码长度 | | dbTableNamePrefix | string | 't_' | 数据库表名前缀 |

命名空间注册

本插件通过 @kne/fastify-namespace 自动注册到 shorten 命名空间下,所有相关方法可通过 fastify.shorten 访问。

自定义配置示例

fastify.register(shortenPlugin, {
  maxAttempts: 15,      // 增加尝试次数
  length: 8,            // 生成长度8的短码
  dbTableNamePrefix: 'short_' // 自定义表前缀
});