mazey-taro-utils
v2.0.1
Published
Taro helpers for environment detection, navigation, login, scrolling, toasts, page parameters, and device information.
Maintainers
Readme
mazey-taro-utils
Taro helpers for environment detection, navigation, login, scrolling, toasts, page parameters, and device information.
- Website: https://chengchuu.github.io/mazey-taro-utils/
- Playground: https://chengchuu.github.io/mazey-taro-utils/playground/
- API documentation: https://chengchuu.github.io/mazey-taro-utils/api/
- GitHub: https://github.com/chengchuu/mazey-taro-utils
- npm: https://www.npmjs.com/package/mazey-taro-utils
Install
npm install mazey-taro-utilsQuick start
Import helpers from the package root:
import {
getEnv,
getWindowSize,
quickNavigateTo,
quickToast,
} from "mazey-taro-utils";
quickToast(`Running in ${getEnv() || "an unspecified Taro environment"}`);
quickNavigateTo("profile", {
params: {
userId: "42",
},
});
const { width, height } = getWindowSize();
console.log({ width, height });Public API
Page information
getCurrentPage()returns the current Taro route without its query string.getAllParams()returns the current route parameters, or an empty object.getQueryParam(name)returns one route parameter, or an empty string.
import { getAllParams, getCurrentPage, getQueryParam } from "mazey-taro-utils";
console.log(getCurrentPage());
console.log(getAllParams());
console.log(getQueryParam("userId"));Environment and device information
getEnv()readsprocess.env.TARO_ENV.getWindowSize()returns width, height, width-to-height ratio, and height-to-width ratio from Taro window information.getSystem()returns the Taro system string.isMiniProgram()andisWeapp()detect theweappbuild environment.isBrowser(),isWeb(), andisH5()detect theh5build environment.isPC()uses browser information when the build environment ish5.isWideScreen()andisMiddleScreen()check whether the width-to-height ratio is greater than0.7.isLongScreen()checks whether the height-to-width ratio is greater than1.9.isIOS()andisAndroid()inspect the Taro system string.
import {
getEnv,
getSystem,
getWindowSize,
isH5,
isMiniProgram,
} from "mazey-taro-utils";
console.log({
environment: getEnv(),
system: getSystem(),
window: getWindowSize(),
h5: isH5(),
miniProgram: isMiniProgram(),
});Navigation and interaction
quickNavigateTo(page, options?)calls TaronavigateTowith a route below/pages.quickRedirectTo(page, options?)calls TaroredirectTowith the same route convention.quickScrollTo(selector, duration?)calls TaropageScrollTo; the default duration is300milliseconds.quickToast(message)displays a text-only Taro toast.getLoginCodeAsync()resolves with the Taro login code and rejects when the login request fails or returns no code.
import {
getLoginCodeAsync,
quickRedirectTo,
quickScrollTo,
quickToast,
} from "mazey-taro-utils";
quickToast("Loading profile");
quickRedirectTo("profile", { params: { userId: "42" } });
quickScrollTo("#profile", 500);
const code = await getLoginCodeAsync();
console.log(code);Package outputs
- CommonJS:
lib/index.cjs.js - ES modules:
lib/index.esm.js - Browser IIFE:
lib/mazey-taro-utils.min.js - TypeScript declarations:
lib/index.d.ts
The browser IIFE expects Taro and mazey globals because both runtime
dependencies remain external to the package bundle.
Development
Use Node.js 22 for the repository tooling.
pnpm install
npm run typecheck
npm run lint
npm test
npm run build
npm run docsnpm run docs creates the final GitHub Pages artifact in docs/, including the
homepage, React playground, TypeDoc API site, manifest, icons, service worker,
robots file, and sitemap.
Run a production-like Pages preview at
http://127.0.0.1:4173/mazey-taro-utils/:
npm run pwa:previewThe public playground uses controlled browser-side Taro stubs. It demonstrates the package’s generated requests without claiming to run a real mini-program environment.
License
Released under the MIT License.
