Skip to content

Commit

Permalink
新增 splitThousand 千分位分割方法
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Mar 2, 2021
1 parent 2786162 commit dd2d298
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 8 deletions.
16 changes: 16 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ name=exMall-detail-goodsInfoId&amp;params[goodsInfoId]=8866 转成 name</em>exMa
<dt><a href="#setSession">setSession(name, value, seconds)</a></dt>
<dd><p>写sessionStorage</p>
</dd>
<dt><a href="#splitThousand">splitThousand([String, Number])</a> ⇒ <code>String</code></dt>
<dd><p>数字千分位分割</p>
</dd>
<dt><a href="#stopBubble">stopBubble(e)</a> ⇒ <code>Boolean</code></dt>
<dd><p>阻止冒泡</p>
</dd>
Expand Down Expand Up @@ -1032,6 +1035,19 @@ setCookie 写入 cookie 的方法
| value | <code>\*</code> | 设置要存储的值,可以是对象或字符串 |
| seconds | <code>Number</code> | 有效时间 |

<a name="splitThousand"></a>

## splitThousand([String, Number]) ⇒ <code>String</code>

数字千分位分割

**Kind**: global function
**Returns**: <code>String</code> - 分割后的字符串

| Param | Description |
| ---------------- | ----------- |
| [String, Number] | value 数字 |

<a name="stopBubble"></a>

## stopBubble(e) ⇒ <code>Boolean</code>
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2021.03.02 v1.0.8 更新日志

1. 新增 splitThousand 千分位分割方法

# 2021.03.01 v1.0.7 更新日志

