Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
蔡金锋 committed Jan 11, 2020
1 parent 60fd619 commit 6fee3a4
Show file tree
Hide file tree
Showing 31 changed files with 379 additions and 332 deletions.
2 changes: 1 addition & 1 deletion docs/divide.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h1 class="page-title">divide.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
16 changes: 8 additions & 8 deletions docs/formatBankCard.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ <h1 class="page-title">formatBankCard.js</h1>
*
*/
function formatBankCard(bankCardNo = '', {
char = ' ',
length = 4
char = ' ',
length = 4
} = {}) {
const reg = new RegExp(`(\\d{${length}})`, 'g');
const reg = new RegExp(`(\\d{${length}})`, 'g');

const needRemoveLastChar = bankCardNo.length % length === 0;
const needRemoveLastChar = bankCardNo.length % length === 0;

const str = bankCardNo.replace(reg, `$1${char}`);
const str = bankCardNo.replace(reg, `$1${char}`);

return needRemoveLastChar ? str.substr(0, str.length - 1) : str;
return needRemoveLastChar ? str.substr(0, str.length - 1) : str;
}

export default formatBankCard</code></pre>
export default formatBankCard;</code></pre>
</article>
</section>

Expand All @@ -109,7 +109,7 @@ <h1 class="page-title">formatBankCard.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
119 changes: 75 additions & 44 deletions docs/formatMoney.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,64 @@ <h1 class="page-title">formatMoney.js</h1>

