xctc-utils 1.5.5 → 1.5.6

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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ### 项目中常用的方法集合
2
2
  #### email: dybself@163.com
3
3
  #### 安装 npm i xctc-utils
4
+ #### 更新到最新版本 npm install xctc-utils@latest
4
5
  #### 项目中引入 import useUtils from "xctc-utils"
5
6
 
6
7
 
package/dist/index.js CHANGED
@@ -42,5 +42,6 @@ var time = __importStar(require("./time"));
42
42
  var mobile = __importStar(require("./mobile"));
43
43
  var format = __importStar(require("./format"));
44
44
  var isType = __importStar(require("./is"));
45
- var obj = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto), time), mobile), format), { type: __assign({}, isType) });
45
+ var modal = __importStar(require("./modal"));
46
+ var obj = __assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto), time), mobile), format), { type: __assign({}, isType) }), modal);
46
47
  exports.default = obj;
@@ -0,0 +1,4 @@
1
+ export declare const createSpinModule: () => void;
2
+ export declare const destroySpinModule: () => void;
3
+ export declare const createMessageModule: (title: string, duration?: number, type?: string) => void;
4
+ export declare const destroyMessageModule: () => void;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.destroyMessageModule = exports.createMessageModule = exports.destroySpinModule = exports.createSpinModule = void 0;
4
+ // 通过ID获取DOM元素
5
+ function $id(id) {
6
+ if (!id)
7
+ return false;
8
+ var dom = document.getElementById(id);
9
+ if (id && dom instanceof HTMLElement) {
10
+ return dom;
11
+ }
12
+ return false;
13
+ }
14
+ var createSpinModule = function () {
15
+ var parentBox = toggleDomModule("serveSpinModule", "block");
16
+ var containerBox = "";
17
+ var canvasBox = "";
18
+ var spinnerFourBox = "";
19
+ if (!parentBox) {
20
+ styleModule();
21
+ parentBox = createDom("div");
22
+ containerBox = createDom("div");
23
+ canvasBox = createDom("div");
24
+ spinnerFourBox = createDom("div");
25
+ var parentBoxStyle = "width:100vw!important; height:100vh!important;background-color:rgba(0,0,0,0.5);z-index:100000000;position: fixed;top:0;left:0;text-align:center;";
26
+ parentBox.setAttribute("style", parentBoxStyle);
27
+ parentBox.id = 'serveSpinModule';
28
+ var containerBoxStyle = "display: inline-block;padding-top:23%;";
29
+ containerBox.setAttribute("style", containerBoxStyle);
30
+ var canvasBoxStyle = "align-items: center;background: #eeeeee;border-radius: 50%;display: flex;justify-content: center;margin: 1em;width: 3em;height: 3em;";
31
+ canvasBox.setAttribute("style", canvasBoxStyle);
32
+ var spinnerFourBoxStyle = "animation: spinnerFour 1s linear infinite;border: solid 7px transparent;border-top: solid 7px #4db6ac;border-radius: 100%;width: 3em;height: 3em;";
33
+ spinnerFourBox.setAttribute("style", spinnerFourBoxStyle);
34
+ parentBox.appendChild(containerBox);
35
+ containerBox.appendChild(canvasBox);
36
+ canvasBox.appendChild(spinnerFourBox);
37
+ document.body.appendChild(parentBox);
38
+ }
39
+ };
40
+ exports.createSpinModule = createSpinModule;
41
+ var styleModule = function () {
42
+ // 创建一个新的style元素
43
+ var styleElement = document.createElement('style');
44
+ // 将css字符串作为文本内容添加到style元素中
45
+ styleElement.textContent = "\n @keyframes spinnerFour {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n }\n ";
46
+ // 将style元素添加到head部分,使得样式生效
47
+ document.head.appendChild(styleElement);
48
+ };
49
+ var destroySpinModule = function () {
50
+ toggleDomModule("serveSpinModule", "none");
51
+ removeDom("serveSpinModule");
52
+ };
53
+ exports.destroySpinModule = destroySpinModule;
54
+ var toggleDomModule = function (id, val) {
55
+ if (!id)
56
+ return;
57
+ var div = $id(id) || "";
58
+ if (div) {
59
+ div.style.display = val;
60
+ }
61
+ return div;
62
+ };
63
+ var createDom = function (dom) {
64
+ if (!dom)
65
+ return;
66
+ return document.createElement(dom);
67
+ };
68
+ var createMessageModule = function (title, duration, type) {
69
+ var box = toggleDomModule("serveMessageModule", "block");
70
+ if (!type)
71
+ type = "success";
72
+ var containerBoxStyle = "display:inline-block;margin:auto;z-index:100000000;position: fixed;top:10px;left:50%;text-align:center;padding:6px 12px;box-shadow: 0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 9px 28px 8px rgba(0, 0, 0, 0.05);box-sizing: border-box;border-radius:4px;color:".concat(type == "success" ? "#52c41a" : "#f50", " ");
73
+ box = createDom("div");
74
+ box.id = "serveMessageModule";
75
+ box.setAttribute("style", containerBoxStyle);
76
+ document.body.appendChild(box);
77
+ box.innerText = title;
78
+ if (!(typeof duration === "number")) {
79
+ duration = 1500;
80
+ }
81
+ setTimeout(function () {
82
+ (0, exports.destroyMessageModule)();
83
+ }, duration);
84
+ };
85
+ exports.createMessageModule = createMessageModule;
86
+ var destroyMessageModule = function () {
87
+ toggleDomModule("serveMessageModule", "none");
88
+ removeDom("serveMessageModule");
89
+ };
90
+ exports.destroyMessageModule = destroyMessageModule;
91
+ var removeDom = function (id) {
92
+ var div = $id(id);
93
+ if (div)
94
+ div.remove();
95
+ };
@@ -12,3 +12,30 @@ export declare function formatTimeStamp(num?: number, format?: string): string;
12
12
  * @returns