1. 修复 nextIndex 的 bug
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ module.exports = {
cleanData, // 清洗数据
download, // 文件下载
searchTreeObject, // 对象查找
openUrl // 新标签页打开链接(浏览器不能解析的文件跳转下载)
openUrl, // 新标签页打开链接(浏览器不能解析的文件跳转下载)
splitThousand, // 千分位分割方法
}
```

Expand Down Expand Up @@ -386,6 +387,9 @@ name=exMall-detail-goodsInfoId&amp;params[goodsInfoId]=8866 转成 name</em>exMa
<dt><a href="#setSession">setSession(name, value, seconds)</a></dt>
<dd><p>写sessionStorage</p>
</dd>
<dt><a href="#splitThousand">splitThousand([String, Number])</a> ⇒ <code>String</code></dt>
<dd><p>数字千分位分割</p>
</dd>
<dt><a href="#stopBubble">stopBubble(e)</a> ⇒ <code>Boolean</code></dt>
<dd><p>阻止冒泡</p>
</dd>
Expand Down Expand Up @@ -1226,6 +1230,19 @@ setCookie 写入 cookie 的方法
| value | <code>\*</code> | 设置要存储的值,可以是对象或字符串 |
| seconds | <code>Number</code> | 有效时间 |

<a name="splitThousand"></a>

## splitThousand([String, Number]) ⇒ <code>String</code>

数字千分位分割

**Kind**: global function
**Returns**: <code>String</code> - 分割后的字符串

| Param | Description |
| ---------------- | ----------- |
| [String, Number] | value 数字 |

<a name="stopBubble"></a>

## stopBubble(e) ⇒ <code>Boolean</code>
Expand Down
17 changes: 15 additions & 2 deletions lib/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ var debounce = function debounce(fn, delay, immediate) {
};

/**
* 阻止冒泡
* @description 阻止冒泡
* @param {Object} e dom的event对象
* @returns {Boolean}
*/
Expand Down Expand Up @@ -1844,4 +1844,17 @@ function openUrl(url) {
document.body.removeChild(dom);
}

export { addEvent, camel2Dash, cleanData, clearAttr, clearBr, clearHtml, clearHtmlExpSN, clearHtmlN, clearHtmlNS, clearHtmlTag, client, cutCHSString, dash2Camel, deWxJumpLink, deWxJumpLinkOld, debounce, decodeBase64, decodeUtf8, delCache, delCookie, delSession, delay, download, enWxJumpLink, enWxJumpLinkOld, encodeBase64, encodeUtf8, extend, fixNumber, formatTime, formatTimeStr, getAppVersion, getCHSLength, getCache, getCookie, getDirParam, getFileType, getIsAppVersionLastest, getNumber, getOsVersion, getParameter, getRandomNum, getRandomStr, getRandomStrWidthSpecialChar, getScrollPosition, getSession, getType, getUrlParam, getWindowSize, imgAdapt, imgChoose, isArray, isDigitals, isExitsFunction, isExitsVariable, nextIndex, openUrl, pattern$1 as pattern, removeEvent, searchTreeObject, setCache, setCookie, setSession, stopBubble, stopDefault, textareaInsertText, textareaMoveToEnd, throttle, trim, upperFirst };
/**
* splitThousand
* @description 数字千分位分割
* @param [String, Number] value 数字
* @returns {String} 分割后的字符串
*/
function splitThousand(val) {
if (!val) return val === 0 || val === '0' ? 0 : '';
val = val.toString();
if (val.split('.').length == 1) return (val || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
return val.split('.')[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$&,') + '.' + val.split('.')[1];
}

export { addEvent, camel2Dash, cleanData, clearAttr, clearBr, clearHtml, clearHtmlExpSN, clearHtmlN, clearHtmlNS, clearHtmlTag, client, cutCHSString, dash2Camel, deWxJumpLink, deWxJumpLinkOld, debounce, decodeBase64, decodeUtf8, delCache, delCookie, delSession, delay, download, enWxJumpLink, enWxJumpLinkOld, encodeBase64, encodeUtf8, extend, fixNumber, formatTime, formatTimeStr, getAppVersion, getCHSLength, getCache, getCookie, getDirParam, getFileType, getIsAppVersionLastest, getNumber, getOsVersion, getParameter, getRandomNum, getRandomStr, getRandomStrWidthSpecialChar, getScrollPosition, getSession, getType, getUrlParam, getWindowSize, imgAdapt, imgChoose, isArray, isDigitals, isExitsFunction, isExitsVariable, nextIndex, openUrl, pattern$1 as pattern, removeEvent, searchTreeObject, setCache, setCookie, setSession, splitThousand, stopBubble, stopDefault, textareaInsertText, textareaMoveToEnd, throttle, trim, upperFirst };
2 changes: 2 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ var cleanData = require('./cleanData.js');
var download = require('./download.js');
var searchTreeObject = require('./searchTreeObject.js');
var openUrl = require('./openUrl.js');
var splitThousand = require('./splitThousand.js');



Expand Down Expand Up @@ -145,3 +146,4 @@ exports.cleanData = cleanData;
exports.download = download;
exports.searchTreeObject = searchTreeObject;
exports.openUrl = openUrl;
exports.splitThousand = splitThousand;
2 changes: 1 addition & 1 deletion lib/index.umd.js

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions lib/splitThousand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

require('core-js/modules/es.date.to-string.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/es.regexp.exec.js');
require('core-js/modules/es.regexp.to-string.js');
require('core-js/modules/es.string.replace.js');
require('core-js/modules/es.string.split.js');

/**
* splitThousand
* @description 数字千分位分割
* @param [String, Number] value 数字
* @returns {String} 分割后的字符串
*/
function splitThousand(val) {
if (!val) return val === 0 || val === '0' ? 0 : '';
val = val.toString();
if (val.split('.').length == 1) return (val || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
return val.split('.')[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$&,') + '.' + val.split('.')[1];
}

module.exports = splitThousand;
2 changes: 1 addition & 1 deletion lib/stopBubble.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

/**
* 阻止冒泡
* @description 阻止冒泡
* @param {Object} e dom的event对象
* @returns {Boolean}
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-cool",
"version": "1.0.7",
"version": "1.0.8",
"description": "一些常用的JS方法,支持按需引入",
"main": "lib/index.js",
"files": [
Expand Down
3 changes: 3 additions & 0 deletions script/docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!bin/sh

cd -
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import cleanData from './cleanData' // 清洗数据
import download from './download' // 文件下载
import searchTreeObject from './searchTreeObject' // 对象查找
import openUrl from './openUrl' // 新标签页打开链接(浏览器不能解析的文件跳转下载)
import splitThousand from './splitThousand' // 千分位分割方法

export {
//
Expand Down Expand Up @@ -157,5 +158,6 @@ export {
cleanData,
download,
searchTreeObject,
openUrl
openUrl,
splitThousand
}
14 changes: 14 additions & 0 deletions src/splitThousand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* splitThousand
* @description 数字千分位分割
* @param [String, Number] value 数字
* @returns {String} 分割后的字符串
*/
function splitThousand(val) {
if (!val) return val === 0 || val === '0' ? 0 : ''
val = val.toString()
if (val.split('.').length == 1) return (val || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
return val.split('.')[0].replace(/(\d)(?=(?:\d{3})+$)/g, '$&,') + '.' + val.split('.')[1]
}

export default splitThousand
2 changes: 1 addition & 1 deletion src/stopBubble.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 阻止冒泡
* @description 阻止冒泡
* @param {Object} e dom的event对象
* @returns {Boolean}
*/
Expand Down

0 comments on commit dd2d298

Please sign in to comment.