0.0.8 • Published 1 year ago

bigscreen-utils v0.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

latest tag npm version airbnb install size

bigscreen-utils

It provides some of the functions used by bigscreens, includes numbers, strings, arrays, and objects.It may allow you to avoid resealing related methods in bigscreen page development.

Install

$ npm install bigscreen-utils

Usage

1、import引入

// 1、全部引入
import { parseFloatByFixed } from "bigscreen-utils";

// 2、只引入部分
import { parseFloatByFixed } from "bigscreen-utils/src/util/numberUtil";

const floatValue = parseFloatByFixed(10000.888, 2)
console.log(floatValue); // 10000.89

2、script标签引入

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<script type="text/javascript" src="dist/arrayutil.min.js"></script>
	<script type="text/javascript" src="dist/numberUtil.min.js"></script>
	<script type="text/javascript" src="dist/stringUtil.min.js"></script>
	<script type="text/javascript" src="dist/objectUtil.min.js"></script>
	<script type="text/javascript">
        const floatValue = parseFloatByFixed(10000.888, 2)
		console.log(floatValue); // 10000.89
	</script>
</head>
<body>
    <div>bigscreen utils test</div>
</body>
</html>

API

1、数组相关 arrayUtil.js

功能方法名
数组等分equallyDivide(array, subGroupLength)

1.1 equallyDivide

参数说明
array原数组
subGroupLength数组等分长度

2、数值相关 numberUtil.js

功能方法名返回值类型
将字符串转换成整型parseInt(str)number
将字符串转换成浮点数parseFloat(str)number
返回保留小数点后指定位数的字符串parseFloatByFixed(str, fixed)string
返回保留小数点后指定位数的值parseFloatValueByFixed(str, fixed, defaultValue)number
加千分位分隔符toLocaleString(str)string
返回保留小数点后一位的字符串parseFloatByFixedOneDecimalPlace(str)string
返回保留小数点后两位的字符串parseFloatByFixedTwoDecimalPlace(str)string
返回百分比数值字符串getPercentNumber(str, fixed)string
返回百分比数值字符串(默认值)getPercentNumberByDefaultValue(str, fixed, defaultValue)string
返回百分比数值字符串(默认字符串)getPercentNumberByDefaultStr(str, fixed, defaultStr)string
返回百分比数值getPercentNumberValue(str, fixed)number
返回百分比数值(默认值)getPercentNumberValueByDefaultValue(str, fixed, defaultValue)number
返回百分比数值(默认字符串)getPercentNumberValueByDefaultStr(str, fixed, defaultStr)number

2.1 parseInt

参数说明
str字符串

2.2 parseFloat

参数说明
str字符串

2.3 parseFloatByFixed

参数说明
str字符串
fixed小数点后保留位数

2.4 parseFloatValueByFixed

2.5 toLocaleString

参数说明
str字符串

2.6 parseFloatByFixedOneDecimalPlace

参数说明
str字符串

2.7 parseFloatByFixedTwoDecimalPlace

参数说明
str字符串

2.8 getPercentNumber

参数说明
str字符串
fixed小数点后保留位数

2.9 getPercentNumberByDefaultValue

参数说明
str字符串
fixed小数点后保留位数
defaultValue默认值

2.10 getPercentNumberByDefaultStr

参数说明
str字符串
fixed小数点后保留位数
defaultStr默认字符串

2.11 getPercentNumberValue

参数说明
str字符串
fixed小数点后保留位数

2.12 getPercentNumberValueByDefaultValue

参数说明
str字符串
fixed小数点后保留位数
fixed默认值

2.13 getPercentNumberValueByDefaultStr

参数说明
str字符串
fixed小数点后保留位数
fixed默认字符串

3、对象相关 objectUtil.js

功能方法名
判断值是否是null或undefinedisNullOrUndefined(value)
判断值是否是null或undefined或空字符串isNullOrUndefinedOrEmptyString(value)

3.1 isNullOrUndefined

参数说明
value

3.2 isNullOrUndefinedOrEmptyString

参数说明
value

4、字符串相关 stringUtil.js

