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

tona-utils

v1.0.23

Published

<p align="center"> <img src="../../assets/tona.png" alt="Tona" width="100" /> </p>

Downloads

291

Readme

tona-utils

English | 中文

特性

  • 博客上下文 - 检测页面类型、用户状态和博客信息
  • 用户操作 - 关注、取消关注、推荐文章
  • URL 助手 - 生成博客园 URL
  • DOM 工具 - 基于 jQuery 的 DOM 辅助函数
  • TypeScript 支持 - 完整的类型定义

安装

npm install tona-utils
pnpm add tona-utils
yarn add tona-utils

使用

import {
  isOwner,
  getLoginState,
  getCurrentPage,
  getFollowers,
  likePost,
} from 'tona-utils'

用户与认证

isOwner()

检查当前用户是否为博客所有者。

import { isOwner } from 'tona-utils'

if (isOwner()) {
  console.log('这是我的博客')
}

getLoginState()

检查用户是否已登录。

import { getLoginState } from 'tona-utils'

const isLoggedIn = getLoginState()

getFollowState()

检查当前用户是否关注了博客作者。

import { getFollowState } from 'tona-utils'

const isFollowing = getFollowState()

页面检测

getCurrentPage()

检测当前页面类型。

import { getCurrentPage } from 'tona-utils'

const page = getCurrentPage()
// 返回: 'home' | 'post' | 'tags' | 'post-archive' | 'category' | 'photos' | 'photo-view' | 'unknown'

页面类型检查

import {
  isHomePage,
  isPostDetailsPage,
  isTagListPage,
  isCategoryPage,
  isAlbumPage,
} from 'tona-utils'

if (isHomePage()) {
  // 在博客首页
}

if (isPostDetailsPage()) {
  // 在博客文章页面
}

博客统计

import {
  getFollowers,
  getFollowing,
  getBlogAge,
  getPostCount,
  getArticleCount,
  getCommentCount,
  getViewCount,
} from 'tona-utils'

const followers = getFollowers() // "123"
const following = getFollowing() // "45"
const age = getBlogAge() // "3年"
const posts = getPostCount() // "100"

用户操作

follow() / unfollow()

关注或取消关注博客作者。

import { follow, unfollow } from 'tona-utils'

follow() // 关注此博客
unfollow() // 取消关注此博客

likePost() / unLikePost()

推荐或取消推荐博客文章。

import { likePost, unLikePost } from 'tona-utils'

likePost() // 推荐此文章
unLikePost() // 取消推荐此文章

URL 助手

import {
  getIndexUrl,
  getFollowersUrl,
  getFolloweesUrl,
  getRssUrl,
  getNewPostUrl,
  getAdminUrl,
} from 'tona-utils'

const blogHome = getIndexUrl() // "https://www.cnblogs.com/username"
const followers = getFollowersUrl() // "https://home.cnblogs.com/u/username/followers"
const rss = getRssUrl() // "https://www.cnblogs.com/username/rss"

博客信息

import {
  getCurrentBlogId,
  getCurrentBlogApp,
  getNickname,
  getBlogUserGuid,
  getSkinName,
} from 'tona-utils'

const blogId = getCurrentBlogId() // "123456"
const blogApp = getCurrentBlogApp() // "username"
const nickname = getNickname() // "博主昵称"
const guid = getBlogUserGuid() // 用户 GUID

代码高亮

import {
  setCodeTheme,
  getCodeHighlightTheme,
  getDarkModeCodeHighlightTheme,
  checkEnableCodeLineNumber,
} from 'tona-utils'

// 设置代码主题
setCodeTheme('dark')

// 检查设置
const hasLineNumbers = checkEnableCodeLineNumber()

相关