13
13
  */
14
14
  export declare function formatStrTime(str: string): any;
15
+ /**
16
+ * 2018-12-28 15:00:00
17
+ * 2018/12/28 15:00:00
18
+ * 2018年12月28日 15点00分00秒
19
+ * @param value
20
+ * 如果传入时间字符串格式,请传入具体时间格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
21
+ * @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
22
+ * @returns
23
+ */
24
+ export declare function getDateData(value: string | number, format?: string): {
25
+ year: number;
26
+ month: string | number;
27
+ day: string | number;
28
+ hour: string | number;
29
+ minute: string | number;
30
+ second: string | number;
31
+ num: any;
32
+ };
33
+ export declare function findIdcardAge(idcard: string): {
34
+ year: number;
35
+ month: string | number;
36
+ day: string | number;
37
+ hour: string | number;
38
+ minute: string | number;
39
+ second: string | number;
40
+ num: any;
41
+ } | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.formatStrTime = exports.formatTimeStamp = exports.getTime = void 0;
3
+ exports.findIdcardAge = exports.getDateData = exports.formatStrTime = exports.formatTimeStamp = exports.getTime = void 0;
4
4
  //获取当前时间戳
5
5
  function getTime() {
6
6
  var now = new Date().getTime() / 1000;
@@ -22,34 +22,36 @@ function formatTimeStamp(num, format) {
22
22
  num = Number(num); // 先将数据转换为数据类型
23
23
  if (!num)
24
24
  return "";
25
- // 传入秒 时间戳
26
- var date = "";
27
- if (typeof num == 'number') {
28
- date = new Date(num * 1000);
29
- }
30
- var year = date.getFullYear();
31
- var month = date.getMonth() + 1;
32
- month = month < 10 ? "0" + month : month;
33
- var day = date.getDate();
34
- day = day < 10 ? "0" + day : day;
35
- var hour = date.getHours();
36
- hour = hour < 10 ? "0" + hour : hour;
37
- var minute = date.getMinutes();
38
- minute = minute < 10 ? "0" + minute : minute;
39
- var second = date.getSeconds();
40
- second = second < 10 ? "0" + second : second;
25
+ var dateObj = getDateData(num, format) || {};
26
+ // // 传入秒 时间戳
27
+ // let date:any=""
28
+ // if ( typeof num == 'number') {
29
+ // date = new Date( num * 1000)
30
+ // }
31
+ // if( !date ) return ;
32
+ // const year:string = date.getFullYear()
33
+ // let month:any = date.getMonth() + 1
34
+ // month = month < 10 ? "0"+month : month
35
+ // let day:any = date.getDate()
36
+ // day = day < 10 ? "0"+day : day
37
+ // let hour:any = date.getHours()
38
+ // hour = hour < 10 ? "0"+hour : hour
39
+ // let minute:any = date.getMinutes()
40
+ // minute = minute < 10 ? "0"+minute : minute
41
+ // let second:any = date.getSeconds()
42
+ // second = second < 10 ? "0"+second : second
41
43
  if (isExist(format, "YYYY"))
42
- format = format.replace("YYYY", year);
44
+ format = format.replace("YYYY", dateObj === null || dateObj === void 0 ? void 0 : dateObj.year);
43
45
  if (isExist(format, "MM"))
44
- format = format.replace("MM", month);
46
+ format = format.replace("MM", dateObj === null || dateObj === void 0 ? void 0 : dateObj.month);
45
47
  if (isExist(format, "DD"))
46
- format = format.replace("DD", day);
48
+ format = format.replace("DD", dateObj === null || dateObj === void 0 ? void 0 : dateObj.day);
47
49
  if (isExist(format, "HH"))
48
- format = format.replace("HH", hour);
50
+ format = format.replace("HH", dateObj === null || dateObj === void 0 ? void 0 : dateObj.hour);
49
51
  if (isExist(format, "mm"))
50
- format = format.replace("mm", minute);
52
+ format = format.replace("mm", dateObj === null || dateObj === void 0 ? void 0 : dateObj.minute);
51
53
  if (isExist(format, "ss"))
52
- format = format.replace("ss", second);
54
+ format = format.replace("ss", dateObj === null || dateObj === void 0 ? void 0 : dateObj.second);
53
55
  return format;
54
56
  }
55
57
  exports.formatTimeStamp = formatTimeStamp;
@@ -81,3 +83,111 @@ function formatStrTime(str) {
81
83
  return "";
82
84
  }
83
85
  exports.formatStrTime = formatStrTime;
86
+ // 获取当前时间的 年月日时分秒对象
87
+ /**
88
+ * 2018-12-28 15:00:00
89
+ * 2018/12/28 15:00:00
90
+ * 2018年12月28日 15点00分00秒
91
+ * @param value
92
+ * 如果传入时间字符串格式,请传入具体时间格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
93
+ * @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
94
+ * @returns
95
+ */
96
+ function getDateData(value, format) {
97
+ var now = new Date();
98
+ if (typeof value == 'number') {
99
+ now = new Date(value * 1000);
100
+ }
101
+ if (typeof value == "string") {
102
+ if (!format)
103
+ format = "YYYY-MM-DD HH:mm:ss";
104
+ var year_1 = value.substring(0, 4);
105
+ var str = "".concat(year_1);
106
+ var monthIndex = format.indexOf("MM");
107
+ var month_1 = "";
108
+ if (monthIndex != -1) {
109
+ month_1 = value.substring(monthIndex, monthIndex + 3);
110
+ str = "".concat(str, "/").concat(month_1);
111
+ }
112
+ else {
113
+ str = "".concat(str, "/01");
114
+ }
115
+ var dayIndex = format.indexOf("DD");
116
+ var day_1 = "";
117
+ if (dayIndex != -1) {
118
+ day_1 = value.substring(dayIndex, dayIndex + 3);
119
+ str = "".concat(str, "/").concat(day_1);
120
+ }
121
+ else {
122
+ str = "".concat(str, "/01");
123
+ }
124
+ var hourIndex = format.indexOf("HH");
125
+ var hour_1 = "";
126
+ if (hourIndex != -1) {
127
+ hour_1 = value.substring(hourIndex, hourIndex + 3);
128
+ str = "".concat(str, " ").concat(hour_1);
129
+ }
130
+ else {
131
+ str = "".concat(str, " 00");
132
+ }
133
+ var minuteIndex = format.indexOf("mm");
134
+ var minute_1 = "";
135
+ if (hourIndex != -1) {
136
+ minute_1 = value.substring(minuteIndex, minuteIndex + 3);
137
+ str = "".concat(str, ":").concat(minute_1);
138
+ }
139
+ else {
140
+ str = "".concat(str, ":00");
141
+ }
142
+ var secondIndex = format.indexOf("ss");
143
+ var second_1 = "";
144
+ if (hourIndex != -1) {
145
+ second_1 = value.substring(secondIndex, secondIndex + 3);
146
+ str = "".concat(str, ":").concat(second_1);
147
+ }
148
+ else {
149
+ str = "".concat(str, ":00");
150
+ }
151
+ now = new Date(str);
152
+ }
153
+ var year = now.getFullYear();
154
+ var month = now.getMonth() + 1;
155
+ month = month < 10 ? "0" + month : month;
156
+ var day = now.getDate();
157
+ day = day < 10 ? "0" + day : day;
158
+ var hour = now.getHours();
159
+ hour = hour < 10 ? "0" + hour : hour;
160
+ var minute = now.getMinutes();
161
+ minute = minute < 10 ? "0" + minute : minute;
162
+ var second = now.getSeconds();
163
+ second = second < 10 ? "0" + second : second;
164
+ var nowNumber = new Date().getTime() / 1000;
165
+ nowNumber = parseInt(nowNumber);
166
+ return {
167
+ year: year,
168
+ month: month,
169
+ day: day,
170
+ hour: hour,
171
+ minute: minute,
172
+ second: second,
173
+ num: nowNumber
174
+ };
175
+ }
176
+ exports.getDateData = getDateData;
177
+ function findIdcardAge(idcard) {
178
+ if (!idcard) {
179
+ return;
180
+ }
181
+ // 提取身份证号中的出生日期部分
182
+ var birthday = idcard.substring(6, 14);
183
+ if (birthday) {
184
+ // 解析出生日期
185
+ var year = birthday.substring(0, 4);
186
+ var month = birthday.substring(4, 6);
187
+ var day = birthday.substring(6, 8);
188
+ var str = "".concat(year, "-").concat(month, "-").concat(day);
189
+ return getDateData(str, "YYYY-MM-DD HH:mm:ss");
190
+ }
191
+ return;
192
+ }
193
+ exports.findIdcardAge = findIdcardAge;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```\r 时间戳转时间,字符串转时间戳",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",