@haluo/util 0.0.11 → 1.0.2

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.
Files changed (45) hide show
  1. package/package.json +2 -1
  2. package/.babelrc +0 -21
  3. package/.eslintrc.js +0 -216
  4. package/__tests__/unit/date/date.spec.js +0 -14
  5. package/__tests__/unit/jest.conf.js +0 -25
  6. package/__tests__/unit/specs/date.test.js +0 -11
  7. package/coverage/clover.xml +0 -78
  8. package/coverage/coverage-final.json +0 -2
  9. package/coverage/lcov-report/base.css +0 -224
  10. package/coverage/lcov-report/block-navigation.js +0 -79
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +0 -111
  13. package/coverage/lcov-report/index.ts.html +0 -668
  14. package/coverage/lcov-report/prettify.css +0 -1
  15. package/coverage/lcov-report/prettify.js +0 -2
  16. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  17. package/coverage/lcov-report/sorter.js +0 -170
  18. package/coverage/lcov.info +0 -170
  19. package/dist/index.js +0 -36
  20. package/dist/modules/cookie/index.js +0 -51
  21. package/dist/modules/date/index.js +0 -192
  22. package/dist/modules/dom/index.js +0 -62
  23. package/dist/modules/filter/index.js +0 -57
  24. package/dist/modules/format/index.js +0 -21
  25. package/dist/modules/match/index.js +0 -31
  26. package/dist/modules/number/index.js +0 -102
  27. package/dist/modules/sentry/index.js +0 -81
  28. package/dist/modules/tools/index.js +0 -393
  29. package/global.d.ts +0 -0
  30. package/publish.sh +0 -11
  31. package/specification/CSS.md +0 -25
  32. package/specification/JS.md +0 -9
  33. package/specification/VUE.md +0 -1
  34. package/src/consts/httpCode.js +0 -10
  35. package/src/index.ts +0 -54
  36. package/src/modules/cookie/index.ts +0 -63
  37. package/src/modules/date/index.ts +0 -196
  38. package/src/modules/dom/index.ts +0 -78
  39. package/src/modules/filter/index.ts +0 -57
  40. package/src/modules/format/index.ts +0 -19
  41. package/src/modules/match/index.ts +0 -31
  42. package/src/modules/number/index.ts +0 -108
  43. package/src/modules/sentry/index.ts +0 -82
  44. package/src/modules/tools/index.ts +0 -427
  45. package/tsconfig.json +0 -34