<section>
<article>
<pre class="prettyprint source linenums"><code>import { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from './utils/constants';
<pre class="prettyprint source linenums"><code>import { checkBoundary, scientificToNumber } from './utils/math.util';
import isNaN from './utils/type/isNaN';

// 检查数字或数字字符串
function checkNumber(num) {
if (
isNaN(num) ||
(typeof num !== 'number' &amp;&amp; typeof num !== 'string') ||
num === '' ||
typeof Number(num) !== 'number' ||
num === Infinity ||
num === -Infinity
) {
console.error(`${num} invalid parameter.`);
return false;
}

// 数字超限如果不是是字符串,可能有异常
// 如 1111111111111111111111 // => 1.1111111111111111e+21
if (typeof num === 'number') {
checkBoundary(num);
}

return true;
}

// 格式化整数部分
function formatInt(intStr, thousand) {
let txt = '';
intStr = intStr[0] === '+' ? intStr.substr(1) : intStr; // 去掉+符号
const negativeSymbol = Number(intStr) &lt; 0 ? '-' : '';
const reArr = negativeSymbol ? intStr.substr(1).split('').reverse() : intStr.split('').reverse();

const reg = /^[+-]?\d*\.?\d*$/;
for (let i = 0; i &lt; reArr.length; i++) {
txt += reArr[i] + ((i + 1) % 3 === 0 &amp;&amp; i + 1 !== reArr.length ? thousand : '');
}

return negativeSymbol + txt.split('').reverse().join('');
}

// 格式化小数部分,如果使用 toFixed,超大额数字会自动被截断
function formatDec(decStr, precision, decimal){
if(precision === 0){
return '';
}

const zero = 0;
let ret = '';

if(decStr &amp;&amp; Number(decStr) > 0){
let tmpNum = parseFloat('0.' + decStr);
ret = tmpNum.toFixed(precision).substr(2);
}else{
ret = zero.toFixed(precision).substr(2);
}

return decimal + ret;
}

/**
* 格式化金额
Expand All @@ -68,7 +123,7 @@ <h1 class="page-title">formatMoney.js</h1>
* @since 1.1.0
* @param {String | Number} num 需转换金额 (最大:9007199254740991 最小: -9007199254740991)
* @param {Object} [options] - 金额格式化配置
* @param {String | Number} [options.precision] - 保留位数 (最高:10位)
* @param {String | Number} [options.precision=2] - 保留位数 (最高:10位)
* @param {String} [options.symbol] - 货币符号
* @param {String} [options.thousand=,] - 千分位符号
* @param {String} [options.decimal=.] - 小数位符号
Expand Down Expand Up @@ -103,52 +158,28 @@ <h1 class="page-title">formatMoney.js</h1>
* formatMoney(1000.00, { thousand: '&amp;' });
* // => 1,000&amp;00
*/
const formatMoney = (num, { precision, symbol, thousand = ',', decimal = '.' } = {}) => {
if (!reg.test(num) || num === '' || !((typeof num) === 'string' || (typeof num) === 'number')) {
return '';
}
if (+num > MAX_SAFE_INTEGER || +num &lt; MIN_SAFE_INTEGER) {
const formatMoney = (num, { precision = 2, symbol, thousand = ',', decimal = '.' } = {}) => {
// 数字参数不正确,返回空字符串
if (!checkNumber(num)) {
return '';
}
if (!precision || !((typeof precision) === 'string' || (typeof precision) === 'number')) {
precision = 2;
} else {
if (precision &lt;= 0) {
precision = 2;
}

if (precision >= 10) {
precision = 10;
}
}

num = parseFloat((num + '').replace(/[^\d\.-]/g, '')).toFixed(precision) + '';
const reArr = num.split('.')[0].split('').reverse();
let dot = num.split('.')[1];
dot = dot === null ? '' : (typeof decimal === 'string' ? decimal : '.') + dot;
let txt = '';
let res = '';
if (reArr[reArr.length - 1] === '-') {
for (let i = 0; i &lt; reArr.length; i++) {
if (reArr[i] === '-') {
txt += reArr[i] + '';
continue;
}
txt += reArr[i] + ((i + 1) % 3 === 0 &amp;&amp; i + 1 !== reArr.length - 1 ? (typeof thousand === 'string' ? thousand : ',') : '');
}
} else {
for (let i = 0; i &lt; reArr.length; i++) {
txt += reArr[i] + ((i + 1) % 3 === 0 &amp;&amp; i + 1 !== reArr.length ? (typeof thousand === 'string' ? thousand : ',') : '');
}
// 参数规整化
if (typeof precision !== 'number' || isNaN(precision) || precision &lt; 0) {
precision = 2;
} else if (precision > 10) {
precision = 10;
}
symbol = typeof symbol === 'string' ? symbol : '';
thousand = typeof thousand === 'string' ? thousand : ',';
decimal = typeof decimal === 'string' ? decimal : '.';

if (symbol &amp;&amp; (typeof symbol) === 'string') {
res = (symbol + txt.split('').reverse().join('') + dot);
} else {
res = (txt.split('').reverse().join('') + dot);
}
// 转换数字字符串,支持科学记数法
const numStr = scientificToNumber(num) + '';
// 整数和小数部分
const [intStr, decStr] = numStr.split('.');

return res;
return symbol + formatInt(intStr, thousand) + formatDec(decStr, precision, decimal);
};

export default formatMoney;</code></pre>
Expand All @@ -165,7 +196,7 @@ <h1 class="page-title">formatMoney.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
13 changes: 6 additions & 7 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,20 @@ <h2>使用</h2>
<p><code>npm</code> 包的 <code>util-helpers/dist</code> 目录下提供了 <code>util-helpers.js</code> 以及 <code>util-helpers.min.js</code>。你也可以通过 <a href="https://unpkg.com/util-helpers@latest/dist/">UNPKG</a> 进行下载。</p>
<p><em>强烈不推荐使用已构建文件,这样无法按需加载。</em></p>
<h2>示例</h2>
<pre class="prettyprint source lang-javascript"><code>import { isMobile, formatMoney } from 'util-helpers'
<pre class="prettyprint source lang-javascript"><code>import { formatBankCard } from 'util-helpers'

isMobile(&quot;13000000000&quot;) // => true
formatMoney('1000') // => 1,000.00
formatBankCard('6228480402564890018'); // => 6228 4804 0256 4890 018
formatBankCard('6228480402564890018', {char: '-'}); // => 6228-4804-0256-4890-018
</code></pre>
<p><strong>按需引入</strong></p>
<p>如果你使用 <code>babel</code>,下面两种方式都可以只加载用到的组件。</p>
<ul>
<li>方式一:指定模块文件,所有模块都放在 <code>lib</code> 目录下</li>
</ul>
<pre class="prettyprint source lang-javascript"><code>import isMobile from 'util-helpers/lib/isMobile'
import formatMoney from 'util-helpers/lib/formatMoney'
<pre class="prettyprint source lang-javascript"><code>import formatBankCard from 'util-helpers/lib/formatBankCard'
</code></pre>
<ul>
<li>方式二:使用 <a href="https://github.com/ant-design/babel-plugin-import">babel-plugin-import</a> ,在 <code>babel</code> <code>plugin</code> 中添加以下配置</li>
<li>方式二:使用 <a href="https://github.com/ant-design/babel-plugin-import">babel-plugin-import</a> ,在 <code>babel</code> <code>plugin</code> 中添加以下配置</li>
</ul>
<pre class="prettyprint source lang-javascript"><code>['import', {
libraryName: 'util-helpers',
Expand Down Expand Up @@ -177,7 +176,7 @@ <h2>精选第三方工具库</h2>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
3 changes: 2 additions & 1 deletion docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ <h1 class="page-title">index.js</h1>
* @module Math
* @since 3.1.0
* @see {@link https://github.com/camsong/blog/issues/9|JavaScript 浮点数陷阱及解法}
* @see {@link https://2zbuy.csb.app/|JS浮点数计算测试}
*/
export { default as plus } from './plus';
export { default as minus } from './minus';
Expand All @@ -115,7 +116,7 @@ <h1 class="page-title">index.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/isBankCard.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h1 class="page-title">isBankCard.js</h1>
*
*/
function isBankCard(value) {
return reg.test(value);
return reg.test(value);
}

export default isBankCard;</code></pre>
Expand All @@ -97,7 +97,7 @@ <h1 class="page-title">isBankCard.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
46 changes: 23 additions & 23 deletions docs/isChinese.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ <h1 class="page-title">isChinese.js</h1>

const supportRegExpUnicode = RegExp.prototype.hasOwnProperty('unicode');

if(supportRegExpUnicode){
looseChineseRegExp = '(?:'+
chineseDictionary.chineseBasic + '|' +
chineseDictionary.chineseExtend + '|' +
chineseDictionary.chineseExtendA + '|' +
chineseDictionary.chineseExtendB + '|' +
chineseDictionary.chineseExtendC + '|' +
chineseDictionary.chineseExtendD + '|' +
chineseDictionary.chineseExtendE + '|' +
chineseDictionary.chineseExtendF + ')+';
chineseRegExp = '^(?:'+
chineseDictionary.chineseBasic + '|' +
chineseDictionary.chineseExtend + '|' +
chineseDictionary.chineseExtendA + '|' +
chineseDictionary.chineseExtendB + '|' +
chineseDictionary.chineseExtendC + '|' +
chineseDictionary.chineseExtendD + '|' +
chineseDictionary.chineseExtendE + '|' +
chineseDictionary.chineseExtendF + ')+$';
if (supportRegExpUnicode) {
looseChineseRegExp = '(?:' +
chineseDictionary.chineseBasic + '|' +
chineseDictionary.chineseExtend + '|' +
chineseDictionary.chineseExtendA + '|' +
chineseDictionary.chineseExtendB + '|' +
chineseDictionary.chineseExtendC + '|' +
chineseDictionary.chineseExtendD + '|' +
chineseDictionary.chineseExtendE + '|' +
chineseDictionary.chineseExtendF + ')+';
chineseRegExp = '^(?:' +
chineseDictionary.chineseBasic + '|' +
chineseDictionary.chineseExtend + '|' +
chineseDictionary.chineseExtendA + '|' +
chineseDictionary.chineseExtendB + '|' +
chineseDictionary.chineseExtendC + '|' +
chineseDictionary.chineseExtendD + '|' +
chineseDictionary.chineseExtendE + '|' +
chineseDictionary.chineseExtendF + ')+$';
}

/**
Expand Down Expand Up @@ -137,10 +137,10 @@ <h1 class="page-title">isChinese.js</h1>
*
*/
function isChinese(value, {
loose = false
loose = false
} = {}) {
const reg = new RegExp(loose ? looseChineseRegExp : chineseRegExp, supportRegExpUnicode ? 'u' : null);
return reg.test(value);
const reg = new RegExp(loose ? looseChineseRegExp : chineseRegExp, supportRegExpUnicode ? 'u' : null);
return reg.test(value);
}

export default isChinese;</code></pre>
Expand All @@ -157,7 +157,7 @@ <h1 class="page-title">isChinese.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/isEmail.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ <h1 class="page-title">isEmail.js</h1>
*
*/
function isEmail(value) {
return reg.test(value);
return reg.test(value);
}

export default isEmail;</code></pre>
Expand All @@ -94,7 +94,7 @@ <h1 class="page-title">isEmail.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/isIPv4.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h1 class="page-title">isIPv4.js</h1>
*
*/
function isIPv4(value) {
return reg.test(value);
return reg.test(value);
}

export default isIPv4;</code></pre>
Expand All @@ -100,7 +100,7 @@ <h1 class="page-title">isIPv4.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
4 changes: 2 additions & 2 deletions docs/isIPv6.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h1 class="page-title">isIPv6.js</h1>
*
*/
function isIPv6(value) {
return reg.test(value);
return reg.test(value);
}

export default isIPv6;</code></pre>
Expand All @@ -125,7 +125,7 @@ <h1 class="page-title">isIPv6.js</h1>
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Dec 22 2019 19:08:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Sun Jan 12 2020 02:15:44 GMT+0800 (GMT+08:00) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
Expand Down
Loading

0 comments on commit 6fee3a4

Please sign in to comment.