# @codesmiths/mp-utils

> Codesmiths Shanghai helper functions for WeChat Mini Programs

Latest version **1.0.7** (published 2022-11-17) · ISC license · 0 weekly downloads

## Install

```sh
npm install @codesmiths/mp-utils
pnpm add @codesmiths/mp-utils
yarn add @codesmiths/mp-utils
bun add @codesmiths/mp-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-11-17 |
| First published | 2021-09-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Frank Zhu |
| Maintainers | frank657, ashkanyadegari |

## Links

- npm: https://www.npmjs.com/package/@codesmiths/mp-utils
- npm.io page: https://npm.io/package/@codesmiths/mp-utils

## Recent versions

- 1.0.7 (latest) — 2022-11-17
- 1.0.6 — 2022-10-18
- 1.0.5 — 2022-10-18
- 1.0.4 — 2022-10-18
- 1.0.3 — 2021-10-09
- 1.0.2 — 2021-10-09
- 1.0.1 — 2021-09-27
- 1.0.0 — 2021-09-26

## README

# CODESMITHS SHANGHAI WECHAT MINI PROGRAM HELPER FUNCTIONS - USER GUIDE

## Functions Index

1. Mini Program DOM
2. Page selector
3. px & rpx converter
4. Other

## Installation

Using npm:

```bash
npm i @codesmiths/mp-utils
```

### Mini Program DOM

* querySelect(classOrId, component)
* getElementHeight(classOrId, component)

#### Examples

```javascript
import cu from '@codesmiths/mp-utils'; 

cu.querySelect('#componentId', this)
  .then((res) => {
    // if found, res[0] returns wxml element
    console.log(res[0])
  })

cu.querySelect('.className', this)
  .then((res) => {
    // if found, res[0] returns array of wxml elements
    console.log(res[0])
  })
```

### Page & Component selector

* thisPage()
* lastPage()
* allPages()

Useful WeChat Component functions

```javascript
// From parent component (or page) to select a child component
this.selectComponent('#componentId')

// From child component to select parent component (or page)
this.selectOwnerComponent()
```

### px & rpx

* getRpx(px)
* getPx(rpx)
* getSafeArea()

---
_Source: https://npm.io/package/@codesmiths/mp-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
