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

@a-drowned-fish/rox-utils

v1.0.28

Published

for compose

Readme

Rox Utils 工具库说明文档

RoxUtils 是一个整合 App、微信小程序、H5 三端工具方法的工具库,包含环境判断、用户登录、签名 Header、页面跳转、地图能力、App 文件下载/分享、数组工具、图片计算工具等能力。


📑 目录(TOC)


📌 功能总览

| 分类 | 方法 | | -------- | --------------------------------------------------------------------- | | 环境判断 | isMiniProgramisWechat | | 登录 | isLoginenhanceIsLogingetAppUserInfogetEnhanceUserPhone | | Header | getHeadersgetMiniProgramHeadersgetAppHeaders | | 跳转 | toLoginPagetoHomePagejumpToAppPagejumpToMiniProgramPage | | 返回 | goBack | | 地图 | openLocationMap | | App 专用 | appDownloadFileshowAppSharePopup | | API 环境 | getApiBaseUrl | | 数组 | shuffleArrayfillArray | | 图片计算 | getBoxSize | | 其他 | registerMethodsortJson |


🚀 快速开始

import { roxUtils } from "./utils";

// 调用
const logged = await roxUtils.isLogin();

适用于 App + 微信小程序 + H5 三端环境。


🧩 功能说明


1. 环境判断

isMiniProgram()

判断当前是否为微信小程序环境。

isWechat()

判断是否为微信浏览器(公众号/H5)环境。


2. 用户登录能力

isLogin(urlLoginField?, debug?)

环境自动判断是否登录。

enhanceIsLogin()

更严格的登录判断。

getAppUserInfo(toLoginPage?)

App 中获取登录信息(UIKit 封装)。

getEnhanceUserPhone()

部分苹果手机无手机号时的兼容逻辑。


3. Header 生成(带签名)

getHeaders(method, data, key, debug, headers)


4. 页面跳转

toLoginPage()

跳转到对应环境的登录页。

toHomePage()

跳转首页。

jumpToAppPage(options)

App 内跳转任意页面。

jumpToMiniProgramPage(url, isTabBar, reStart)

小程序跳转封装。


5. 返回上一页

goBack({ isShared, homePath })


6. 地图能力

openLocationMap(location)


7. App 下载 / 分享

appDownloadFile(base64OrBlob)

App 内调用原生下载能力。

showAppSharePopup(base64OrBlob)

调用 App 内分享弹窗。


8. API 域名配置

getApiBaseUrl({ mode, buildModule })

9. 数组 / 随机工具

shuffleArray(array)

随机乱序数组。

fillArray({ arr, count, fallbackValue })

把数组填充至固定长度。


10. 图片位置计算

getBoxSize 注: 相对于视口宽高,盒子位置等比缩放

计算图片盒子真实位置(H5)。

getImageBoxSize 注: 并非相对于视口宽高,而是相对于图片(图片有可能高于或者低于视口高度), 盒子位置等比缩放

计算图片内盒子的真实位置 (H5)。


11. 其他工具

registerMethod(eventName, data)

App 调用 JS 的注册方法。

sortJson(json)

按 key 排序。