@pisell/utils 1.0.1 → 1.0.3

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.
@@ -0,0 +1,4 @@
1
+ declare const webHookApi: {
2
+ warning_log: string;
3
+ };
4
+ export { webHookApi };
@@ -0,0 +1,4 @@
1
+ var webHookApi = {
2
+ warning_log: "https://open.feishu.cn/open-apis/bot/v2/hook/6f328eb8-782c-4305-a0b5-d14986a24a0d"
3
+ };
4
+ export { webHookApi };
package/es/date.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @title: 格式化日期
3
+ * @description:
4
+ * @param {string} date
5
+ * @param {string} format
6
+ * @return {*}
7
+ * @Author: zhiwei.Wang
8
+ * @Date: 2023-07-21 10:49
9
+ */
10
+ export declare const formatDate: (date: string | Date, format?: string) => string;
11
+ /**
12
+ * @title: excel日期 转 js日期
13
+ * @description:
14
+ * @param {number} excelDate
15
+ * @return {*}
16
+ * @Author: zhiwei.Wang
17
+ * @Date: 2023-07-21 10:49
18
+ */
19
+ export declare const excelDateToJSDate: (excelDate: number) => string;
20
+ /**
21
+ * @title: js日期 转 excel日期
22
+ * @description:
23
+ * @param {string} jsDate
24
+ * @return {*}
25
+ * @Author: zhiwei.Wang
26
+ * @Date: 2023-07-21 10:49
27
+ */
28
+ export declare const jsDateToExcelDate: (jsDate: string) => number;
package/es/date.js ADDED
@@ -0,0 +1,59 @@
1
+ import dayjs from "dayjs";
2
+ var formatMaps = [
3
+ // 19 Jul 2023, 09:00am
4
+ 'D MMM YYYY, hh:mma',
5
+ // 2023-07-19
6
+ 'YYYY-MM-DD'];
7
+
8
+ /**
9
+ * @title: 格式化日期
10
+ * @description:
11
+ * @param {string} date
12
+ * @param {string} format
13
+ * @return {*}
14
+ * @Author: zhiwei.Wang
15
+ * @Date: 2023-07-21 10:49
16
+ */
17
+ export var formatDate = function formatDate(date, format) {
18
+ // 19 Jul 2023, 09:00am
19
+ var _format = format || formatMaps[0];
20
+ if (!date) {
21
+ return date;
22
+ }
23
+ return dayjs(date).format(_format);
24
+ };
25
+
26
+ /**
27
+ * @title: excel日期 转 js日期
28
+ * @description:
29
+ * @param {number} excelDate
30
+ * @return {*}
31
+ * @Author: zhiwei.Wang
32
+ * @Date: 2023-07-21 10:49
33
+ */
34
+ export var excelDateToJSDate = function excelDateToJSDate(excelDate) {
35
+ // Excel日期的起始日期为1900年1月1日,JavaScript的起始日期为1970年1月1日
36
+ var dateOffset = (excelDate - 25569) * 86400000; // 将天数转换成毫秒数
37
+
38
+ var jsDate = formatDate(new Date(dateOffset), formatMaps[1]);
39
+ return jsDate;
40
+ };
41
+
42
+ /**
43
+ * @title: js日期 转 excel日期
44
+ * @description:
45
+ * @param {string} jsDate
46
+ * @return {*}
47
+ * @Author: zhiwei.Wang
48
+ * @Date: 2023-07-21 10:49
49
+ */
50
+ export var jsDateToExcelDate = function jsDateToExcelDate(jsDate) {
51
+ var _jsDate = new Date(jsDate);
52
+ // Excel日期的起始日期为1900年1月1日,JavaScript的起始日期为1970年1月1日
53
+ var excelStartDate = new Date(Date.UTC(1900, 0, 1)); // Excel的起始日期为UTC的1900年1月1日
54
+ var dateOffset = _jsDate - excelStartDate; // 计算日期之间的偏移量(毫秒数)
55
+
56
+ var excelDate = dateOffset / 86400000 + 25569; // 将毫秒数转换回天数,并加上Excel的起始日期偏移量
57
+
58
+ return excelDate;
59
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @Title: 设置主题
3
+ * @Describe: 传入字符串键值对
4
+ * @Author: Wzw
5
+ */
6
+ export declare const setTheme: (themes: {
7
+ [key: string]: string;
8
+ }) => void;
package/es/document.js ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @Title: 设置主题
3
+ * @Describe: 传入字符串键值对
4
+ * @Author: Wzw
5
+ */
6
+ export var setTheme = function setTheme(themes) {
7
+ try {
8
+ var _themes = Object.entries(themes);
9
+ for (var _i = 0, _themes2 = _themes; _i < _themes2.length; _i++) {
10
+ var item = _themes2[_i];
11
+ document.documentElement.style.setProperty(item[0], item[1]);
12
+ }
13
+ } catch (err) {
14
+ console.error(err);
15
+ }
16
+ };
package/es/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from './otherUtils';
2
2
  export * from './typeUtils';
3
- //# sourceMappingURL=index.d.ts.map
3
+ export * from './document';
4
+ export * from './date';
5
+ export * from './platform';
6
+ export * from './log';
package/es/index.js CHANGED
@@ -1,2 +1,6 @@
1
1
  export * from "./otherUtils";
2
- export * from "./typeUtils";
2
+ export * from "./typeUtils";
3
+ export * from "./document";
4
+ export * from "./date";
5
+ export * from "./platform";
6
+ export * from "./log";
package/es/log.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ interface contentItem {
2
+ key: string;
3
+ value: string;
4
+ }
5
+ interface sendWebhookProps {
6
+ title: string;
7
+ content: contentItem[];
8
+ }
9
+ declare const _default: {
10
+ sendWarningLog: ({ title, content }: sendWebhookProps) => Promise<any>;
11
+ };
12
+ export default _default;
package/es/log.js ADDED
@@ -0,0 +1,54 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ import { webHookApi } from "./constants";
6
+ var createFeishuMessageContent = function createFeishuMessageContent(contentArr) {
7
+ return JSON.stringify(contentArr.map(function (item) {
8
+ return [{
9
+ tag: "text",
10
+ text: "".concat(item.key, ": ")
11
+ }, {
12
+ tag: "text",
13
+ text: "".concat(item.value)
14
+ }];
15
+ }));
16
+ };
17
+ var sendWarningLog = /*#__PURE__*/function () {
18
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
19
+ var title, content, contentStr, response;
20
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ title = _ref.title, content = _ref.content;
24
+ contentStr = createFeishuMessageContent(content);
25
+ _context.next = 4;
26
+ return fetch(webHookApi.warning_log, {
27
+ headers: {
28
+ "Content-Type": "application/json"
29
+ },
30
+ method: "POST",
31
+ body: JSON.stringify({
32
+ msg_type: "post",
33
+ content: "{\"post\":{\"zh_cn\":{\"title\":\"".concat(title, "\",\"content\":").concat(contentStr, "}}}")
34
+ })
35
+ });
36
+ case 4:
37
+ response = _context.sent;
38
+ _context.next = 7;
39
+ return response.json();
40
+ case 7:
41
+ return _context.abrupt("return", _context.sent);
42
+ case 8:
43
+ case "end":
44
+ return _context.stop();
45
+ }
46
+ }, _callee);
47
+ }));
48
+ return function sendWarningLog(_x) {
49
+ return _ref2.apply(this, arguments);
50
+ };
51
+ }();
52
+ export default {
53
+ sendWarningLog: sendWarningLog
54
+ };
@@ -6,4 +6,3 @@
6
6
  * @return {*}