功能方法名
字符串前面补0addLeftZero(num, length)
判断是否是JSON字符串isJSONStr(str)

4.1 addLeftZero

参数说明
num数值
length字符串长度

4.2 isJSONStr

参数说明
str字符串

5、日期相关 timeUtil.js

功能方法名
传入开始时间、结束时间,返回一个时间数组getTimeArray(startTimeStr, endTimeStr, type, interval, formatStr)
传入开始时间、结束时间返回一个时间数组,时间间隔为1小时getTimeArrayByHours(startTimeStr, endTimeStr)

5.1 getTimeArray

参数说明
startTimeStr开始时间字符串
endTimeStr结束时间字符串
type类型
interval时间间隔
formatStr时间格式

5.2 getTimeArrayByHours

参数说明
startTimeStr开始时间字符串
endTimeStr结束时间字符串

6、金融相关 financeUtil.js

功能方法名
将传入的值除以1万之后返回getValueByTenThousand(oldValue)
将传入的值除以1万之后返回保留一位小数的字符串getStrByTenThousandFixedOneDecimalPlace(oldValue)
将传入的值除以1万之后返回保留两位小数的字符串getStrByTenThousandFixedTwoDecimalPlace(oldValue)
将传入的值除以1万之后返回保留一位小数的值getValueByTenThousandFixedOneDecimalPlace(oldValue, ignoreZero)
将传入的值除以1万之后返回保留两位小数的值getValueByTenThousandFixedTwoDecimalPlace(oldValue, ignoreZero)
将传入的值除以1万之后返回保留一位小数的值,0不做处理getValueByTenThousandFixedOneIgnoreZero(oldValue)
将传入的值除以1万之后返回保留两位小数的值,0不做处理getValueByTenThousandFixedTwoIgnoreZero(oldValue)
将传入的值除以1亿之后返回getValueByHundredMillion(oldValue)
将传入的值除以1亿之后返回保留一位小数的字符串getStrByHundredMillionFixedOneDecimalPlace(oldValue)
将传入的值除以1亿之后返回保留两位小数的字符串getStrByHundredMillionFixedTwoDecimalPlace(oldValue)
将传入的值除以1亿之后返回保留一位小数的值getValueByHundredMillionFixedOneDecimalPlace(oldValue, ignoreZero)
将传入的值除以1亿之后返回保留两位小数的值getValueByHundredMillionFixedTwoDecimalPlace(oldValue, ignoreZero)
将传入的值除以1亿之后返回保留一位小数的值,0不做处理getValueByHundredMillionFixedOneIgnoreZero(oldValue)
将传入的值除以1亿之后返回保留两位小数的值,0不做处理getValueByHundredMillionFixedTwoIgnoreZero(oldValue)

6.1 getValueByTenThousand

参数说明
oldValue

6.2 getStrByTenThousandFixedOneDecimalPlace

参数说明
oldValue

6.3 getStrByTenThousandFixedTwoDecimalPlace

参数说明
oldValue

6.4 getValueByTenThousandFixedOneDecimalPlace

参数说明
oldValue
ignoreZero是否忽略0

6.5 getValueByTenThousandFixedTwoDecimalPlace

参数说明
oldValue
ignoreZero是否忽略0

6.6 getValueByTenThousandFixedOneIgnoreZero

参数说明
oldValue

6.7 getValueByTenThousandFixedTwoIgnoreZero

参数说明
oldValue

6.8 getValueByHundredMillion

参数说明
oldValue

6.9 getStrByHundredMillionFixedOneDecimalPlace

参数说明
oldValue

6.10 getStrByHundredMillionFixedTwoDecimalPlace

参数说明
oldValue

6.11 getValueByHundredMillionFixedOneDecimalPlace

参数说明
oldValue
ignoreZero是否忽略0

6.12 getValueByHundredMillionFixedTwoDecimalPlace

参数说明
oldValue
ignoreZero是否忽略0

6.13 getValueByHundredMillionFixedOneIgnoreZero

参数说明
oldValue

6.14 getValueByHundredMillionFixedTwoIgnoreZero

参数说明
oldValue
0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2-beta

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago