xctc-utils 1.0.7 → 1.0.8

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
@@ -74,3 +74,27 @@ interface Share{
74
74
  utils.weixinShareInit(config:Share)
75
75
  ```
76
76
 
77
+ ### 时间相关方法
78
+ #### 获取当前时间的时间戳
79
+ ```
80
+ utils.getTime() // 返回秒
81
+ ```
82
+ #### 时间戳转任意格式时间字符串
83
+ ```
84
+ /**
85
+ *
86
+ * @param num 传入的时间戳(秒):如 1675667655
87
+ * @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
88
+ * @returns
89
+ */
90
+ utils.formatTimeStamp(num,format) // 返回 format 格式时间戳
91
+ ```
92
+ #### 时间字符串转时间戳
93
+ ```
94
+ /**
95
+ *
96
+ * @param str 字符串格式必须为: 2017/03/03 12:23:55 格式,避免兼容性,不能传 “-” 分割的时间字符串 2017-03-03
97
+ * @returns
98
+ */
99
+ utils.formatStrTime(str) // 返回时间戳 秒
100
+ ```
package/app.ts CHANGED
@@ -2,9 +2,19 @@
2
2
  // npm run build
3
3
 
4
4
  // npm publish
5
+ // ts-node app.ts
6
+ import {formatTimeStamp,formatStrTime} from "./src/time"
5
7
 
6
8
  function app(){
7
9
  console.log("xxxx")
8
10
  }
9
11
 
10
- app()
12
+
13
+
14
+ const xx1 = formatStrTime( "2017/03/03 12:23:55" )
15
+ console.log("formatStrTime",xx1)
16
+
17
+ const xx = formatTimeStamp(1488515035 , "YYYY年MM月DD日 HH时")
18
+ console.log("formatTimeStamp:",xx)
19
+
20
+
package/dist/index.js CHANGED
@@ -38,5 +38,6 @@ var storage = __importStar(require("./storage"));
38
38
  var utils = __importStar(require("./utils"));
39
39
  var crypto = __importStar(require("./crypto"));
40
40
  var weixin = __importStar(require("./weixin"));
41
- var obj = __assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto);
41
+ var time = __importStar(require("./time"));
42
+ var obj = __assign(__assign(__assign(__assign(__assign({}, storage), utils), weixin), crypto), time);
42
43
  exports.default = obj;
@@ -0,0 +1,14 @@
1
+ export declare function etTime(): number;
2
+ /**
3
+ *
4
+ * @param num 传入的时间戳(秒):如 1675667655
5
+ * @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
6
+ * @returns
7
+ */
8
+ export declare function formatTimeStamp(num?: number, format?: string): string;
9
+ /**
10
+ *
11
+ * @param str 字符串格式必须为: 2017/03/03 12:23:55 格式,避免兼容性,不能传 “ - ” 分割的时间字符串 2017-03-03
12
+ * @returns
13
+ */
14
+ export declare function formatStrTime(str: string): number;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatStrTime = exports.formatTimeStamp = exports.etTime = void 0;
4
+ //获取当前时间戳
5
+ function etTime() {
6
+ var now = new Date().getTime() / 1000;
7
+ now = parseInt(now);
8
+ return now;
9
+ }
10
+ exports.etTime = etTime;
11
+ // 1675667655
12
+ // 时间戳转时间字符串
13
+ /**
14
+ *
15
+ * @param num 传入的时间戳(秒):如 1675667655
16
+ * @param format 解析后展示时间字符串格式,默认 "YYYY-MM-DD HH:mm:ss" 格式, 可传格式如: YYYY年MM月DD日 HH时 YYYY/MM/DD HH
17
+ * @returns
18
+ */
19
+ function formatTimeStamp(num, format) {
20
+ if (!format)
21
+ format = "YYYY-MM-DD HH:mm:ss";
22
+ if (!num)
23
+ return "";
24
+ // 传入秒 时间戳
25
+ var date = "";
26
+ if (typeof num == 'number') {
27
+ date = new Date(num * 1000);
28
+ }
29
+ var year = date.getFullYear();
30
+ var month = date.getMonth() + 1;
31
+ month = month < 10 ? "0" + month : month;
32
+ var day = date.getDate();
33
+ day = day < 10 ? "0" + day : day;
34
+ var hour = date.getHours();
35
+ hour = hour < 10 ? "0" + hour : hour;
36
+ var minute = date.getMinutes();
37
+ minute = minute < 10 ? "0" + minute : minute;
38
+ var second = date.getSeconds();
39
+ second = second < 10 ? "0" + second : second;
40
+ if (isExist(format, "YYYY"))
41
+ format = format.replace("YYYY", year);
42
+ if (isExist(format, "MM"))
43
+ format = format.replace("MM", month);
44
+ if (isExist(format, "DD"))
45
+ format = format.replace("DD", day);
46
+ if (isExist(format, "HH"))
47
+ format = format.replace("HH", hour);
48
+ if (isExist(format, "mm"))
49
+ format = format.replace("mm", minute);
50
+ if (isExist(format, "ss"))
51
+ format = format.replace("ss", second);
52
+ return format;
53
+ }
54
+ exports.formatTimeStamp = formatTimeStamp;
55
+ function isExist(str, key) {
56
+ if (!str)
57
+ return;
58
+ if (!key)
59
+ return;
60
+ var index = str.indexOf(key);
61
+ if (index != -1)
62
+ return true;
63
+ return false;
64
+ }
65
+ /**
66
+ *
67
+ * @param str 字符串格式必须为: 2017/03/03 12:23:55 格式,避免兼容性,不能传 “ - ” 分割的时间字符串 2017-03-03
68
+ * @returns
69
+ */
70
+ function formatStrTime(str) {
71
+ var timestamp = new Date(str).getTime();
72
+ timestamp = timestamp / 1000;
73
+ return parseInt(timestamp);
74
+ }
75
+ exports.formatStrTime = formatStrTime;
package/dist/utils.d.ts CHANGED
@@ -3,5 +3,5 @@ export declare function isJson(str: string): any;
3
3
  export declare function $id(id: string): false | HTMLElement;
4
4
  export declare function checkIframeContentHeight(option: UeditorHeightOption): string;
5
5
  export declare function getIframeContentHeight(id: string): any;
6
- export declare function deviceEnvironment(): "android" | "ios" | undefined;
6
+ export declare function deviceEnvironment(): string;
7
7
  export declare function weixinBrowser(): boolean;
package/dist/utils.js CHANGED
@@ -73,6 +73,7 @@ function deviceEnvironment() {
73
73
  return "android";
74
74
  if (!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/))
75
75
  return "ios";
76
+ return "other";
76
77
  }
77
78
  exports.deviceEnvironment = deviceEnvironment;
78
79
  function weixinBrowser() {
@@ -9,7 +9,7 @@ interface configOption {
9
9
  }
10
10
  export declare function weixinUrlCode(config: configOption): void;
11
11
  interface ShareConfig {
12
- http: any;
12
+ http?: any;
13
13
  cb?: any;
14
14
  appId: string;
15
15
  jsApiList?: string[];
@@ -25,4 +25,18 @@ interface ShareOptions {
25
25
  key?: string;
26
26
  }
27
27
  export declare function weixinShareInit(options: ShareOptions): void;
28
+ /**
29
+ *
30
+ * @param options
31
+ *
32
+ */
33
+ interface ConfigPay {
34
+ timeStamp: string;
35
+ nonceStr: string;
36
+ package: string;
37
+ signType: string;
38
+ paySign: string;
39
+ cb?: any;
40
+ }
41
+ export declare function weixinPay(config: ConfigPay): void;
28
42
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.weixinShareInit = exports.weixinShareConfig = exports.weixinUrlCode = void 0;
3
+ exports.weixinPay = exports.weixinShareInit = exports.weixinShareConfig = exports.weixinUrlCode = void 0;
4
4
  // import * as weixin from 'weixin-js-sdk' // 引入微信SDK
5
5
  var weixin = require("weixin-js-sdk");
6
6
  var utils_1 = require("../utils");
@@ -165,7 +165,7 @@ function weixinCode() {
165
165
  }
166
166
  function weixinShareConfig(config) {
167
167
  var _a;
168
- if (!config['http'])
168
+ if (!(config === null || config === void 0 ? void 0 : config.http))
169
169
  return;
170
170
  var url = loc.href.split("#")[0];
171
171
  var param = {
@@ -261,3 +261,34 @@ function weixinShareInit(options) {
261
261
  });
262
262
  }
263
263
  exports.weixinShareInit = weixinShareInit;
264
+ function weixinPay(config) {
265
+ var wx = weixinInit();
266
+ // let { timeStamp,signType,prepay_id,paySign,package,nonceStr,appId } = params
267
+ var cb = "";
268
+ if ((config === null || config === void 0 ? void 0 : config.cb) && typeof config.cb === "function")
269
+ cb = config.cb;
270
+ wx.chooseWXPay({
271
+ timestamp: config.timeStamp,
272
+ nonceStr: config.nonceStr,
273
+ package: config.package,
274
+ signType: config.signType,
275
+ paySign: config.paySign,
276
+ success: function (res) {
277
+ var obj = {
278
+ status: "success",
279
+ data: res,
280
+ };
281
+ if (cb)
282
+ cb(obj);
283
+ },
284
+ cancel: function (cancel) {
285
+ var obj = {
286
+ status: "cancel",
287
+ data: cancel,
288
+ };
289
+ if (cb)
290
+ cb(obj);
291
+ }
292
+ });
293
+ }
294
+ exports.weixinPay = weixinPay;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "xctc-utils",
3
- "version": "1.0.7",
4
- "description": "localStorage存储\r ```\r sessionStorage存储\r ```\r crypto-js加密、解密\r ```\r 微信授权登录、微信分享\r ```\r 设备环境获取\r ```\r 是否是微信浏览器\r ```",
3
+ "version": "1.0.8",
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",
7
7
  "scripts": {
@@ -17,14 +17,12 @@
17
17
  "typescript": "^4.9.5"
18
18
  },
19
19
  "dependencies": {
20
- "@types/crypto-js": "^4.1.1",
21
20
  "crypto-js": "^4.1.1",
22
- "weixin-js-sdk": "^1.6.0",
23
- "weixin-js-sdk-ts": "^1.6.1"
21
+ "weixin-js-sdk": "^1.6.0"
24
22
  },
25
23
  "repository": {
26
24
  "type": "git",
27
25
  "url": "git@gitee.com:npm-management/xctc-utils.git"
28
26
  },
29
- "keywords": [ "localStorage","sessionStorage","crypto-js","微信授权登录","微信H5" ]
27
+ "keywords": [ "localStorage","sessionStorage","crypto-js","微信授权登录","微信H5","时间戳时间字符串转换" ]
30
28
  }