@jhqn/utils-core 0.0.1-beta.20 → 0.0.1-beta.22
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/index.cjs +53 -0
- package/dist/index.d.ts +22 -1
- package/dist/index.mjs +42 -1
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const detectBrowser = require('detect-browser');
|
|
4
|
+
const dayjs = require('dayjs/esm');
|
|
5
|
+
const localeData = require('dayjs/esm/plugin/localeData');
|
|
6
|
+
const duration = require('dayjs/esm/plugin/duration');
|
|
7
|
+
const relativeTime = require('dayjs/esm/plugin/relativeTime');
|
|
8
|
+
const customParseFormat = require('dayjs/esm/plugin/customParseFormat');
|
|
9
|
+
const objectSupport = require('dayjs/esm/plugin/objectSupport');
|
|
10
|
+
const zhCN = require('dayjs/esm/locale/zh-cn');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
13
|
+
|
|
14
|
+
const dayjs__default = /*#__PURE__*/_interopDefaultCompat(dayjs);
|
|
15
|
+
const localeData__default = /*#__PURE__*/_interopDefaultCompat(localeData);
|
|
16
|
+
const duration__default = /*#__PURE__*/_interopDefaultCompat(duration);
|
|
17
|
+
const relativeTime__default = /*#__PURE__*/_interopDefaultCompat(relativeTime);
|
|
18
|
+
const customParseFormat__default = /*#__PURE__*/_interopDefaultCompat(customParseFormat);
|
|
19
|
+
const objectSupport__default = /*#__PURE__*/_interopDefaultCompat(objectSupport);
|
|
20
|
+
const zhCN__default = /*#__PURE__*/_interopDefaultCompat(zhCN);
|
|
4
21
|
|
|
5
22
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
6
23
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
@@ -232,11 +249,47 @@ const reviver = (_, value) => {
|
|
|
232
249
|
};
|
|
233
250
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
234
251
|
|
|
252
|
+
dayjs__default.extend(localeData__default).locale("zh-cn", zhCN__default);
|
|
253
|
+
dayjs__default.extend(duration__default);
|
|
254
|
+
dayjs__default.extend(relativeTime__default);
|
|
255
|
+
dayjs__default.extend(customParseFormat__default);
|
|
256
|
+
dayjs__default.extend(objectSupport__default);
|
|
257
|
+
const dateFmt = (date, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
258
|
+
const dd = dayjs__default(date);
|
|
259
|
+
let fmt = format;
|
|
260
|
+
if (!isDef(date) || !dd.isValid())
|
|
261
|
+
return "";
|
|
262
|
+
if (format === "date")
|
|
263
|
+
fmt = "YYYY-MM-DD";
|
|
264
|
+
if (format === "datetime")
|
|
265
|
+
fmt = "YYYY-MM-DD HH:mm:ss";
|
|
266
|
+
return dd.format(fmt);
|
|
267
|
+
};
|
|
268
|
+
const dateDuration = (start, end) => {
|
|
269
|
+
const startDay = dayjs__default(start);
|
|
270
|
+
const endDay = dayjs__default(end);
|
|
271
|
+
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid())
|
|
272
|
+
return "";
|
|
273
|
+
const dd = dayjs__default.duration(endDay.diff(startDay));
|
|
274
|
+
const year = dd.years();
|
|
275
|
+
const month = dd.months();
|
|
276
|
+
const day = dd.days();
|
|
277
|
+
const format = [
|
|
278
|
+
year === 0 ? "" : "Y\u5E74",
|
|
279
|
+
month === 0 ? "" : "M\u4E2A\u6708",
|
|
280
|
+
day === 0 ? "" : `${day < 10 && (year !== 0 || month !== 0) ? "\u96F6" : ""}D\u5929`
|
|
281
|
+
].join("");
|
|
282
|
+
return dd.format(format);
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
exports.dayjs = dayjs__default;
|
|
235
286
|
exports.camel2Kebab = camel2Kebab;
|
|
236
287
|
exports.camel2Pascal = camel2Pascal;
|
|
237
288
|
exports.camel2Snake = camel2Snake;
|
|
238
289
|
exports.camel2Title = camel2Title;
|
|
239
290
|
exports.checkImg = checkImg;
|
|
291
|
+
exports.dateDuration = dateDuration;
|
|
292
|
+
exports.dateFmt = dateFmt;
|
|
240
293
|
exports.filterObj = filterObj;
|
|
241
294
|
exports.fixiOSInputAutoZoomIn = fixiOSInputAutoZoomIn;
|
|
242
295
|
exports.getHostEnv = getHostEnv;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
/// <reference types="dayjs/esm/plugin/localeData" />
|
|
2
|
+
/// <reference types="dayjs/esm/plugin/duration" />
|
|
3
|
+
/// <reference types="dayjs/esm/plugin/relativeTime" />
|
|
4
|
+
/// <reference types="dayjs/esm/plugin/customParseFormat" />
|
|
5
|
+
/// <reference types="dayjs/esm/plugin/objectSupport" />
|
|
1
6
|
import * as detect_browser from 'detect-browser';
|
|
7
|
+
import { ConfigType } from 'dayjs/esm';
|
|
8
|
+
export { Dayjs, default as dayjs } from 'dayjs/esm';
|
|
2
9
|
|
|
3
10
|
/**
|
|
4
11
|
* snake2Kebab
|
|
@@ -477,6 +484,20 @@ declare const filterObj: (obj: Record<string, any>, keys: string[], reverse?: bo
|
|
|
477
484
|
[k: string]: any;
|
|
478
485
|
};
|
|
479
486
|
|
|
487
|
+
/**
|
|
488
|
+
* 格式化时间
|
|
489
|
+
* @param {import('dayjs/esm').ConfigType} date 时间
|
|
490
|
+
* @param {string} format 格式
|
|
491
|
+
* @returns {string} 格式化后的时间
|
|
492
|
+
*/
|
|
493
|
+
declare const dateFmt: (date: ConfigType, format?: string | 'date' | 'datetime') => string;
|
|
494
|
+
/**
|
|
495
|
+
* 格式化时间间隔
|
|
496
|
+
* @param {import('dayjs/esm').ConfigType} start 开始时间
|
|
497
|
+
* @param {import('dayjs/esm').ConfigType} end 结束时间
|
|
498
|
+
*/
|
|
499
|
+
declare const dateDuration: (start: ConfigType, end: ConfigType) => string;
|
|
500
|
+
|
|
480
501
|
/**
|
|
481
502
|
* 是否有意义的值
|
|
482
503
|
* @param val
|
|
@@ -556,4 +577,4 @@ declare const isValidArrRes: (res: Res<any[]>) => boolean;
|
|
|
556
577
|
*/
|
|
557
578
|
declare const isValidPageRes: (res: PageRes) => boolean;
|
|
558
579
|
|
|
559
|
-
export { NullOrUndefinable, Nullable, Numeric, PageRes, PageResData, Res, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
|
|
580
|
+
export { NullOrUndefinable, Nullable, Numeric, PageRes, PageResData, Res, Undefinable, camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { detect } from 'detect-browser';
|
|
2
|
+
import dayjs from 'dayjs/esm';
|
|
3
|
+
export { default as dayjs } from 'dayjs/esm';
|
|
4
|
+
import localeData from 'dayjs/esm/plugin/localeData';
|
|
5
|
+
import duration from 'dayjs/esm/plugin/duration';
|
|
6
|
+
import relativeTime from 'dayjs/esm/plugin/relativeTime';
|
|
7
|
+
import customParseFormat from 'dayjs/esm/plugin/customParseFormat';
|
|
8
|
+
import objectSupport from 'dayjs/esm/plugin/objectSupport';
|
|
9
|
+
import zhCN from 'dayjs/esm/locale/zh-cn';
|
|
2
10
|
|
|
3
11
|
const snake2Kebab = (str) => str.replace(/_([a-z])/g, (_, letter) => `-${letter.toLowerCase()}`);
|
|
4
12
|
const snake2Pascal = (str) => str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^[a-z]/, (letter) => letter.toUpperCase());
|
|
@@ -230,4 +238,37 @@ const reviver = (_, value) => {
|
|
|
230
238
|
};
|
|
231
239
|
const filterObj = (obj, keys, reverse = false) => Object.fromEntries(Object.entries(obj).filter(([key]) => reverse ? !keys.includes(key) : keys.includes(key)));
|
|
232
240
|
|
|
233
|
-
|
|
241
|
+
dayjs.extend(localeData).locale("zh-cn", zhCN);
|
|
242
|
+
dayjs.extend(duration);
|
|
243
|
+
dayjs.extend(relativeTime);
|
|
244
|
+
dayjs.extend(customParseFormat);
|
|
245
|
+
dayjs.extend(objectSupport);
|
|
246
|
+
const dateFmt = (date, format = "YYYY-MM-DD HH:mm:ss") => {
|
|
247
|
+
const dd = dayjs(date);
|
|
248
|
+
let fmt = format;
|
|
249
|
+
if (!isDef(date) || !dd.isValid())
|
|
250
|
+
return "";
|
|
251
|
+
if (format === "date")
|
|
252
|
+
fmt = "YYYY-MM-DD";
|
|
253
|
+
if (format === "datetime")
|
|
254
|
+
fmt = "YYYY-MM-DD HH:mm:ss";
|
|
255
|
+
return dd.format(fmt);
|
|
256
|
+
};
|
|
257
|
+
const dateDuration = (start, end) => {
|
|
258
|
+
const startDay = dayjs(start);
|
|
259
|
+
const endDay = dayjs(end);
|
|
260
|
+
if (!isDef(start) || !startDay.isValid() || !isDef(end) || !endDay.isValid())
|
|
261
|
+
return "";
|
|
262
|
+
const dd = dayjs.duration(endDay.diff(startDay));
|
|
263
|
+
const year = dd.years();
|
|
264
|
+
const month = dd.months();
|
|
265
|
+
const day = dd.days();
|
|
266
|
+
const format = [
|
|
267
|
+
year === 0 ? "" : "Y\u5E74",
|
|
268
|
+
month === 0 ? "" : "M\u4E2A\u6708",
|
|
269
|
+
day === 0 ? "" : `${day < 10 && (year !== 0 || month !== 0) ? "\u96F6" : ""}D\u5929`
|
|
270
|
+
].join("");
|
|
271
|
+
return dd.format(format);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export { camel2Kebab, camel2Pascal, camel2Snake, camel2Title, checkImg, dateDuration, dateFmt, filterObj, fixiOSInputAutoZoomIn, getHostEnv, hideCardNo, hideMiddle, hideName, hidePhone, hideThird, inBrowser, isArrStr, isDef, isEmail, isIdCard, isJSONStr, isNumeric, isPhone, isTel, isValidArrRes, isValidKey, isValidPageRes, isValidRes, jClear, jDebug, jError, jGroup, jGroupC, jGroupE, jInfo, jLog, jTime, jTimeEnd, jWarn, kebab2Camel, kebab2Pascal, kebab2Snake, kebab2Title, nonASCII, parseToJSON, pascal2Camel, pascal2Kebab, pascal2Snake, pascal2Title, replacer, reviver, snake2Camel, snake2Kebab, snake2Pascal, snake2Title, title2Camel, title2Kebab, title2Pascal, title2Snake, userAgent, waitTime };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jhqn/utils-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.22",
|
|
5
5
|
"author": "jade-gjz <jiangang.zhang@jaderd.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/jaderd-jh/utils/tree/main/packages/core#readme",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"dayjs": "^1.11.9",
|
|
35
36
|
"detect-browser": "^5.3.0"
|
|
36
37
|
},
|
|
37
38
|
"scripts": {
|