https://github.com/supervons/react-native-adaptive-utils
React-Native adaptive utils, contains various adaptation function.
https://github.com/supervons/react-native-adaptive-utils
Last synced: about 2 months ago
JSON representation
React-Native adaptive utils, contains various adaptation function.
- Host: GitHub
- URL: https://github.com/supervons/react-native-adaptive-utils
- Owner: supervons
- Created: 2022-02-09T01:34:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-03-07T01:37:06.000Z (7 months ago)
- Last Synced: 2025-03-07T02:30:32.997Z (7 months ago)
- Language: JavaScript
- Size: 50.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
English | [简体中文](./README_CN.md)
# react-native-adaptive-utils
# Install
```shell
npm install react-native-adaptive-utils
```# Import
```javascript
import { YourNeed } from "react-native-adaptive-utils";
```#### Demo
Such as, import debounce function.
```javascript
import { debounce } from "react-native-adaptive-utils";
```# API
## 1 Improve tools.
### 1.1 debounce
The appointed time(default `500ms` ),trigger many times that execute last once.
#### Demo
```javascript
debounce(() => {
console.log(1);
}, 500);
```Means if trigger many times in `500ms`, execute last once.
### 1.2 throttle
The appointed time(default `500ms` ), ignored triggers after first once executed.
#### Demo
```javascript
throttle(() => {
console.log(1);
}, 500);
```Means execute first once, then if trigger many times in 500ms, ignored.
### 1.3 randomString
Generates a random string of a specified length (32 bits by default).
#### Demo
```javascript
let randomStr = randomString(16);
```Above generate '16' length random number.
### 1.4 integerDecimalsFormat
The integer is displayed in thousands of fractions
#### Demo
```javascript
let thousandsNum = integerDecimalsFormat(-456123131.12301);
```The above num format is' -456,123,131.12301 '
### 1.5 computeSomeCharsCount
Counts the number of occurrences of a specified character or string in a string
#### Demo
```javascript
let count = computeSomeCharsCount("ad", "adsfdasf");
```The count above is the number of occurrences of 'AD' in 'adsfdasf'
### 1.5 allSettled
Encapsulated in the rn Promise.all () simulation Promise.allSettled ()
#### Demo
```javascript
allSettled(['promiseA','promiseB',...])
```Returns an array containing the success or failure returns of all Promises
## 2 validator
### 2.1 validPhone
Verify phone no.
#### Demo
```javascript
let checkPhoneFlag = validPhone(12);
```### 2.2 validEmail
Verify E-mail.
#### Demo
```javascript
let checkEmailFlag = validEmail(12);
```### 2.3 validCardNo
Verify Chinese card no.
#### Demo
```javascript
let checkCardNoFlag = validCardNo(12);
```### 2.4 strLimit
Character length limit verification
#### Demo
```javascript
let text = limitStr(str, length);
```### 2.5 isImg
Image type verification
#### Demo
```javascript
let isPicture = isImg(target);
```## 3 Resolution
### 3.1 dynamicFontSize
Get font size base on width.
#### Demo
```javascript
let fontSize = dynamicFontSize(12);
```Suggest Usage:
```javascript
const styles = StyleSheet.create({
container: {
fontSize: dynamicFontSize(12)
}
});
```### 3.2 isIphoneX
Check whether it is iphonex
#### Demo
```javascript
isIphoneX() ? "..." : "...";
``````javascript
const styles = StyleSheet.create({
container: {
height: isIphoneX() ? 15 : 20;
}
});
### 3.3 getTitleBarHeightGets the title bar height based on the current screen.
#### Demo
```
```javascript
let height = getTitleBarHeight();
``````javascript
const styles = StyleSheet.create({
container: {
height: getTitleBarHeight();
}
});
```# Todo List
- [x] Get image type.
- [x] Determines the upper limit of input characters in the text box.
- [x] Generate UUID.
- [x] RN-allSettled# Todo Prepare
- [ ] Network tool.