7
7
  */
8
8
  export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
- //# sourceMappingURL=otherUtils.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const isIpad: () => boolean;
2
+ export declare const isMobile: () => boolean;
package/es/platform.js ADDED
@@ -0,0 +1,26 @@
1
+ export var isIpad = function isIpad() {
2
+ var ua = navigator.userAgent;
3
+ var isSafari = ua.indexOf('Safari') != -1 && ua.indexOf('Version') != -1;
4
+ var isIphone = ua.indexOf('iPhone') != -1 && ua.indexOf('Version') != -1;
5
+ var isIPad = isSafari && !isIphone && 'ontouchend' in document;
6
+ if (!/iphone|ios|ipad|android|mobile/i.test(navigator.userAgent.toLowerCase()) && !isIPad) {
7
+ return false;
8
+ }
9
+ return true;
10
+ };
11
+ export var isMobile = function isMobile() {
12
+ var sUserAgent = window.navigator.userAgent.toLowerCase();
13
+ var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
14
+ var bIsIphoneOs = sUserAgent.match(/iphone os/i) == 'iphone os';
15
+ var bIsMidp = sUserAgent.match(/midp/i) == 'midp';
16
+ var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
17
+ var bIsUc = sUserAgent.match(/ucweb/i) == 'ucweb';
18
+ var bIsAndroid = sUserAgent.match(/android/i) == 'android';
19
+ var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
20
+ var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';
21
+ if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || isIpad()) {
22
+ return true;
23
+ } else {
24
+ return false;
25
+ }
26
+ };
package/es/typeUtils.d.ts CHANGED
@@ -40,4 +40,3 @@ export declare const isJson: (v: any) => boolean;
40
40
  * @param {any} obj
