Installations
npm install mazey-taro-utils
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.20.2
NPM Version
8.19.4
Score
49.2
Supply Chain
81.4
Quality
82.6
Maintenance
50
Vulnerability
94.3
License
Contributors
Unable to fetch Contributors
Languages
TypeScript (53.1%)
JavaScript (46.9%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
mazeyqian
Download Statistics
Total Downloads
1,592
Last Day
1
Last Week
14
Last Month
45
Last Year
1,592
GitHub Statistics
MIT License
38 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Jun 10, 2024
Bundle Size
89.38 kB
Minified
27.93 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.2
Package Id
mazey-taro-utils@1.0.2
Unpacked Size
46.54 kB
Size
9.14 kB
File Count
10
NPM Version
8.19.4
Node Version
16.20.2
Published on
Jun 10, 2024
Total Downloads
Cumulative downloads
Total Downloads
1,592
Last Day
-83.3%
1
Compared to previous day
Last Week
-30%
14
Compared to previous week
Last Month
18.4%
45
Compared to previous month
Last Year
0%
1,592
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
50
mazey-taro-utils
Mazey's Taro utils.
Install
Use mazey-taro-utils via npm.
1npm 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
1import { getLoginCodeAsync } from "mazey-taro-utils"; 2 3getLoginCodeAsync() 4 .then((code) => { 5 console.log(`Login code: ${code}`); 6 }) 7 .catch((error) => { 8 console.error(error); 9 });
Usage
quickToast
Displays a toast message.
Parameters:
msg
(string): The message to display in the toast.
Example Usage:
1quickToast('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:
1quickNavigateTo('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:
1quickRedirectTo('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:
1quickScrollTo('#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:
1console.log(`Current environment: ${getEnv()}`);
getCurrentPage
Gets the path of the current page.
Returns: string
Example Usage:
1console.log(`Current page path: ${getCurrentPage()}`);
getAllParams
Gets all parameters of the current page.
Returns: object
Example Usage:
1console.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:
1const userId = getQueryParam('userId'); 2console.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:
1const { width, height, ratio, hwRatio } = getWindowSize(); 2console.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:
1const systemInfo = getSystem(); 2console.log(`System Info: ${systemInfo}`);
getLoginCodeAsync
Calls the interface to get the login credential (code).
Returns: Promise<string>
Example Usage:
1getLoginCodeAsync().then(code => { 2 console.log(`Login code: ${code}`); 3}).catch(err => { 4 console.error(`Failed to get login code: ${err}`); 5});
isMiniProgram
Checks if the current environment is a WeChat Mini Program.
Returns: boolean
Example Usage:
1if (isMiniProgram()) { 2 console.log('Running in a WeChat Mini Program'); 3}
isH5
Determines if the current environment is a web environment (H5).
Returns: boolean
true
if the current environment is H5.false
otherwise.
Example Usage:
1if (isH5()) { 2 console.log('Running in a web environment'); 3}
isWideScreen
Checks if the device has a wide screen.
Returns: boolean
Example Usage:
1if (isWideScreen()) { 2 console.log('Device has a wide screen'); 3}
isIOS
Checks if the system is iOS.
Returns: boolean
Example Usage:
1if (isIOS()) { 2 console.log('Running on iOS'); 3}
isAndroid
Checks if the system is Android.
Returns: boolean
Example Usage:
1if (isAndroid()) { 2 console.log('Running on Android'); 3}
Contributing
Node.js Version: 16.x
Install Dependencies:
1npm i
Development:
1npm run dev
Build:
1npm run build
Document:
1npm run docs
Test:
1npm run test
License
This software is released under the terms of the MIT license.

No vulnerabilities found.

No security vulnerabilities found.