@heyform-inc/utils 1.0.7 → 1.0.9
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.d.mts +34 -19
- package/dist/index.d.ts +34 -19
- package/dist/index.js +149 -117
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -117
- package/dist/index.mjs.map +1 -1
- package/package.json +75 -71
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from 'deep-object-diff';
|
|
2
|
+
import { IParseOptions, IStringifyOptions } from 'qs';
|
|
3
|
+
export { default as qs } from 'qs';
|
|
2
4
|
import dayjs, { QUnitType, OpUnitType } from 'dayjs';
|
|
3
5
|
import visUUID from 'validator/lib/isUUID';
|
|
6
|
+
import visFQDN from 'validator/lib/isFQDN';
|
|
4
7
|
import { IsNumericOptions } from 'validator/lib/isNumeric';
|
|
5
8
|
import { IsEmailOptions } from 'validator/lib/isEmail';
|
|
6
9
|
import { IsURLOptions } from 'validator/lib/isURL';
|
|
@@ -28,7 +31,26 @@ declare function darken(hex: string, alpha: number): string;
|
|
|
28
31
|
declare function invert(hex: string): string;
|
|
29
32
|
declare function alphaHexToRgb(hex: string, alpha: number, backgroundHex: string): number[];
|
|
30
33
|
|
|
31
|
-
declare function toBool(value: unknown, defaults?: boolean): boolean;
|
|
34
|
+
declare function toBool(value: unknown, defaults?: boolean): boolean;
|
|
35
|
+
declare const parseBool: typeof toBool;
|
|
36
|
+
declare function toInteger(value: unknown, defaults?: number, maxValue?: number): number | undefined;
|
|
37
|
+
declare const parseNumber: typeof toInteger;
|
|
38
|
+
declare const toInt: typeof toInteger;
|
|
39
|
+
declare function toFloat(value: unknown, defaults?: number, maxValue?: number): number | undefined;
|
|
40
|
+
declare function toFixed(value: number, precision?: number): string;
|
|
41
|
+
declare function toJSON<T extends object>(str: unknown, defaults?: T): T | undefined;
|
|
42
|
+
declare const parseJson: typeof toJSON;
|
|
43
|
+
declare function toIntlNumber(value: number): string;
|
|
44
|
+
interface ToDurationOptions {
|
|
45
|
+
hideOnZeroValue?: boolean;
|
|
46
|
+
padNumber?: boolean;
|
|
47
|
+
hourUnit?: string;
|
|
48
|
+
minuteUnit?: string;
|
|
49
|
+
secondUnit?: string;
|
|
50
|
+
}
|
|
51
|
+
declare function toDuration(value: number, options?: ToDurationOptions): string;
|
|
52
|
+
declare function toURLParams<T extends object>(value: string, options?: IParseOptions): T;
|
|
53
|
+
declare function toURLQuery(value: Record<string | number, any>, baseUri?: string, options?: IStringifyOptions): string;
|
|
32
54
|
|
|
33
55
|
declare function timestamp(): number;
|
|
34
56
|
declare function date(str?: string, format?: string): dayjs.Dayjs;
|
|
@@ -43,7 +65,9 @@ declare function isNumber(arg: any): boolean;
|
|
|
43
65
|
declare function isValidArray(arg: any): boolean;
|
|
44
66
|
declare function isNan(arg: any): boolean;
|
|
45
67
|
declare function isSet(arg: any): boolean;
|
|
68
|
+
declare function isWeakSet(arg: any): boolean;
|
|
46
69
|
declare function isMap(arg: any): boolean;
|
|
70
|
+
declare function isWeakMap(arg: any): boolean;
|
|
47
71
|
declare function isSymbol(arg: any): boolean;
|
|
48
72
|
declare function isObject(arg: any): boolean;
|
|
49
73
|
declare function isDate(arg: any): boolean;
|
|
@@ -65,8 +89,9 @@ declare function uniqueArray(arg: any): any[];
|
|
|
65
89
|
declare function isNumeric(arg: any, options?: IsNumericOptions): boolean;
|
|
66
90
|
declare function isURL(arg: any, options?: IsURLOptions): boolean;
|
|
67
91
|
declare function isEmail(arg: any, options?: IsEmailOptions): boolean;
|
|
68
|
-
declare const _default
|
|
92
|
+
declare const _default: {
|
|
69
93
|
isUUID: typeof visUUID;
|
|
94
|
+
isFQDN: typeof visFQDN;
|
|
70
95
|
isBoolean: typeof isBoolean;
|
|
71
96
|
isString: typeof isString;
|
|
72
97
|
isNumber: typeof isNumber;
|
|
@@ -76,6 +101,8 @@ declare const _default$1: {
|
|
|
76
101
|
isNan: typeof isNan;
|
|
77
102
|
isSet: typeof isSet;
|
|
78
103
|
isMap: typeof isMap;
|
|
104
|
+
isWeakSet: typeof isWeakSet;
|
|
105
|
+
isWeakMap: typeof isWeakMap;
|
|
79
106
|
isSymbol: typeof isSymbol;
|
|
80
107
|
isObject: typeof isObject;
|
|
81
108
|
isDate: typeof isDate;
|
|
@@ -99,7 +126,9 @@ declare const _default$1: {
|
|
|
99
126
|
};
|
|
100
127
|
|
|
101
128
|
declare function hs(arg: string): number | undefined;
|
|
102
|
-
declare function ms(arg: string): number | undefined;
|
|
129
|
+
declare function ms(arg: string): number | undefined;
|
|
130
|
+
declare const toSecond: typeof hs;
|
|
131
|
+
declare const toMillisecond: typeof ms;
|
|
103
132
|
|
|
104
133
|
declare const commonImageMimeTypes: string[];
|
|
105
134
|
declare const commonFileMimeTypes: string[];
|
|
@@ -109,27 +138,13 @@ declare function nanoid(len?: number): string;
|
|
|
109
138
|
declare function nanoidCustomAlphabet(alphabet: string, len?: number): string;
|
|
110
139
|
|
|
111
140
|
declare function pickObject(target: Record<string, any>, fields: Array<string | string[]>, excludes?: Array<string>): Record<string, any>;
|
|
141
|
+
declare function excludeObject(target: Record<string, any>, excludes?: Array<string>): Record<string, any>;
|
|
112
142
|
declare function pickValidValues<T = string | number | boolean>(target: Record<string, T>, fields: Array<string | string[]>): Record<string, T>;
|
|
113
143
|
declare function removeObjectNil(target: Record<string, any>): Record<string, any>;
|
|
114
144
|
declare function copyObjectValues(target: Record<string, any>, dist: Record<string, any>, keyMaps: Array<string | string[]>): void;
|
|
115
145
|
|
|
116
|
-
declare function parseJson(str: string, defaultValue?: any): any;
|
|
117
|
-
declare function parseBool(arg: any, defaultValue?: boolean): boolean;
|
|
118
|
-
declare function parseNumber(arg: any, defaultValue?: number, maxValue?: number): number | undefined;
|
|
119
146
|
declare function htmlToText(html: string, limit?: number): string;
|
|
120
147
|
|
|
121
|
-
interface QsOptions {
|
|
122
|
-
encode?: boolean;
|
|
123
|
-
decode?: boolean;
|
|
124
|
-
separator?: string;
|
|
125
|
-
}
|
|
126
|
-
declare function stringify(arg: Record<string, any>, options?: QsOptions): string;
|
|
127
|
-
declare function parse(str: string, options?: QsOptions): Record<string, any>;
|
|
128
|
-
declare const _default: {
|
|
129
|
-
stringify: typeof stringify;
|
|
130
|
-
parse: typeof parse;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
148
|
declare enum RandomType {
|
|
134
149
|
LOWER = 0,
|
|
135
150
|
UPPER = 1,
|
|
@@ -153,4 +168,4 @@ declare function slugify(text: string, options?: SlugifyOptions): string;
|
|
|
153
168
|
|
|
154
169
|
declare function type(obj: any): string;
|
|
155
170
|
|
|
156
|
-
export { RandomType, type SlugifyOptions, alpha, alphaHexToRgb, bytes, clone, colorBrightness, commonFileMimeTypes, commonImageMimeTypes, copyObjectValues, darken, date, datePeriod, formatBytes, _default
|
|
171
|
+
export { RandomType, type SlugifyOptions, alpha, alphaHexToRgb, bytes, clone, colorBrightness, commonFileMimeTypes, commonImageMimeTypes, copyObjectValues, darken, date, datePeriod, excludeObject, formatBytes, _default as helper, hexToRgb, hs, htmlToText, invert, isDarkColor, isDateExpired, isHexColor, isLightColor, isRgb, isRgba, lighten, mime, ms, nanoid, nanoidCustomAlphabet, parseBool, parseBytes, parseJson, parseNumber, pickObject, pickValidValues, random, removeObjectNil, rgbToHex, slugify, timestamp, toBool, toDuration, toFixed, toFloat, toInt, toInteger, toIntlNumber, toJSON, toMillisecond, toSecond, toURLParams, toURLQuery, type, unixDate, unixDiff };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from 'deep-object-diff';
|
|
2
|
+
import { IParseOptions, IStringifyOptions } from 'qs';
|
|
3
|
+
export { default as qs } from 'qs';
|
|
2
4
|
import dayjs, { QUnitType, OpUnitType } from 'dayjs';
|
|
3
5
|
import visUUID from 'validator/lib/isUUID';
|
|
6
|
+
import visFQDN from 'validator/lib/isFQDN';
|
|
4
7
|
import { IsNumericOptions } from 'validator/lib/isNumeric';
|
|
5
8
|
import { IsEmailOptions } from 'validator/lib/isEmail';
|
|
6
9
|
import { IsURLOptions } from 'validator/lib/isURL';
|
|
@@ -28,7 +31,26 @@ declare function darken(hex: string, alpha: number): string;
|
|
|
28
31
|
declare function invert(hex: string): string;
|
|
29
32
|
declare function alphaHexToRgb(hex: string, alpha: number, backgroundHex: string): number[];
|
|
30
33
|
|
|
31
|
-
declare function toBool(value: unknown, defaults?: boolean): boolean;
|
|
34
|
+
declare function toBool(value: unknown, defaults?: boolean): boolean;
|
|
35
|
+
declare const parseBool: typeof toBool;
|
|
36
|
+
declare function toInteger(value: unknown, defaults?: number, maxValue?: number): number | undefined;
|
|
37
|
+
declare const parseNumber: typeof toInteger;
|
|
38
|
+
declare const toInt: typeof toInteger;
|
|
39
|
+
declare function toFloat(value: unknown, defaults?: number, maxValue?: number): number | undefined;
|
|
40
|
+
declare function toFixed(value: number, precision?: number): string;
|
|
41
|
+
declare function toJSON<T extends object>(str: unknown, defaults?: T): T | undefined;
|
|
42
|
+
declare const parseJson: typeof toJSON;
|
|
43
|
+
declare function toIntlNumber(value: number): string;
|
|
44
|
+
interface ToDurationOptions {
|
|
45
|
+
hideOnZeroValue?: boolean;
|
|
46
|
+
padNumber?: boolean;
|
|
47
|
+
hourUnit?: string;
|
|
48
|
+
minuteUnit?: string;
|
|
49
|
+
secondUnit?: string;
|
|
50
|
+
}
|
|
51
|
+
declare function toDuration(value: number, options?: ToDurationOptions): string;
|
|
52
|
+
declare function toURLParams<T extends object>(value: string, options?: IParseOptions): T;
|
|
53
|
+
declare function toURLQuery(value: Record<string | number, any>, baseUri?: string, options?: IStringifyOptions): string;
|
|
32
54
|
|
|
33
55
|
declare function timestamp(): number;
|
|
34
56
|
declare function date(str?: string, format?: string): dayjs.Dayjs;
|
|
@@ -43,7 +65,9 @@ declare function isNumber(arg: any): boolean;
|
|
|
43
65
|
declare function isValidArray(arg: any): boolean;
|
|
44
66
|
declare function isNan(arg: any): boolean;
|
|
45
67
|
declare function isSet(arg: any): boolean;
|
|
68
|
+
declare function isWeakSet(arg: any): boolean;
|
|
46
69
|
declare function isMap(arg: any): boolean;
|
|
70
|
+
declare function isWeakMap(arg: any): boolean;
|
|
47
71
|
declare function isSymbol(arg: any): boolean;
|
|
48
72
|
declare function isObject(arg: any): boolean;
|
|
49
73
|
declare function isDate(arg: any): boolean;
|
|
@@ -65,8 +89,9 @@ declare function uniqueArray(arg: any): any[];
|
|
|
65
89
|
declare function isNumeric(arg: any, options?: IsNumericOptions): boolean;
|
|
66
90
|
declare function isURL(arg: any, options?: IsURLOptions): boolean;
|
|
67
91
|
declare function isEmail(arg: any, options?: IsEmailOptions): boolean;
|
|
68
|
-
declare const _default
|
|
92
|
+
declare const _default: {
|
|
69
93
|
isUUID: typeof visUUID;
|
|
94
|
+
isFQDN: typeof visFQDN;
|
|
70
95
|
isBoolean: typeof isBoolean;
|
|
71
96
|
isString: typeof isString;
|
|
72
97
|
isNumber: typeof isNumber;
|
|
@@ -76,6 +101,8 @@ declare const _default$1: {
|
|
|
76
101
|
isNan: typeof isNan;
|
|
77
102
|
isSet: typeof isSet;
|
|
78
103
|
isMap: typeof isMap;
|
|
104
|
+
isWeakSet: typeof isWeakSet;
|
|
105
|
+
isWeakMap: typeof isWeakMap;
|
|
79
106
|
isSymbol: typeof isSymbol;
|
|
80
107
|
isObject: typeof isObject;
|
|
81
108
|
isDate: typeof isDate;
|
|
@@ -99,7 +126,9 @@ declare const _default$1: {
|
|
|
99
126
|
};
|
|
100
127
|
|
|
101
128
|
declare function hs(arg: string): number | undefined;
|
|
102
|
-
declare function ms(arg: string): number | undefined;
|
|
129
|
+
declare function ms(arg: string): number | undefined;
|
|
130
|
+
declare const toSecond: typeof hs;
|
|
131
|
+
declare const toMillisecond: typeof ms;
|
|
103
132
|
|
|
104
133
|
declare const commonImageMimeTypes: string[];
|
|
105
134
|
declare const commonFileMimeTypes: string[];
|
|
@@ -109,27 +138,13 @@ declare function nanoid(len?: number): string;
|
|
|
109
138
|
declare function nanoidCustomAlphabet(alphabet: string, len?: number): string;
|
|
110
139
|
|
|
111
140
|
declare function pickObject(target: Record<string, any>, fields: Array<string | string[]>, excludes?: Array<string>): Record<string, any>;
|
|
141
|
+
declare function excludeObject(target: Record<string, any>, excludes?: Array<string>): Record<string, any>;
|
|
112
142
|
declare function pickValidValues<T = string | number | boolean>(target: Record<string, T>, fields: Array<string | string[]>): Record<string, T>;
|
|
113
143
|
declare function removeObjectNil(target: Record<string, any>): Record<string, any>;
|
|
114
144
|
declare function copyObjectValues(target: Record<string, any>, dist: Record<string, any>, keyMaps: Array<string | string[]>): void;
|
|
115
145
|
|
|
116
|
-
declare function parseJson(str: string, defaultValue?: any): any;
|
|
117
|
-
declare function parseBool(arg: any, defaultValue?: boolean): boolean;
|
|
118
|
-
declare function parseNumber(arg: any, defaultValue?: number, maxValue?: number): number | undefined;
|
|
119
146
|
declare function htmlToText(html: string, limit?: number): string;
|
|
120
147
|
|
|
121
|
-
interface QsOptions {
|
|
122
|
-
encode?: boolean;
|
|
123
|
-
decode?: boolean;
|
|
124
|
-
separator?: string;
|
|
125
|
-
}
|
|
126
|
-
declare function stringify(arg: Record<string, any>, options?: QsOptions): string;
|
|
127
|
-
declare function parse(str: string, options?: QsOptions): Record<string, any>;
|
|
128
|
-
declare const _default: {
|
|
129
|
-
stringify: typeof stringify;
|
|
130
|
-
parse: typeof parse;
|
|
131
|
-
};
|
|
132
|
-
|
|
133
148
|
declare enum RandomType {
|
|
134
149
|
LOWER = 0,
|
|
135
150
|
UPPER = 1,
|
|
@@ -153,4 +168,4 @@ declare function slugify(text: string, options?: SlugifyOptions): string;
|
|
|
153
168
|
|
|
154
169
|
declare function type(obj: any): string;
|
|
155
170
|
|
|
156
|
-
export { RandomType, type SlugifyOptions, alpha, alphaHexToRgb, bytes, clone, colorBrightness, commonFileMimeTypes, commonImageMimeTypes, copyObjectValues, darken, date, datePeriod, formatBytes, _default
|
|
171
|
+
export { RandomType, type SlugifyOptions, alpha, alphaHexToRgb, bytes, clone, colorBrightness, commonFileMimeTypes, commonImageMimeTypes, copyObjectValues, darken, date, datePeriod, excludeObject, formatBytes, _default as helper, hexToRgb, hs, htmlToText, invert, isDarkColor, isDateExpired, isHexColor, isLightColor, isRgb, isRgba, lighten, mime, ms, nanoid, nanoidCustomAlphabet, parseBool, parseBytes, parseJson, parseNumber, pickObject, pickValidValues, random, removeObjectNil, rgbToHex, slugify, timestamp, toBool, toDuration, toFixed, toFloat, toInt, toInteger, toIntlNumber, toJSON, toMillisecond, toSecond, toURLParams, toURLQuery, type, unixDate, unixDiff };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var deepObjectDiff = require('deep-object-diff');
|
|
4
|
+
var qs = require('qs');
|
|
4
5
|
var visUUID = require('validator/lib/isUUID');
|
|
6
|
+
var visFQDN = require('validator/lib/isFQDN');
|
|
5
7
|
var visNumeric = require('validator/lib/isNumeric');
|
|
6
8
|
var visEmail = require('validator/lib/isEmail');
|
|
7
9
|
var visURL = require('validator/lib/isURL');
|
|
8
10
|
var _clone = require('clone');
|
|
11
|
+
var vms = require('ms');
|
|
9
12
|
var dayjs = require('dayjs');
|
|
10
13
|
var m = require('mime-types');
|
|
11
14
|
var nanoid$1 = require('nanoid');
|
|
@@ -34,11 +37,14 @@ function _interopNamespace(e) {
|
|
|
34
37
|
return Object.freeze(n);
|
|
35
38
|
}
|
|
36
39
|
|
|
40
|
+
var qs__default = /*#__PURE__*/_interopDefault(qs);
|
|
37
41
|
var visUUID__default = /*#__PURE__*/_interopDefault(visUUID);
|
|
42
|
+
var visFQDN__default = /*#__PURE__*/_interopDefault(visFQDN);
|
|
38
43
|
var visNumeric__default = /*#__PURE__*/_interopDefault(visNumeric);
|
|
39
44
|
var visEmail__default = /*#__PURE__*/_interopDefault(visEmail);
|
|
40
45
|
var visURL__default = /*#__PURE__*/_interopDefault(visURL);
|
|
41
46
|
var _clone__default = /*#__PURE__*/_interopDefault(_clone);
|
|
47
|
+
var vms__default = /*#__PURE__*/_interopDefault(vms);
|
|
42
48
|
var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
|
|
43
49
|
var m__namespace = /*#__PURE__*/_interopNamespace(m);
|
|
44
50
|
var objectPath__namespace = /*#__PURE__*/_interopNamespace(objectPath);
|
|
@@ -70,6 +76,7 @@ function type(obj) {
|
|
|
70
76
|
// src/helper.ts
|
|
71
77
|
var whiteSpaceRegx = /^[\s\f\n\r\t\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\x09\x0a\x0b\x0c\x0d\x20\xa0]+$/;
|
|
72
78
|
var isUUID = visUUID__default.default;
|
|
79
|
+
var isFQDN = visFQDN__default.default;
|
|
73
80
|
function isBoolean(arg) {
|
|
74
81
|
return type(arg) === "boolean";
|
|
75
82
|
}
|
|
@@ -89,9 +96,15 @@ function isNan(arg) {
|
|
|
89
96
|
function isSet(arg) {
|
|
90
97
|
return type(arg) === "set";
|
|
91
98
|
}
|
|
99
|
+
function isWeakSet(arg) {
|
|
100
|
+
return type(arg) === "weakset";
|
|
101
|
+
}
|
|
92
102
|
function isMap(arg) {
|
|
93
103
|
return type(arg) === "map";
|
|
94
104
|
}
|
|
105
|
+
function isWeakMap(arg) {
|
|
106
|
+
return type(arg) === "weakmap";
|
|
107
|
+
}
|
|
95
108
|
function isSymbol(arg) {
|
|
96
109
|
return type(arg) === "symbol";
|
|
97
110
|
}
|
|
@@ -189,6 +202,7 @@ function isEmail(arg, options) {
|
|
|
189
202
|
}
|
|
190
203
|
var helper_default = {
|
|
191
204
|
isUUID,
|
|
205
|
+
isFQDN,
|
|
192
206
|
isBoolean,
|
|
193
207
|
isString,
|
|
194
208
|
isNumber,
|
|
@@ -198,6 +212,8 @@ var helper_default = {
|
|
|
198
212
|
isNan,
|
|
199
213
|
isSet,
|
|
200
214
|
isMap,
|
|
215
|
+
isWeakSet,
|
|
216
|
+
isWeakMap,
|
|
201
217
|
isSymbol,
|
|
202
218
|
isObject,
|
|
203
219
|
isDate,
|
|
@@ -381,8 +397,6 @@ function hexToFloatAlpha(arg) {
|
|
|
381
397
|
const max = parseInt("0xff", 16);
|
|
382
398
|
return Number((num / max).toFixed(2));
|
|
383
399
|
}
|
|
384
|
-
|
|
385
|
-
// src/conv.ts
|
|
386
400
|
function toBool(value, defaults) {
|
|
387
401
|
if (isEmpty(value)) {
|
|
388
402
|
return defaults || false;
|
|
@@ -392,53 +406,131 @@ function toBool(value, defaults) {
|
|
|
392
406
|
}
|
|
393
407
|
return isTrue(value);
|
|
394
408
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
var year = day * 365;
|
|
403
|
-
var regx2 = /^(-?(?:\d+)?\.?\d+)(s|m|h|d|w|y)$/i;
|
|
404
|
-
function parse(arg) {
|
|
405
|
-
if (isEmpty(arg)) {
|
|
406
|
-
return;
|
|
409
|
+
var parseBool = toBool;
|
|
410
|
+
function toInteger(value, defaults, maxValue) {
|
|
411
|
+
let val;
|
|
412
|
+
if (isNumber(value)) {
|
|
413
|
+
val = Number(value);
|
|
414
|
+
} else {
|
|
415
|
+
val = parseInt(value, 10);
|
|
407
416
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
417
|
+
if (!isFinite(val)) {
|
|
418
|
+
return defaults;
|
|
419
|
+
}
|
|
420
|
+
return maxValue ? Math.min(maxValue, val) : val;
|
|
421
|
+
}
|
|
422
|
+
var parseNumber = toInteger;
|
|
423
|
+
var toInt = toInteger;
|
|
424
|
+
function toFloat(value, defaults, maxValue) {
|
|
425
|
+
let val;
|
|
426
|
+
if (isNumber(value)) {
|
|
427
|
+
val = Number(value);
|
|
428
|
+
} else {
|
|
429
|
+
val = parseFloat(value);
|
|
430
|
+
}
|
|
431
|
+
if (!isFinite(val)) {
|
|
432
|
+
return defaults;
|
|
433
|
+
}
|
|
434
|
+
return maxValue ? Math.min(maxValue, val) : val;
|
|
435
|
+
}
|
|
436
|
+
function toFixed(value, precision = 2) {
|
|
437
|
+
return value.toFixed(precision).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
|
|
438
|
+
}
|
|
439
|
+
function toJSON(str, defaults) {
|
|
440
|
+
let value;
|
|
441
|
+
if (isValid(str) && isString(str)) {
|
|
442
|
+
try {
|
|
443
|
+
value = JSON.parse(str);
|
|
444
|
+
} catch (e) {
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (!!defaults && !value) {
|
|
448
|
+
value = defaults;
|
|
449
|
+
}
|
|
450
|
+
return value;
|
|
451
|
+
}
|
|
452
|
+
var parseJson = toJSON;
|
|
453
|
+
var THOUSAND = 1e3;
|
|
454
|
+
var HUNDRED_THOUSAND = 1e5;
|
|
455
|
+
var MILLION = 1e6;
|
|
456
|
+
var HUNDRED_MILLION = 1e8;
|
|
457
|
+
var BILLION = 1e9;
|
|
458
|
+
var HUNDRED_BILLION = 1e11;
|
|
459
|
+
var TRILLION = 1e12;
|
|
460
|
+
function toIntlNumber(value) {
|
|
461
|
+
if (value >= THOUSAND && value < MILLION) {
|
|
462
|
+
const thousands = value / THOUSAND;
|
|
463
|
+
if (thousands === Math.floor(thousands) || value >= HUNDRED_THOUSAND) {
|
|
464
|
+
return Math.floor(thousands) + "K";
|
|
465
|
+
} else {
|
|
466
|
+
return Math.floor(thousands * 10) / 10 + "K";
|
|
467
|
+
}
|
|
468
|
+
} else if (value >= MILLION && value < BILLION) {
|
|
469
|
+
const millions = value / MILLION;
|
|
470
|
+
if (millions === Math.floor(millions) || value >= HUNDRED_MILLION) {
|
|
471
|
+
return Math.floor(millions) + "M";
|
|
472
|
+
} else {
|
|
473
|
+
return Math.floor(millions * 10) / 10 + "M";
|
|
474
|
+
}
|
|
475
|
+
} else if (value >= BILLION && value < TRILLION) {
|
|
476
|
+
const billions = value / BILLION;
|
|
477
|
+
if (billions === Math.floor(billions) || value >= HUNDRED_BILLION) {
|
|
478
|
+
return Math.floor(billions) + "B";
|
|
479
|
+
} else {
|
|
480
|
+
return Math.floor(billions * 10) / 10 + "B";
|
|
481
|
+
}
|
|
482
|
+
} else {
|
|
483
|
+
return `${value}`;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
function durationPad(num, size) {
|
|
487
|
+
return ("000" + num).slice(size * -1);
|
|
488
|
+
}
|
|
489
|
+
function getDuration(num, unit, options) {
|
|
490
|
+
if (options?.hideOnZeroValue && num === 0) {
|
|
411
491
|
return;
|
|
412
492
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
switch (type2) {
|
|
416
|
-
case "y":
|
|
417
|
-
return num * year;
|
|
418
|
-
case "w":
|
|
419
|
-
return num * week;
|
|
420
|
-
case "d":
|
|
421
|
-
return num * day;
|
|
422
|
-
case "h":
|
|
423
|
-
return num * hour;
|
|
424
|
-
case "m":
|
|
425
|
-
return num * minute;
|
|
426
|
-
case "s":
|
|
427
|
-
return num * second;
|
|
493
|
+
if (options?.padNumber) {
|
|
494
|
+
return durationPad(num, 2) + unit;
|
|
428
495
|
}
|
|
496
|
+
return num + unit;
|
|
497
|
+
}
|
|
498
|
+
function toDuration(value, options) {
|
|
499
|
+
const hours = Math.floor(value / 60 / 60);
|
|
500
|
+
const minutes = Math.floor(value / 60) % 60;
|
|
501
|
+
const seconds = Math.floor(value - minutes * 60 - hours * 60 * 60);
|
|
502
|
+
return [
|
|
503
|
+
hours > 0 ? { num: hours, unit: options?.hourUnit || "h" } : null,
|
|
504
|
+
minutes > 0 ? { num: minutes, unit: options?.minuteUnit || "m" } : null,
|
|
505
|
+
{ num: seconds, unit: options?.secondUnit || "s" }
|
|
506
|
+
].filter(Boolean).map(
|
|
507
|
+
(d, i) => getDuration(d.num, d.unit, {
|
|
508
|
+
...options,
|
|
509
|
+
hideOnZeroValue: i === 0 ? false : options?.hideOnZeroValue
|
|
510
|
+
})
|
|
511
|
+
).filter(Boolean).join(" ");
|
|
512
|
+
}
|
|
513
|
+
function toURLParams(value, options) {
|
|
514
|
+
return qs.parse(value, options);
|
|
515
|
+
}
|
|
516
|
+
function toURLQuery(value, baseUri, options) {
|
|
517
|
+
const query = qs.stringify(value, options);
|
|
518
|
+
if (baseUri) {
|
|
519
|
+
return baseUri + (baseUri.includes("?") ? "&" : "?") + query;
|
|
520
|
+
}
|
|
521
|
+
return query;
|
|
429
522
|
}
|
|
430
523
|
function hs(arg) {
|
|
431
|
-
const value =
|
|
524
|
+
const value = ms(arg);
|
|
432
525
|
if (value) {
|
|
433
|
-
return Math.round(value);
|
|
526
|
+
return Math.round(value / 1e3);
|
|
434
527
|
}
|
|
435
528
|
}
|
|
436
529
|
function ms(arg) {
|
|
437
|
-
|
|
438
|
-
if (value) {
|
|
439
|
-
return value * 1e3;
|
|
440
|
-
}
|
|
530
|
+
return vms__default.default(arg);
|
|
441
531
|
}
|
|
532
|
+
var toSecond = hs;
|
|
533
|
+
var toMillisecond = ms;
|
|
442
534
|
function timestamp() {
|
|
443
535
|
return Math.floor(Date.now() / 1e3);
|
|
444
536
|
}
|
|
@@ -528,6 +620,9 @@ function pickObject(target, fields, excludes = []) {
|
|
|
528
620
|
});
|
|
529
621
|
return newObj;
|
|
530
622
|
}
|
|
623
|
+
function excludeObject(target, excludes = []) {
|
|
624
|
+
return pickObject(target, [], excludes);
|
|
625
|
+
}
|
|
531
626
|
function pickValidValues(target, fields) {
|
|
532
627
|
const dist = {};
|
|
533
628
|
fields.forEach((field) => {
|
|
@@ -589,42 +684,6 @@ function copyObjectValues(target, dist, keyMaps) {
|
|
|
589
684
|
}
|
|
590
685
|
|
|
591
686
|
// src/parse.ts
|
|
592
|
-
function parseJson(str, defaultValue) {
|
|
593
|
-
let value;
|
|
594
|
-
try {
|
|
595
|
-
value = JSON.parse(str);
|
|
596
|
-
} catch (e) {
|
|
597
|
-
}
|
|
598
|
-
if (defaultValue && !value) {
|
|
599
|
-
value = defaultValue;
|
|
600
|
-
}
|
|
601
|
-
return value;
|
|
602
|
-
}
|
|
603
|
-
function parseBool(arg, defaultValue) {
|
|
604
|
-
if (isEmpty(arg)) {
|
|
605
|
-
return defaultValue || false;
|
|
606
|
-
}
|
|
607
|
-
if (isBoolean(arg)) {
|
|
608
|
-
return arg;
|
|
609
|
-
}
|
|
610
|
-
return isTrue(arg);
|
|
611
|
-
}
|
|
612
|
-
function parseNumber(arg, defaultValue, maxValue) {
|
|
613
|
-
if (isNumber(arg)) {
|
|
614
|
-
if (maxValue && maxValue < Number(arg)) {
|
|
615
|
-
return maxValue;
|
|
616
|
-
}
|
|
617
|
-
return Number(arg);
|
|
618
|
-
}
|
|
619
|
-
const num = parseInt(arg, 10);
|
|
620
|
-
if (isNaN(num)) {
|
|
621
|
-
return defaultValue;
|
|
622
|
-
}
|
|
623
|
-
if (maxValue && maxValue < num) {
|
|
624
|
-
return maxValue;
|
|
625
|
-
}
|
|
626
|
-
return num;
|
|
627
|
-
}
|
|
628
687
|
function htmlToText(html, limit = 100) {
|
|
629
688
|
let result = html.replace(/<style[^<>]*>((?!<\/).)*<\/style>/gi, "").replace(/<script[^<>]*>((?!<\/).)*<\/script>/gi, "").replace(/<[^>]+>/g, "").replace(/\t|\r|\n|\r\n/g, "").replace(/\s+/g, "").replace(/ /g, " ").replace(/"/g, '"').replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
630
689
|
if (limit > 0) {
|
|
@@ -633,48 +692,6 @@ function htmlToText(html, limit = 100) {
|
|
|
633
692
|
return result;
|
|
634
693
|
}
|
|
635
694
|
|
|
636
|
-
// src/qs.ts
|
|
637
|
-
function stringify(arg, options) {
|
|
638
|
-
const arr = [];
|
|
639
|
-
Object.keys(arg).forEach((key) => {
|
|
640
|
-
let val = arg[key];
|
|
641
|
-
if (isEmpty(val)) {
|
|
642
|
-
val = "";
|
|
643
|
-
} else {
|
|
644
|
-
val = String(val);
|
|
645
|
-
}
|
|
646
|
-
if (options?.encode) {
|
|
647
|
-
val = encodeURIComponent(val);
|
|
648
|
-
}
|
|
649
|
-
arr.push(`${key}=${val}`);
|
|
650
|
-
});
|
|
651
|
-
return arr.join("&");
|
|
652
|
-
}
|
|
653
|
-
function parse2(str, options) {
|
|
654
|
-
const obj = {};
|
|
655
|
-
if (!isString(str)) {
|
|
656
|
-
return obj;
|
|
657
|
-
}
|
|
658
|
-
const arr = str.replace(/^([^?]+)?\?/, "").split("&");
|
|
659
|
-
arr.forEach((param) => {
|
|
660
|
-
const paramArr = param.split("=");
|
|
661
|
-
const key = paramArr[0];
|
|
662
|
-
if (!isEmpty(key)) {
|
|
663
|
-
let val = paramArr[1];
|
|
664
|
-
if (options?.decode) {
|
|
665
|
-
val = decodeURIComponent(val);
|
|
666
|
-
}
|
|
667
|
-
val = options?.separator && val.includes(options?.separator) ? val.split(options?.separator) : val;
|
|
668
|
-
obj[key] = val;
|
|
669
|
-
}
|
|
670
|
-
});
|
|
671
|
-
return obj;
|
|
672
|
-
}
|
|
673
|
-
var qs_default = {
|
|
674
|
-
stringify,
|
|
675
|
-
parse: parse2
|
|
676
|
-
};
|
|
677
|
-
|
|
678
695
|
// src/random.ts
|
|
679
696
|
var numeric = "0123456789";
|
|
680
697
|
var hexic = "0123456789abcdef";
|
|
@@ -731,6 +748,10 @@ function slugify(text, options) {
|
|
|
731
748
|
});
|
|
732
749
|
}
|
|
733
750
|
|
|
751
|
+
Object.defineProperty(exports, "qs", {
|
|
752
|
+
enumerable: true,
|
|
753
|
+
get: function () { return qs__default.default; }
|
|
754
|
+
});
|
|
734
755
|
Object.defineProperty(exports, "deepEqual", {
|
|
735
756
|
enumerable: true,
|
|
736
757
|
get: function () { return fastEquals.deepEqual; }
|
|
@@ -755,6 +776,7 @@ exports.copyObjectValues = copyObjectValues;
|
|
|
755
776
|
exports.darken = darken;
|
|
756
777
|
exports.date = date;
|
|
757
778
|
exports.datePeriod = datePeriod;
|
|
779
|
+
exports.excludeObject = excludeObject;
|
|
758
780
|
exports.formatBytes = formatBytes;
|
|
759
781
|
exports.helper = helper_default;
|
|
760
782
|
exports.hexToRgb = hexToRgb;
|
|
@@ -778,13 +800,23 @@ exports.parseJson = parseJson;
|
|
|
778
800
|
exports.parseNumber = parseNumber;
|
|
779
801
|
exports.pickObject = pickObject;
|
|
780
802
|
exports.pickValidValues = pickValidValues;
|
|
781
|
-
exports.qs = qs_default;
|
|
782
803
|
exports.random = random;
|
|
783
804
|
exports.removeObjectNil = removeObjectNil;
|
|
784
805
|
exports.rgbToHex = rgbToHex;
|
|
785
806
|
exports.slugify = slugify;
|
|
786
807
|
exports.timestamp = timestamp;
|
|
787
808
|
exports.toBool = toBool;
|
|
809
|
+
exports.toDuration = toDuration;
|
|
810
|
+
exports.toFixed = toFixed;
|
|
811
|
+
exports.toFloat = toFloat;
|
|
812
|
+
exports.toInt = toInt;
|
|
813
|
+
exports.toInteger = toInteger;
|
|
814
|
+
exports.toIntlNumber = toIntlNumber;
|
|
815
|
+
exports.toJSON = toJSON;
|
|
816
|
+
exports.toMillisecond = toMillisecond;
|
|
817
|
+
exports.toSecond = toSecond;
|
|
818
|
+
exports.toURLParams = toURLParams;
|
|
819
|
+
exports.toURLQuery = toURLQuery;
|
|
788
820
|
exports.type = type;
|
|
789
821
|
exports.unixDate = unixDate;
|
|
790
822
|
exports.unixDiff = unixDiff;
|