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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mxnet/taro

v0.9.1

Published

taro utils

Downloads

11

Readme

taro

taro utils

Usage

  • package 在浏览器内不会执行也不会报错
import {} from '@mxnet/taro'

getCurRouter

获取当前页面的所有信息

  • 良好的类型声明能节约没必要的判断

  • 避免忘记个别 api 的使用方法

import { getCurRouter } from "@mxnet/taro";

// 定义页面参数类型
type pageParams = {
  age: number;
};
const { getParameter } = getCurRouter<pageParams>();

// 获取页面参数信息
getParameter().age;

Storeage

小程序中的 localstorage utils

  • 良好的类型声明会在定义 setget 的检查你的代码

  • 链式同步调用

import { Storeage } from "@mxnet/taro";
// 定义所有item 的 key 类型
const key = {
  name: "name",
};

new Storeage<typeof key | "age">().set("age", "age").get("age");

SimpleRouteJump

简单的路由跳转

  • 链式调用

  • 新增预跳转验证函数

  • 每个参数都有良好的类型提示

  • 良好的预设

  • 避免拼接 url query , 且 url query 可预设类型

  • 自动处理 url 前缀

import { SimpleRouteJump } from "@mxnet/taro";

//  根据 对象 转换成 url query

SimpleRouteJump.parseParameters({ name: "age", age: "12" }); // => ?name=age&age=12

// url query
interface parameter {
  name: string;
  age: string;
}

new SimpleRouteJump<parameter>("url")
  // 定义跳转方法,良好的类型提示
  // 默认 navigateTo 跳转
  .setMethod("navigateBack")
  // 预跳转回调
  // 在跳转前背调用,根据返回值是否为fasly决定是否发起一次跳转
  .setPreJumpJnterceptor((params: parameter) => false)
  .success(() => {})
  .complete(() => {})
  .fail(() => {})
  // 根据定义方法传递所需参数,良好的类型提示
  .trigger({
    // mete 会将参数附加在url后
    mete: { name: "age", age: "12" }, // => ?name=age&age=12
    // 一下回调会覆盖上方同名回调
    success() {},
    fail() {},
    complete() {},
  });
// 集中管理跳转api
const container = {
  goHome: new SimpleRouteJump("url"),
};

// verfiy.tsx
useEffect(() => {
  container.goHome.trigger();
}, []);

getAppId

获取小程序 appid

getWxLoginCode

同步获取 wxlogin.code

DownloadFile

  • 下载临时文件,缓存文件,用户文件 的集合类

  • 微信文件系统参考 https://developers.weixin.qq.com/miniprogram/dev/framework/ability/file-system.html

  • 灵活的类型声明

import { DownloadFile } from "@mxnet/taro";
// 下载临时文件
new DownloadFile()
  .success((res) => {
    console.log(res);
  })
  .fail(() => {})
  .down({
    url: "",
  });

// 下载临时文件后缓存到本地 成为缓存文件
new DownloadFile()
  .setDownloadLocation("cache")
  .success(() => {})
  .fail(() => {})
  .down({
    url: "",
  });

// 下载并储存到指定路径成为用户文件
new DownloadFile()
  .setDownloadLocation("userFile")
  .success(() => {})
  .fail(() => {})
  .down({
    data: "hahah",
    encoding: "utf-8",
    filePath:
      "/Users/devops/Desktop/maixun/taro-react-template/assets/hello.txt",
  });

ChainCall

  • 链式调用

  • 灵活的类型声明

import { ChainCall } from "@mxnet/taro";

new ChainCall()
  // 选择需要调用的api
  .injectApi("downloadFile")
  // success 回调参数会根据 injectApi 声明自动匹配参数类型, 以下回调同理
  .success(() => {})
  .fail(() => {})
  .complete(() => {})
  // 注入参数
  .injectionParameters({ url: "" })
  // 调用
  .done();

useAudio

  • 解决一个页面中 createInnerAudioContext 实例不一致问题
  • tips: 不要尝试用 setStateuseRef 取创建一个 createInnerAudioContext 实例 ,会变得不幸
const { audioInstanceToUpdate, audioInstanceRef } = useAudio();

// 更新 实例选项
audioInstanceToUpdate({
  src: "",
});

// 调用实例api
audioInstanceRef.play();