util-helpers 4.2.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/util-helpers.js +85 -2
- package/dist/util-helpers.min.js +1 -1
- package/dist/util-helpers.min.js.map +1 -1
- package/esm/formatBankCard.js +3 -1
- package/esm/index.js +1 -0
- package/esm/normalizeString.js +31 -0
- package/esm/utils/type/isNil.js +17 -0
- package/lib/formatBankCard.js +5 -1
- package/lib/index.js +8 -0
- package/lib/normalizeString.js +42 -0
- package/lib/utils/type/isNil.js +28 -0
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
- package/types/normalizeString.d.ts +21 -0
- package/types/utils/type/isNil.d.ts +11 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import isNil from './utils/type/isNil';
|
|
2
|
+
import convertToString from './utils/convertToString';
|
|
3
|
+
/**
|
|
4
|
+
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @alias module:Processor.normalizeString
|
|
8
|
+
* @since 4.3.0
|
|
9
|
+
* @param {*} value 待处理的值
|
|
10
|
+
* @returns {string} 规整化的值
|
|
11
|
+
* @example
|
|
12
|
+
* normalizeString(); // ''
|
|
13
|
+
* normalizeString(undefined); // ''
|
|
14
|
+
* normalizeString(void 0); // ''
|
|
15
|
+
* normalizeString(null); // ''
|
|
16
|
+
*
|
|
17
|
+
* normalizeString(true); // 'true'
|
|
18
|
+
* normalizeString(NaN); // 'NaN'
|
|
19
|
+
* normalizeString(1); // '1'
|
|
20
|
+
* normalizeString('a'); // 'a'
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function normalizeString(value) {
|
|
24
|
+
if (isNil(value)) {
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return convertToString(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default normalizeString;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import isUndefined from './isUndefined';
|
|
2
|
+
import isNull from './isNull';
|
|
3
|
+
/**
|
|
4
|
+
* 检查值是否为 undefined 或 null
|
|
5
|
+
*
|
|
6
|
+
* @static
|
|
7
|
+
* @alias module:Type.isNaN
|
|
8
|
+
* @since 4.3.0
|
|
9
|
+
* @param {*} value 检查值
|
|
10
|
+
* @returns {boolean} 是否为 undefined 或 null
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function isNil(value) {
|
|
14
|
+
return isUndefined(value) || isNull(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default isNil;
|
package/lib/formatBankCard.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
|
|
8
|
+
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* 格式化银行卡号
|
|
10
14
|
*
|
|
@@ -46,7 +50,7 @@ function formatBankCard() {
|
|
|
46
50
|
|
|
47
51
|
var reg = new RegExp("(.{".concat(length, "})"), 'g');
|
|
48
52
|
var regChar = new RegExp("".concat(_char), 'g');
|
|
49
|
-
var realValue = bankCardNo.replace(regChar, '');
|
|
53
|
+
var realValue = (0, _normalizeString["default"])(bankCardNo).replace(regChar, '');
|
|
50
54
|
var needRemoveLastChar = realValue.length % length === 0;
|
|
51
55
|
var str = realValue.replace(reg, "$1".concat(_char));
|
|
52
56
|
return needRemoveLastChar ? str.substring(0, str.length - 1) : str;
|
package/lib/index.js
CHANGED
|
@@ -183,6 +183,12 @@ Object.defineProperty(exports, "setDataURLPrefix", {
|
|
|
183
183
|
return _setDataURLPrefix["default"];
|
|
184
184
|
}
|
|
185
185
|
});
|
|
186
|
+
Object.defineProperty(exports, "normalizeString", {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function get() {
|
|
189
|
+
return _normalizeString["default"];
|
|
190
|
+
}
|
|
191
|
+
});
|
|
186
192
|
Object.defineProperty(exports, "plus", {
|
|
187
193
|
enumerable: true,
|
|
188
194
|
get: function get() {
|
|
@@ -286,6 +292,8 @@ var _dataURLToBlob = _interopRequireDefault(require("./dataURLToBlob"));
|
|
|
286
292
|
|
|
287
293
|
var _setDataURLPrefix = _interopRequireDefault(require("./setDataURLPrefix"));
|
|
288
294
|
|
|
295
|
+
var _normalizeString = _interopRequireDefault(require("./normalizeString"));
|
|
296
|
+
|
|
289
297
|
var _plus = _interopRequireDefault(require("./plus"));
|
|
290
298
|
|
|
291
299
|
var _minus = _interopRequireDefault(require("./minus"));
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _isNil = _interopRequireDefault(require("./utils/type/isNil"));
|
|
9
|
+
|
|
10
|
+
var _convertToString = _interopRequireDefault(require("./utils/convertToString"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
16
|
+
*
|
|
17
|
+
* @static
|
|
18
|
+
* @alias module:Processor.normalizeString
|
|
19
|
+
* @since 4.3.0
|
|
20
|
+
* @param {*} value 待处理的值
|
|
21
|
+
* @returns {string} 规整化的值
|
|
22
|
+
* @example
|
|
23
|
+
* normalizeString(); // ''
|
|
24
|
+
* normalizeString(undefined); // ''
|
|
25
|
+
* normalizeString(void 0); // ''
|
|
26
|
+
* normalizeString(null); // ''
|
|
27
|
+
*
|
|
28
|
+
* normalizeString(true); // 'true'
|
|
29
|
+
* normalizeString(NaN); // 'NaN'
|
|
30
|
+
* normalizeString(1); // '1'
|
|
31
|
+
* normalizeString('a'); // 'a'
|
|
32
|
+
*/
|
|
33
|
+
function normalizeString(value) {
|
|
34
|
+
if ((0, _isNil["default"])(value)) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return (0, _convertToString["default"])(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
var _default = normalizeString;
|
|
42
|
+
exports["default"] = _default;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
|
|
8
|
+
var _isUndefined = _interopRequireDefault(require("./isUndefined"));
|
|
9
|
+
|
|
10
|
+
var _isNull = _interopRequireDefault(require("./isNull"));
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 检查值是否为 undefined 或 null
|
|
16
|
+
*
|
|
17
|
+
* @static
|
|
18
|
+
* @alias module:Type.isNaN
|
|
19
|
+
* @since 4.3.0
|
|
20
|
+
* @param {*} value 检查值
|
|
21
|
+
* @returns {boolean} 是否为 undefined 或 null
|
|
22
|
+
*/
|
|
23
|
+
function isNil(value) {
|
|
24
|
+
return (0, _isUndefined["default"])(value) || (0, _isNull["default"])(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var _default = isNil;
|
|
28
|
+
exports["default"] = _default;
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export { default as parseIdCard } from "./parseIdCard";
|
|
|
28
28
|
export { default as blobToDataURL } from "./blobToDataURL";
|
|
29
29
|
export { default as dataURLToBlob } from "./dataURLToBlob";
|
|
30
30
|
export { default as setDataURLPrefix } from "./setDataURLPrefix";
|
|
31
|
+
export { default as normalizeString } from "./normalizeString";
|
|
31
32
|
export { default as plus } from "./plus";
|
|
32
33
|
export { default as minus } from "./minus";
|
|
33
34
|
export { default as times } from "./times";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default normalizeString;
|
|
2
|
+
/**
|
|
3
|
+
* 规整化字符串。如果值为 undefined 或 null 将转为空字符串,如果值不是字符串类型将转为字符串。
|
|
4
|
+
*
|
|
5
|
+
* @static
|
|
6
|
+
* @alias module:Processor.normalizeString
|
|
7
|
+
* @since 4.3.0
|
|
8
|
+
* @param {*} value 待处理的值
|
|
9
|
+
* @returns {string} 规整化的值
|
|
10
|
+
* @example
|
|
11
|
+
* normalizeString(); // ''
|
|
12
|
+
* normalizeString(undefined); // ''
|
|
13
|
+
* normalizeString(void 0); // ''
|
|
14
|
+
* normalizeString(null); // ''
|
|
15
|
+
*
|
|
16
|
+
* normalizeString(true); // 'true'
|
|
17
|
+
* normalizeString(NaN); // 'NaN'
|
|
18
|
+
* normalizeString(1); // '1'
|
|
19
|
+
* normalizeString('a'); // 'a'
|
|
20
|
+
*/
|
|
21
|
+
declare function normalizeString(value: any): string;
|