41
41
  */
42
42
  export declare const isPlainObject: (obj: any) => boolean;
43
- //# sourceMappingURL=typeUtils.d.ts.map
@@ -0,0 +1,4 @@
1
+ declare const webHookApi: {
2
+ warning_log: string;
3
+ };
4
+ export { webHookApi };
@@ -0,0 +1,31 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/constants/index.ts
20
+ var constants_exports = {};
21
+ __export(constants_exports, {
22
+ webHookApi: () => webHookApi
23
+ });
24
+ module.exports = __toCommonJS(constants_exports);
25
+ var webHookApi = {
26
+ warning_log: "https://open.feishu.cn/open-apis/bot/v2/hook/6f328eb8-782c-4305-a0b5-d14986a24a0d"
27
+ };
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ webHookApi
31
+ });
package/lib/date.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @title: 格式化日期
3
+ * @description:
4
+ * @param {string} date
5
+ * @param {string} format
6
+ * @return {*}
7
+ * @Author: zhiwei.Wang
8
+ * @Date: 2023-07-21 10:49
9
+ */
10
+ export declare const formatDate: (date: string | Date, format?: string) => string;
11
+ /**
12
+ * @title: excel日期 转 js日期
13
+ * @description:
14
+ * @param {number} excelDate
15
+ * @return {*}
16
+ * @Author: zhiwei.Wang
17
+ * @Date: 2023-07-21 10:49
18
+ */
19
+ export declare const excelDateToJSDate: (excelDate: number) => string;
20
+ /**
21
+ * @title: js日期 转 excel日期
22
+ * @description:
23
+ * @param {string} jsDate
24
+ * @return {*}
25
+ * @Author: zhiwei.Wang
26
+ * @Date: 2023-07-21 10:49
27
+ */
28
+ export declare const jsDateToExcelDate: (jsDate: string) => number;
package/lib/date.js ADDED
@@ -0,0 +1,68 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/date.ts
30
+ var date_exports = {};
31
+ __export(date_exports, {
32
+ excelDateToJSDate: () => excelDateToJSDate,
33
+ formatDate: () => formatDate,
34
+ jsDateToExcelDate: () => jsDateToExcelDate
35
+ });
36
+ module.exports = __toCommonJS(date_exports);
37
+ var import_dayjs = __toESM(require("dayjs"));
38
+ var formatMaps = [
39
+ // 19 Jul 2023, 09:00am
40
+ "D MMM YYYY, hh:mma",
41
+ // 2023-07-19
42
+ "YYYY-MM-DD"
43
+ ];
44
+ var formatDate = (date, format) => {
45
+ let _format = format || formatMaps[0];
46
+ if (!date) {
47
+ return date;
48
+ }
49
+ return (0, import_dayjs.default)(date).format(_format);
50
+ };
51
+ var excelDateToJSDate = (excelDate) => {
52
+ const dateOffset = (excelDate - 25569) * 864e5;
53
+ const jsDate = formatDate(new Date(dateOffset), formatMaps[1]);
54
+ return jsDate;
55
+ };
56
+ var jsDateToExcelDate = (jsDate) => {
57
+ const _jsDate = new Date(jsDate);
58
+ const excelStartDate = new Date(Date.UTC(1900, 0, 1));
59
+ const dateOffset = _jsDate - excelStartDate;
60
+ const excelDate = dateOffset / 864e5 + 25569;
61
+ return excelDate;
62
+ };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ excelDateToJSDate,
66
+ formatDate,
67
+ jsDateToExcelDate
68
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @Title: 设置主题
3
+ * @Describe: 传入字符串键值对
4
+ * @Author: Wzw
5
+ */
6
+ export declare const setTheme: (themes: {
7
+ [key: string]: string;
8
+ }) => void;
@@ -0,0 +1,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/document.ts
20
+ var document_exports = {};
21
+ __export(document_exports, {
22
+ setTheme: () => setTheme
23
+ });
24
+ module.exports = __toCommonJS(document_exports);
25
+ var setTheme = (themes) => {
26
+ try {
27
+ let _themes = Object.entries(themes);
28
+ for (let item of _themes) {
29
+ document.documentElement.style.setProperty(item[0], item[1]);
30
+ }
31
+ } catch (err) {
32
+ console.error(err);
33
+ }
34
+ };
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ setTheme
38
+ });
package/lib/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
1
  export * from './otherUtils';
