Code Monkey home page Code Monkey logo

react-native-adaptive-utils's Introduction

English | 简体中文

react-native-adaptive-utils

Install

npm install react-native-adaptive-utils

Import

import { YourNeed } from "react-native-adaptive-utils";

Demo

Such as, import debounce function.

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

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

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

let randomStr = randomString(16);

Above generate '16' length random number.

1.4 integerDecimalsFormat

The integer is displayed in thousands of fractions

Demo

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

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

allSettled(['promiseA','promiseB',...])

Returns an array containing the success or failure returns of all Promises

2 validator

2.1 validPhone

Verify phone no.

Demo

let checkPhoneFlag = validPhone(12);

2.2 validEmail

Verify E-mail.

Demo

let checkEmailFlag = validEmail(12);

2.3 validCardNo

Verify Chinese card no.

Demo

let checkCardNoFlag = validCardNo(12);

2.4 strLimit

Character length limit verification

Demo

let text = limitStr(str, length);

2.5 isImg

Image type verification

Demo

let isPicture = isImg(target);

3 Resolution

3.1 dynamicFontSize

Get font size base on width.

Demo

let fontSize = dynamicFontSize(12);

Suggest Usage:

const styles = StyleSheet.create({
  container: {
    fontSize: dynamicFontSize(12)
  }
});

3.2 isIphoneX

Check whether it is iphonex

Demo

isIphoneX() ? "..." : "...";
const styles = StyleSheet.create({
  container: {
    height: isIphoneX() ? 15 : 20;
  }
});
### 3.3 getTitleBarHeight

Gets the title bar height based on the current screen.

#### Demo
let height = getTitleBarHeight();
const styles = StyleSheet.create({
  container: {
    height: getTitleBarHeight();
  }
});

Todo List

  • Get image type.
  • Determines the upper limit of input characters in the text box.
  • Generate UUID.
  • RN-allSettled

Todo Prepare

  • Network tool.

react-native-adaptive-utils's People

Contributors

a1daxiang avatar jinglj0512 avatar lj88888 avatar supervons avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.