@heyform-inc/utils 1.2.0 → 1.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  export * from 'deep-object-diff';
2
2
  import { IParseOptions, IStringifyOptions } from 'qs';
3
3
  export { default as qs } from 'qs';
4
- import dayjs, { QUnitType, OpUnitType } from 'dayjs';
4
+ import _dayjs, { QUnitType, OpUnitType } from 'dayjs';
5
5
  import _isUUID from 'validator/lib/isUUID';
6
6
  import _isFQDN from 'validator/lib/isFQDN';
7
7
  import { IsNumericOptions } from 'validator/lib/isNumeric';
@@ -36,7 +36,7 @@ declare function toInteger(value: unknown, defaults?: number, maxValue?: number)
36
36
  declare const parseNumber: typeof toInteger;
37
37
  declare const toInt: typeof toInteger;
38
38
  declare function toFloat(value: unknown, defaults?: number, maxValue?: number): number | undefined;
39
- declare function toFixed(value: number, precision?: number): string;
39
+ declare function toFixed(value: number, precision?: number): string | undefined;
40
40
  declare function toJSON<T extends object>(str: unknown, defaults?: T): T | undefined;
41
41
  declare const parseJson: typeof toJSON;
42
42
  declare function toIntlNumber(value: number): string;
@@ -53,8 +53,9 @@ declare function toURLQuery(value: Record<string | number, any>, baseUri?: strin
53
53
  declare function htmlToText(html: string, limit?: number): string;
54
54
 
55
55
  declare function timestamp(): number;
56
- declare function date(str?: string, format?: string): dayjs.Dayjs;
57
- declare function unixDate(t: number): dayjs.Dayjs;
56
+ declare const dayjs: typeof _dayjs;
57
+ declare const date: typeof _dayjs;
58
+ declare function unixDate(t: number): _dayjs.Dayjs;
58
59
  declare function isDateExpired(start: number, end: number, expire: string): boolean;
59
60
  declare function unixDiff(start: number, end: number, unit?: QUnitType | OpUnitType): number;
60
61
  declare function datePeriod(start: number, value?: number, unit?: OpUnitType): number;
@@ -168,4 +169,4 @@ declare function slugify(text: string, options?: SlugifyOptions): string;
168
169
 
169
170
  declare function type(obj: any): string;
170
171
 
171
- export { FILE_MIME_TYPES, IMAGE_MIME_TYPES, 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 };
172
+ export { FILE_MIME_TYPES, IMAGE_MIME_TYPES, RandomType, type SlugifyOptions, alpha, alphaHexToRgb, bytes, clone, colorBrightness, commonFileMimeTypes, commonImageMimeTypes, copyObjectValues, darken, date, datePeriod, dayjs, 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,7 +1,7 @@
1
1
  export * from 'deep-object-diff';
2
2
  import { IParseOptions, IStringifyOptions } from 'qs';
3
3
  export { default as qs } from 'qs';
4
- import dayjs, { QUnitType, OpUnitType } from 'dayjs';
4
+ import _dayjs, { QUnitType, OpUnitType } from 'dayjs';
5
5
  import _isUUID from 'validator/lib/isUUID';
6
6
  import _isFQDN from 'validator/lib/isFQDN';
7
7
  import { IsNumericOptions } from 'validator/lib/isNumeric';
@@ -36,7 +36,7 @@ declare function toInteger(value: unknown, defaults?: number, maxValue?: number)
36
36
  declare const parseNumber: typeof toInteger;
37
37
  declare const toInt: typeof toInteger;
38
38
  declare function toFloat(value: unknown, defaults?: number, maxValue?: number): number | undefined;
39
- declare function toFixed(value: number, precision?: number): string;
39
+ declare function toFixed(value: number, precision?: number): string | undefined;
40
40
  declare function toJSON<T extends object>(str: unknown, defaults?: T): T | undefined;
41
41
  declare const parseJson: typeof toJSON;
42
42
  declare function toIntlNumber(value: number): string;
@@ -53,8 +53,9 @@ declare function toURLQuery(value: Record<string | number, any>, baseUri?: strin
53
53
  declare function htmlToText(html: string, limit?: number): string;
54
54
 
55
55
  declare function timestamp(): number;
56
- declare function date(str?: string, format?: string): dayjs.Dayjs;
57
- declare function unixDate(t: number): dayjs.Dayjs;
56
+ declare const dayjs: typeof _dayjs;
57
+ declare const date: typeof _dayjs;
58
+ declare function unixDate(t: number): _dayjs.Dayjs;
58
59
  declare function isDateExpired(start: number, end: number, expire: string): boolean;
59
60
  declare function unixDiff(start: number, end: number, unit?: QUnitType | OpUnitType): number;
60
61
  declare function datePeriod(start: number, value?: number, unit?: OpUnitType): number;
@@ -168,4 +169,4 @@ declare function slugify(text: string, options?: SlugifyOptions): string;
168
169
 
169
170
  declare function type(obj: any): string;
170
171
 
171
- export { FILE_MIME_TYPES, IMAGE_MIME_TYPES, 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 };
172
+ export { FILE_MIME_TYPES, IMAGE_MIME_TYPES, RandomType, type SlugifyOptions, alpha, alphaHexToRgb, bytes, clone, colorBrightness, commonFileMimeTypes, commonImageMimeTypes, copyObjectValues, darken, date, datePeriod, dayjs, 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
@@ -10,7 +10,7 @@ var _isURL = require('validator/lib/isURL');
10
10
  var _clone = require('clone');
11
11
  var htmlToText$1 = require('html-to-text');
12
12
  var _ms = require('ms');
13
- var dayjs = require('dayjs');
13
+ var _dayjs = require('dayjs');
14
14
  var nanoid$1 = require('nanoid');
15
15
  var objectPath = require('object-path');
16
16
  var fastEquals = require('fast-equals');
@@ -45,7 +45,7 @@ var _isEmail__default = /*#__PURE__*/_interopDefault(_isEmail);
45
45
  var _isURL__default = /*#__PURE__*/_interopDefault(_isURL);
46
46
  var _clone__default = /*#__PURE__*/_interopDefault(_clone);
47
47
  var _ms__default = /*#__PURE__*/_interopDefault(_ms);
48
- var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
48
+ var _dayjs__default = /*#__PURE__*/_interopDefault(_dayjs);
49
49
  var objectPath__namespace = /*#__PURE__*/_interopNamespace(objectPath);
50
50
  var slug__default = /*#__PURE__*/_interopDefault(slug);
51
51
 
@@ -433,7 +433,9 @@ function toFloat(value, defaults, maxValue) {
433
433
  return maxValue ? Math.min(maxValue, val) : val;
434
434
  }
435
435
  function toFixed(value, precision = 2) {
436
- return value.toFixed(precision).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
436
+ if (isNumber(value)) {
437
+ return value.toFixed(precision).replace(/(\.\d*?)0+$/, "$1").replace(/\.$/, "");
438
+ }
437
439
  }
438
440
  function toJSON(str, defaults) {
439
441
  let value;
@@ -549,11 +551,10 @@ var toMillisecond = ms;
549
551
  function timestamp() {
550
552
  return Math.floor(Date.now() / 1e3);
551
553
  }
552
- function date(str, format) {
553
- return dayjs__default.default(str, format);
554
- }
554
+ var dayjs = _dayjs__default.default;
555
+ var date = dayjs;
555
556
  function unixDate(t) {
556
- return dayjs__default.default.unix(t);
557
+ return date.unix(t);
557
558
  }
558
559
  function isDateExpired(start, end, expire) {
559
560
  return end - start > hs(expire);
@@ -1984,6 +1985,7 @@ exports.copyObjectValues = copyObjectValues;
1984
1985
  exports.darken = darken;
1985
1986
  exports.date = date;
1986
1987
  exports.datePeriod = datePeriod;
1988
+ exports.dayjs = dayjs;
1987
1989
  exports.excludeObject = excludeObject;
1988
1990
  exports.formatBytes = formatBytes;
1989
1991
  exports.helper = helper_default;