2
2
  export * from './typeUtils';
3
- //# sourceMappingURL=index.d.ts.map
3
+ export * from './document';
4
+ export * from './date';
5
+ export * from './platform';
6
+ export * from './log';
package/lib/index.js CHANGED
@@ -18,8 +18,16 @@ var src_exports = {};
18
18
  module.exports = __toCommonJS(src_exports);
19
19
  __reExport(src_exports, require("./otherUtils"), module.exports);
20
20
  __reExport(src_exports, require("./typeUtils"), module.exports);
21
+ __reExport(src_exports, require("./document"), module.exports);
22
+ __reExport(src_exports, require("./date"), module.exports);
23
+ __reExport(src_exports, require("./platform"), module.exports);
24
+ __reExport(src_exports, require("./log"), module.exports);
21
25
  // Annotate the CommonJS export names for ESM import in node:
22
26
  0 && (module.exports = {
23
27
  ...require("./otherUtils"),
24
- ...require("./typeUtils")
28
+ ...require("./typeUtils"),
29
+ ...require("./document"),
30
+ ...require("./date"),
31
+ ...require("./platform"),
32
+ ...require("./log")
25
33
  });
package/lib/log.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ interface contentItem {
2
+ key: string;
3
+ value: string;
4
+ }
5
+ interface sendWebhookProps {
6
+ title: string;
7
+ content: contentItem[];
8
+ }
9
+ declare const _default: {
10
+ sendWarningLog: ({ title, content }: sendWebhookProps) => Promise<any>;
11
+ };
12
+ export default _default;
package/lib/log.js ADDED
@@ -0,0 +1,52 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/log.ts
20
+ var log_exports = {};
21
+ __export(log_exports, {
22
+ default: () => log_default
23
+ });
24
+ module.exports = __toCommonJS(log_exports);
25
+ var import_constants = require("./constants");
26
+ var createFeishuMessageContent = (contentArr) => {
27
+ return JSON.stringify(
28
+ contentArr.map((item) => {
29
+ return [
30
+ { tag: "text", text: `${item.key}: ` },
31
+ { tag: "text", text: `${item.value}` }
32
+ ];
33
+ })
34
+ );
35
+ };
36
+ var sendWarningLog = async ({ title, content }) => {
37
+ const contentStr = createFeishuMessageContent(content);
38
+ const response = await fetch(import_constants.webHookApi.warning_log, {
39
+ headers: {
40
+ "Content-Type": "application/json"
41
+ },
42
+ method: "POST",
43
+ body: JSON.stringify({
44
+ msg_type: "post",
45
+ content: `{"post":{"zh_cn":{"title":"${title}","content":${contentStr}}}}`
46
+ })
47
+ });
48
+ return await response.json();
49
+ };
50
+ var log_default = {
51
+ sendWarningLog
52
+ };
@@ -6,4 +6,3 @@
6
6
  * @return {*}
