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

mazey-taro-utils

v1.0.2

Published

Mazey's Taro utils.

Downloads

12

Readme

mazey-taro-utils

npm version l

Mazey's Taro utils.

Install

Use mazey-taro-utils via npm.

npm install mazey-taro-utils --save

Of course, you can also download this file and serve it yourself. The file locates at the lib/mazey-taro-utils.min.js.

Quick Start

import { getLoginCodeAsync } from "mazey-taro-utils";

getLoginCodeAsync()
  .then((code) => {
    console.log(`Login code: ${code}`);
  })
  .catch((error) => {
    console.error(error);
  });

Usage

quickToast

Displays a toast message.

Parameters:

  • msg (string): The message to display in the toast.

Example Usage:

quickToast('Hello, world!');

quickNavigateTo

Navigates to a specified page.

Parameters:

  • page (string): The page to navigate to. This should be the name of the directory under /pages without the /index part.
  • params (object, optional): Query parameters to include in the URL.

Example Usage:

quickNavigateTo('home', { params: { userId: 123 } });

quickRedirectTo

Redirects to a specified page, without keeping the current page in the navigation history.

Parameters:

  • page (string): The page to redirect to. This should be the name of the directory under /pages without the /index part.
  • params (object, optional): Query parameters to include in the URL.

Example Usage:

quickRedirectTo('home', { params: { userId: 123 } });

quickScrollTo

Quickly scrolls to a specified element on the page.

Parameters:

  • selector (string): The selector of the element to scroll to.
  • duration (number, optional): The duration of the scroll animation in milliseconds. Default is 300ms.

Example Usage:

quickScrollTo('#elementId', 500);

getEnv

Gets the current environment the application is running in.

Returns: string

  • The name of the current environment (e.g., 'h5', 'weapp', etc.).

Example Usage:

console.log(`Current environment: ${getEnv()}`);

getCurrentPage

Gets the path of the current page.

Returns: string

Example Usage:

console.log(`Current page path: ${getCurrentPage()}`);

getAllParams

Gets all parameters of the current page.

Returns: object

Example Usage:

console.log(`Current page params: ${JSON.stringify(getAllParams())}`);

getQueryParam

Gets the value of a query parameter from the current path.

Parameters:

  • name (string): The name of the query parameter.

Returns: string

Example Usage:

const userId = getQueryParam('userId');
console.log(`User ID: ${userId}`);

getWindowSize

Gets the size of the current window.

Returns: object

  • width (number): The width of the window.
  • height (number): The height of the window.
  • ratio (number): The width-to-height ratio.
  • hwRatio (number): The height-to-width ratio.

Example Usage:

const { width, height, ratio, hwRatio } = getWindowSize();
console.log(`Window size - Width: ${width}, Height: ${height}, Ratio: ${ratio}, HW Ratio: ${hwRatio}`);

getSystem

Gets the current system information, such as "iOS 14.4".

Returns: string

Example Usage:

const systemInfo = getSystem();
console.log(`System Info: ${systemInfo}`);

getLoginCodeAsync

Calls the interface to get the login credential (code).

Returns: Promise<string>

Example Usage:

getLoginCodeAsync().then(code => {
  console.log(`Login code: ${code}`);
}).catch(err => {
  console.error(`Failed to get login code: ${err}`);
});

isMiniProgram

Checks if the current environment is a WeChat Mini Program.

Returns: boolean

Example Usage:

if (isMiniProgram()) {
  console.log('Running in a WeChat Mini Program');
}

isH5

Determines if the current environment is a web environment (H5).

Returns: boolean

  • true if the current environment is H5.
  • false otherwise.

Example Usage:

if (isH5()) {
  console.log('Running in a web environment');
}

isWideScreen

Checks if the device has a wide screen.

Returns: boolean

Example Usage:

if (isWideScreen()) {
  console.log('Device has a wide screen');
}

isIOS

Checks if the system is iOS.

Returns: boolean

Example Usage:

if (isIOS()) {
  console.log('Running on iOS');
}

isAndroid

Checks if the system is Android.

Returns: boolean

Example Usage:

if (isAndroid()) {
  console.log('Running on Android');
}

Contributing

Node.js Version: 16.x

Install Dependencies:

npm i

Development:

npm run dev

Build:

npm run build

Document:

npm run docs

Test:

npm run test

License

This software is released under the terms of the MIT license.