@@ -1,62 +0,0 @@
1
- /**
2
- * @file Cookie
3
- * @Author: wanghui
4
- * @createBy: @2021.08.17
5
- */
6
- 'use strict';
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- var DomClass = /** @class */ (function () {
9
- function DomClass() {
10
- }
11
- /**
12
- * 创建一个子元素并添加至父节点
13
- * @param {Object} { name = 'div', innerHTML = '', style = {}, parent, }
14
- * @return {String}
15
- */
16
- DomClass.prototype.createElement = function (_a) {
17
- var _b = _a.name, name = _b === void 0 ? 'div' : _b, _c = _a.innerHTML, innerHTML = _c === void 0 ? '' : _c, _d = _a.style, style = _d === void 0 ? {} : _d, parent = _a.parent;
18
- if (!(window && window.document)) {
19
- return new Error('仅支持浏览器');
20
- }
21
- var element = document.createElement(name);
22
- element.innerHTML = innerHTML;
23
- Object.keys(style).map(function (_) { return element.style[_] = style[_]; });
24
- if (parent) {
25
- var body = document.querySelector(parent);
26
- body && body.append(element);
27
- }
28
- return element;
29
- };
30
- /**
31
- * 获取文本中的url并用a标签包裹
32
- * @param {Object} ICookie
33
- */
34
- DomClass.prototype.wrapperA = function (text) {
35
- if (!(window && window.document)) {
36
- return new Error('仅支持浏览器');
37
- }
38
- return text.replace(/((https|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|])/g, '<a href="$1">$1</a>');
39
- };
40
- /**
41
- * 对象转化为formdata
42
- * getFormData({a: 1, b: 2})
43
- * @param {Object} object
44
- */
45
- DomClass.prototype.getFormData = function (object) {
46
- var formData = new FormData();
47
- Object.keys(object).forEach(function (key) {
48
- var value = object[key];
49
- if (Array.isArray(value)) {
50
- value.forEach(function (subValue, i) {
51
- return formData.append(key + ("[" + i + "]"), subValue);
52
- });
53
- }
54
- else {
55
- formData.append(key, object[key]);
56
- }
57
- });
58
- return formData;
59
- };
60
- return DomClass;
61
- }());
62
- module.exports = new DomClass();
@@ -1,57 +0,0 @@
1
- /**
2
- * @file 过滤器
3
- * @Author: wanghui
4
- * @createBy: @2020.05.28
5
- */
6
- /**
7
- * 示例:注入所有过滤器
8
- * import { filter as filters } from '@haluo/util'
9
- * Object.keys(filters).forEach(key => {
10
- * Vue.filter(key, filters[key])
11
- * })
12
- */
13
- 'use strict';
14
- var dateClass = require('../date');
15
- var numberClass = require('../number');
16
- var toolsClass = require('../tools');
17
- var FilterClass = /** @class */ (function () {
18
- function FilterClass() {
19
- }
20
- /**
21
- * 格式化时间,示例:1586840260500 | format('YYYY-MM-DD HH:mm:ss')
22
- * @param {String|Number} date
23
- * @param {String} fmt 'YYYY-MM-DD HH:mm:ss'
24
- * @return {String} 'YYYY-MM-DD HH:mm:ss'
25
- */
26
- FilterClass.prototype.format = function (date, fmt) {
27
- if (fmt === void 0) { fmt = 'YYYY-MM-DD HH:mm:ss'; }
28
- return dateClass.format(date, fmt);
29
- };
30
- /**
31
- * 格式化金额,示例:123456 | formatMoney
32
- * @param {Number} num
33
- * @return {String} 123,456
34
- */
35
- FilterClass.prototype.formatMoney = function (money) {
36
- return numberClass.formatMoney(money);
37
- };
38
- /**
39
- * 截取数组或字符串,示例:'1234' | slice(3)
40
- * @param {Array|String} target 数组或字符串
41
- * @param {Number} length 截取长度,从0开始
42
- * @return {any}
43
- */
44
- FilterClass.prototype.slice = function (target, length) {
45
- if (target === void 0) { target = ''; }
46
- if (length === void 0) { length = 0; }
47
- return toolsClass.slice(target, length);
48
- };
49
- FilterClass.prototype.install = function (Vue) {
50
- var _this = this;
51
- Vue.filter('format', _this.format);
52
- Vue.filter('formatMoney', _this.formatMoney);
53
- Vue.filter('slice', _this.slice);
54
- };
55
- return FilterClass;
56
- }());
57
- module.exports = new FilterClass();
@@ -1,21 +0,0 @@
1
- "use strict";
2
- var Format = /** @class */ (function () {
3
- function Format() {
4
- }
5
- /**
6
- * @desc 对于对象非数字与布尔值的value,当其为falsy时,转换成separator
7
- * @param {object} obj 传入的对象
8
- * @param {string} separator 替换后的值
9
- * transformObjectNullVal({ a: null, b: 0}, '23') // {a: "23", b: 0}
10
- * @return {object}
11
- */
12
- Format.prototype.transformObjectNullVal = function (obj, separator) {
13
- if (separator === void 0) { separator = '-'; }
14
- return Object.keys(obj).reduce(function (cur, key) {
15
- cur[key] = obj[key] || ((obj[key] === 0 || obj[key] === false) ? obj[key] : separator);
16
- return cur;
17
- }, {});
18
- };
19
- return Format;
20
- }());
21
- module.exports = new Format();
@@ -1,31 +0,0 @@
1
- /**
2
- * @file: tools 常用的工具函数
3
- * @Author: wanghui
4
- */
5
- 'use strict';
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- var MatchClass = /** @class */ (function () {
8
- function MatchClass() {
9
- }
10
- /**
11
- * 根据类型返回正则
12
- * @param {String} str 检测的内容
13
- * @param {String} type 检测类型
14
- * checkType('10.120.33.11', 'ip') // true
15
- * @return {Boolean} true or false
16
- */
17
- MatchClass.prototype.checkType = function (str, type) {
18
- var regexp = {
19
- 'ip': /((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}/.test(str),
20
- 'port': /^(\d|[1-5]\d{4}|6[1-4]\d{3}|65[1-4]\d{2}|655[1-2]\d|6553[1-5])$/.test(str),
21
- 'phone': /^1[3|4|5|6|7|8][0-9]{9}$/.test(str),
22
- 'number': /^[0-9]+$/.test(str),
23
- 'email': /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(str),
24
- 'IDCard': /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str),
25
- 'url': /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str)
26
- };
27
- return regexp[type];
28
- };
29
- return MatchClass;
30
- }());
31
- module.exports = new MatchClass();
@@ -1,102 +0,0 @@
1
- /**
2
- * @file number 格式化
3
- * @Author: wanghui
4
- * @createBy: @2020.05.26
5
- */
6
- 'use strict';
7
- var NumberClass = /** @class */ (function () {
8
- function NumberClass() {
9
- }
10
- /**
11
- * 个位数前面补0
12
- * @param {Number} num 需要格式化的数字
13
- * @return {String} '01'
14
- */
15
- NumberClass.prototype.formatNumber = function (num) {
16
- var res = num.toString();
17
- return res[1] ? res : '0' + res;
18
- };
19
- /**
20
- * 将手机号中间部分替换为星号
21
- * @param {String} phone 手机号码
22
- * @return {String} 131****1111
23
- */
24
- NumberClass.prototype.formatPhone = function (phone) {
25
- return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
26
- };
27
- /**
28
- * 格式化数字 万
29
- * @param {Number} num
30
- * @return {String} 12.3万
31
- */
32
- NumberClass.prototype.convertToWan = function (num) {
33
- var result = '';
34
- if (num < 10000) {
35
- result = num;
36
- }
37
- if (num >= 10000) {
38
- result = (num / 10000).toFixed(1) + '万';
39
- }
40
- return result;
41
- };
42
- /**
43
- * 格式化数字 k
44
- * @param {Number} num
45
- * @return {String} 1.2k
46
- */
47
- NumberClass.prototype.convertToThousand = function (num) {
48
- var result = '';
49
- if (num < 1000) {
50
- result = num;
51
- }
52
- if (num >= 1000) {
53
- result = (num / 1000).toFixed(1) + 'k';
54
- }
55
- return result;
56
- };
57
- /**
58
- * 随机数,指定范围
59
- * @param {Number} min 开始
60
- * @param {Number} max 结束
61
- * @return {Number|Object}
62
- */
63
- NumberClass.prototype.random = function (min, max) {
64
- if (arguments.length === 2) {
65
- return Math.floor(min + Math.random() * ((max + 1) - min));
66
- }
67
- else {
68
- return null;
69
- }
70
- };
71
- /**
72
- * 格式化金额
73
- * @param {Number} num
74
- * @return {String} 123,456
75
- */
76
- NumberClass.prototype.formatMoney = function (money, signal) {
77
- var result = '';
78
- if (money === '') {
79
- return result;
80
- }
81
- money = String(money).replace('.00', '');
82
- money = money.substring(money.length - 2) === '.0' ? money.replace('.0', '') : money;
83
- // 小于3位数,直接返回
84
- if (Number(money) < 1000) {
85
- return result = money;
86
- }
87
- if (money.split('.')[0].length < 3) {
88
- return result = money;
89
- }
90
- signal = signal === '' ? '' : ',';
91
- var price = money.split('.')[0] + '';
92
- var pricePoint = money.split('.')[1];
93
- result = price.length > 6 ?
94
- "" + price.substring(0, price.length - 6) + signal + price.substring(price.length - 6, price.length - 3) + "," + price.substring(price.length - 3, price.length)
95
- :
96
- "" + price.substring(0, price.length - 3) + signal + price.substring(price.length - 3, price.length);
97
- result = pricePoint ? "" + result + signal + pricePoint : result;
98
- return result;
99
- };
100
- return NumberClass;
101
- }());
102
- module.exports = new NumberClass();
@@ -1,81 +0,0 @@
1
- /**
2
- * 异常上报日志监控类
3
- * @Author: wanghui
4
- * 常用配置 option:https://docs.sentry.io/clients/javascript/config/
5
- * 1.自动捕获vue组件内异常
6
- * 2.自动捕获promise内的异常
7
- * 3.自动捕获没有被catch的运行异常
8
- */
9
- 'use strict';
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- var raven_js_1 = __importDefault(require("raven-js"));
15
- // import RavenVue from 'raven-js/plugins/vue';
16
- var Report = /** @class */ (function () {
17
- function Report(Vue, options) {
18
- if (options === void 0) { options = {}; }
19
- if (process.env.NODE_ENV !== 'development') {
20
- // todo
21
- }
22
- this.vue = Vue;
23
- this.options = options;
24
- }
25
- Report.getInstance = function (Vue, Option) {
26
- if (!(this.instance instanceof this)) {
27
- this.instance = new this(Vue, Option);
28
- this.instance.install();
29
- }
30
- return this.instance;
31
- };
32
- Report.prototype.install = function () {
33
- if (process.env.NODE_ENV !== 'development') {
34
- // Raven.config(this.options.dsn, {
35
- // environment: process.env.NODE_ENV,
36
- // }).addPlugin(RavenVue, this.Vue).install();
37
- // raven内置了vue插件,会通过vue.config.errorHandler来捕获vue组件内错误并上报sentry服务
38
- // 记录用户信息
39
- raven_js_1.default.setUserContext({ user: this.options.user || '' });
40
- // 设置全局tag标签
41
- raven_js_1.default.setTagsContext({ environment: this.options.env || '' });
42
- }
43
- };
44
- /**
45
- * 主动上报
46
- * @param {String} data
47
- * @param {String} type 'info','warning','error'
48
- * @param {Object} options
49
- */
50
- Report.prototype.log = function (data, type, options) {
51
- if (data === void 0) { data = null; }
52
- if (type === void 0) { type = 'error'; }
53
- if (options === void 0) { options = {}; }
54
- // 添加面包屑
55
- raven_js_1.default.captureBreadcrumb({
56
- message: data,
57
- category: 'manual message',
58
- });
59
- // 异常上报
60
- if (data instanceof Error) {
61
- raven_js_1.default.captureException(data, {
62
- level: type,
63
- logger: 'manual exception',
64
- tags: { options: options },
65
- });
66
- }
67
- else {
68
- raven_js_1.default.captureException('error', {
69
- level: type,
70
- logger: 'manual data',
71
- extra: {
72
- data: data,
73
- options: this.options,
74
- date: new Date(),
75
- },
76
- });
77
- }
78
- };
79
- return Report;
80
- }());
81
- exports.default = Report;