7
7
  */
8
8
  export declare const getUniqueId: (prefix?: string, maxLength?: number) => string;
9
- //# sourceMappingURL=otherUtils.d.ts.map
@@ -0,0 +1,2 @@
1
+ export declare const isIpad: () => boolean;
2
+ export declare const isMobile: () => boolean;
@@ -0,0 +1,58 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/platform.ts
20
+ var platform_exports = {};
21
+ __export(platform_exports, {
22
+ isIpad: () => isIpad,
23
+ isMobile: () => isMobile
24
+ });
25
+ module.exports = __toCommonJS(platform_exports);
26
+ var isIpad = () => {
27
+ var ua = navigator.userAgent;
28
+ var isSafari = ua.indexOf("Safari") != -1 && ua.indexOf("Version") != -1;
29
+ var isIphone = ua.indexOf("iPhone") != -1 && ua.indexOf("Version") != -1;
30
+ var isIPad = isSafari && !isIphone && "ontouchend" in document;
31
+ if (!/iphone|ios|ipad|android|mobile/i.test(
32
+ navigator.userAgent.toLowerCase()
33
+ ) && !isIPad) {
34
+ return false;
35
+ }
36
+ return true;
37
+ };
38
+ var isMobile = () => {
39
+ let sUserAgent = window.navigator.userAgent.toLowerCase();
40
+ let bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
41
+ let bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
42
+ let bIsMidp = sUserAgent.match(/midp/i) == "midp";
43
+ let bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
44
+ let bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
45
+ let bIsAndroid = sUserAgent.match(/android/i) == "android";
46
+ let bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
47
+ let bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
48
+ if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || isIpad()) {
49
+ return true;
50
+ } else {
51
+ return false;
52
+ }
53
+ };
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ isIpad,
57
+ isMobile
58
+ });
@@ -40,4 +40,3 @@ export declare const isJson: (v: any) => boolean;
40
40
  * @param {any} obj
41
41
  */
42
42
  export declare const isPlainObject: (obj: any) => boolean;
43
- //# sourceMappingURL=typeUtils.d.ts.map
package/package.json CHANGED
@@ -1,9 +1,20 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
+ "main": "./lib/index.js",
5
+ "module": "./es/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "typings": "./lib/index.d.ts",
4
8
  "devDependencies": {
5
- "father": "^4.1.0"
9
+ "father": "^4.1.0",
10
+ "dayjs": "^1.11.9"
6
11
  },
12
+ "files": [
13
+ "es",
14
+ "lib",
15
+ "package.json",
16
+ "README.md"
17
+ ],
7
18
  "publishConfig": {
8
19
  "access": "public"
9
20
  },
package/.fatherrc.ts DELETED
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'father';
2
-
3
- export default defineConfig({
4
- // more father config: https://github.com/umijs/father/blob/master/docs/config.md
5
- esm: { output: 'es' },
6
- cjs: { output: 'lib' },
7
- });
package/CHANGELOG.md DELETED
@@ -1,7 +0,0 @@
1
- # @pisell/utils
2
-
3
- ## 1.0.1
4
-
5
- ### Patch Changes
6
-
7
- - 测试更新包
package/es/index.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"otherUtils.d.ts","sourceRoot":"","sources":["otherUtils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,iDAIvB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,GAAG,oBACR,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAS,GAAG,iBAA0C,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAS,GAAG,qBACR,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,GAAG,mBAA6C,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,MAAM,MAAO,GAAG,KAAG,OAU/B,CAAC;AAOF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAS,GAAG,YAarC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"otherUtils.d.ts","sourceRoot":"","sources":["otherUtils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,iDAIvB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"typeUtils.d.ts","sourceRoot":"","sources":["typeUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAS,GAAG,oBACR,CAAC;AAE5B;;;GAGG;AACH,eAAO,MAAM,KAAK,QAAS,GAAG,iBAA0C,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAS,GAAG,kBAA2C,CAAC;AAE7E;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAS,GAAG,qBACR,CAAC;AAE7B;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAS,GAAG,mBAA6C,CAAC;AAEhF;;;GAGG;AACH,eAAO,MAAM,MAAM,MAAO,GAAG,KAAG,OAU/B,CAAC;AAOF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAAS,GAAG,YAarC,CAAC"}
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './otherUtils';
2
- export * from './typeUtils';
package/src/otherUtils.ts DELETED
@@ -1,13 +0,0 @@
1
-
2
- /**
3
- * @Description: 生成唯一id
4
- * @Author: wzw
5
- * @Date: 2020-12-01 14:20:29
6
- * @param {*}
7
- * @return {*}
8
- */
9
- export const getUniqueId = (prefix = '', maxLength = 11) => {
10
- return (
11
- prefix + (Math.random() + '').replace(/\D/g, '').substring(0, maxLength)
12
- );
13
- };
package/src/typeUtils.ts DELETED
@@ -1,79 +0,0 @@
1
- /**
2
- * 判断是否是函数
3
- * @param obj
4
- */
5
- export const isFunction = (obj: any): obj is Function =>
6
- typeof obj === 'function';
7
-
8
- /**
9
- * 判断是否是数组
10
- * @param obj
11
- */
12
- export const isArr = (obj: any): obj is Array<any> => Array.isArray(obj);
13
-
14
- /**
15
- * 判断是否是字符串
16
- * @param obj
17
- */
18
- export const isString = (obj: any): obj is string => typeof obj === 'string';
19
-
20
- /**
21
- * 判断是否是数字
22
- * @param obj
23
- */
24
- export const isNumber = (obj: any): obj is number => typeof obj === 'number';
25
-
26
- /**
27
- * 判断是否是undefined
28
- * @param obj
29
- */
30
- export const isUndefined = (obj: any): obj is undefined =>
31
- typeof obj === 'undefined';
32
-
33
- /**
34
- * 判断是否是boolean
35
- * @param obj
36
- */
37
- export const isBoolean = (obj: any): obj is boolean => typeof obj === 'boolean';
38
-
39
- /**
40
- * 判断是否是json字符串
41
- * @param v
42
- */
43
- export const isJson = (v: any): boolean => {
44
- if (typeof v === 'string') {
45
- try {
46
- return JSON.parse(v);
47
- } catch (e) {
48
- return false;
49
- }
50
- } else {
51
- return false;
52
- }
53
- };
54
-
55
- const getProto = Object.getPrototypeOf;
56
- const hasOwn = {}.hasOwnProperty;
57
- const fnToString = hasOwn.toString;
58
- const ObjectFunctionString = fnToString.call(Object);
59
-
60
- /**
61
- * @Title: 判断是否为对象
62
- * @Describe:
63
- * @Author: Wzw
64
- * @param {any} obj
65
- */
66
- export const isPlainObject = (obj: any) => {
67
- var proto, Ctor;
68
- if (!obj || toString.call(obj) !== '[object Object]') {
69
- return false;
70
- }
71
- proto = getProto(obj);
72
- if (!proto) {
73
- return true;
74
- }
75
- Ctor = hasOwn.call(proto, 'constructor') && proto.constructor;
76
- return (
77
- typeof Ctor === 'function' && fnToString.call(Ctor) === ObjectFunctionString
78
- );
79
- };
package/tsconfig.json DELETED
@@ -1,14 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "strict": true,
4
- "declaration": true,
5
- "skipLibCheck": true,
6
- "esModuleInterop": true,
7
- "jsx": "react",
8
- "baseUrl": "./",
9
- "paths": {
10
- "@": ["src/*"]
11
- }
12
- },
13
- "include": ["src"]
14
- }