@heyform-inc/utils 1.2.2 → 1.3.1

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,12 +1,13 @@
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';
5
- import _isUUID from 'validator/lib/isUUID';
4
+ import { ClassValue } from 'clsx';
5
+ import _dayjs, { OpUnitType, QUnitType } from 'dayjs';
6
+ import { IsEmailOptions } from 'validator/lib/isEmail';
6
7
  import _isFQDN from 'validator/lib/isFQDN';
7
8
  import { IsNumericOptions } from 'validator/lib/isNumeric';
8
- import { IsEmailOptions } from 'validator/lib/isEmail';
9
9
  import { IsURLOptions } from 'validator/lib/isURL';
10
+ import _isUUID from 'validator/lib/isUUID';
10
11
  export { v4 as uuidv4, v5 as uuidv5 } from 'uuid';
11
12
  export { deepEqual } from 'fast-equals';
12
13
 
@@ -16,6 +17,8 @@ declare function formatBytes(value: string | number): string;
16
17
 
17
18
  declare function clone<T>(obj: T): T;
18
19
 
20
+ declare function clsx(...inputs: ClassValue[]): string;
21
+
19
22
  declare function isHexColor(color: string): boolean;
20
23
  declare function isRgba(color: string): boolean;
21
24
  declare function isRgb(color: string): boolean;
@@ -60,6 +63,151 @@ declare function isDateExpired(start: number, end: number, expire: string): bool
60
63
  declare function unixDiff(start: number, end: number, unit?: QUnitType | OpUnitType): number;
61
64
  declare function datePeriod(start: number, value?: number, unit?: OpUnitType): number;
62
65
 
66
+ declare enum HttpStatus {
67
+ CONTINUE = 100,
68
+ SWITCHING_PROTOCOLS = 101,
69
+ PROCESSING = 102,
70
+ EARLYHINTS = 103,
71
+ OK = 200,
72
+ CREATED = 201,
73
+ ACCEPTED = 202,
74
+ NON_AUTHORITATIVE_INFORMATION = 203,
75
+ NO_CONTENT = 204,
76
+ RESET_CONTENT = 205,
77
+ PARTIAL_CONTENT = 206,
78
+ MULTI_STATUS = 207,
79
+ ALREADY_REPORTED = 208,
80
+ CONTENT_DIFFERENT = 210,
81
+ AMBIGUOUS = 300,
82
+ MOVED_PERMANENTLY = 301,
83
+ FOUND = 302,
84
+ SEE_OTHER = 303,
85
+ NOT_MODIFIED = 304,
86
+ TEMPORARY_REDIRECT = 307,
87
+ PERMANENT_REDIRECT = 308,
88
+ BAD_REQUEST = 400,
89
+ UNAUTHORIZED = 401,
90
+ PAYMENT_REQUIRED = 402,
91
+ FORBIDDEN = 403,
92
+ NOT_FOUND = 404,
93
+ METHOD_NOT_ALLOWED = 405,
94
+ NOT_ACCEPTABLE = 406,
95
+ PROXY_AUTHENTICATION_REQUIRED = 407,
96
+ REQUEST_TIMEOUT = 408,
97
+ CONFLICT = 409,
98
+ GONE = 410,
99
+ LENGTH_REQUIRED = 411,
100
+ PRECONDITION_FAILED = 412,
101
+ PAYLOAD_TOO_LARGE = 413,
102
+ URI_TOO_LONG = 414,
103
+ UNSUPPORTED_MEDIA_TYPE = 415,
104
+ REQUESTED_RANGE_NOT_SATISFIABLE = 416,
105
+ EXPECTATION_FAILED = 417,
106
+ I_AM_A_TEAPOT = 418,
107
+ MISDIRECTED = 421,
108
+ UNPROCESSABLE_ENTITY = 422,
109
+ LOCKED = 423,
110
+ FAILED_DEPENDENCY = 424,
111
+ PRECONDITION_REQUIRED = 428,
112
+ TOO_MANY_REQUESTS = 429,
113
+ UNRECOVERABLE_ERROR = 456,
114
+ INTERNAL_SERVER_ERROR = 500,
115
+ NOT_IMPLEMENTED = 501,
116
+ BAD_GATEWAY = 502,
117
+ SERVICE_UNAVAILABLE = 503,
118
+ GATEWAY_TIMEOUT = 504,
119
+ HTTP_VERSION_NOT_SUPPORTED = 505,
120
+ INSUFFICIENT_STORAGE = 507,
121
+ LOOP_DETECTED = 508
122
+ }
123
+ interface Options {
124
+ status: HttpStatus;
125
+ code?: string;
126
+ errors?: Array<{
127
+ path?: string;
128
+ message: string;
129
+ }>;
130
+ }
131
+ declare class HttpError extends Error {
132
+ readonly status: HttpStatus;
133
+ readonly code: string;
134
+ readonly errors?: Options['errors'];
135
+ constructor(message: string, { status, code, errors }: Options);
136
+ getStatus(): number;
137
+ getCode(): string;
138
+ getErrors(): Array<{
139
+ path?: string;
140
+ message: string;
141
+ }> | undefined;
142
+ toJSON(): Record<string, any>;
143
+ }
144
+ declare class BadGatewayError extends HttpError {
145
+ constructor(message?: string, code?: string, errors?: Options['errors']);
146
+ }
147
+ declare class BadRequestError extends HttpError {
148
+ constructor(message?: string, code?: string, errors?: Options['errors']);
149
+ }
150
+ declare class ConflictError extends HttpError {
151
+ constructor(message?: string, code?: string, errors?: Options['errors']);
152
+ }
153
+ declare class ForbiddenError extends HttpError {
154
+ constructor(message?: string, code?: string, errors?: Options['errors']);
155
+ }
156
+ declare class TooManyRequestsError extends HttpError {
157
+ constructor(message?: string, code?: string, errors?: Options['errors']);
158
+ }
159
+ declare class GatewayTimeoutError extends HttpError {
160
+ constructor(message?: string, code?: string, errors?: Options['errors']);
161
+ }
162
+ declare class GoneError extends HttpError {
163
+ constructor(message?: string, code?: string, errors?: Options['errors']);
164
+ }
165
+ declare class HttpVersionNotSupportedError extends HttpError {
166
+ constructor(message?: string, code?: string, errors?: Options['errors']);
167
+ }
168
+ declare class ImATeapotError extends HttpError {
169
+ constructor(message?: string, code?: string, errors?: Options['errors']);
170
+ }
171
+ declare class InternalServerError extends HttpError {
172
+ constructor(message?: string, code?: string, errors?: Options['errors']);
173
+ }
174
+ declare class MethodNotAllowedError extends HttpError {
175
+ constructor(message?: string, code?: string, errors?: Options['errors']);
176
+ }
177
+ declare class MisdirectedError extends HttpError {
178
+ constructor(message?: string, code?: string, errors?: Options['errors']);
179
+ }
180
+ declare class NotAcceptableError extends HttpError {
181
+ constructor(message?: string, code?: string, errors?: Options['errors']);
182
+ }
183
+ declare class NotFoundError extends HttpError {
184
+ constructor(message?: string, code?: string, errors?: Options['errors']);
185
+ }
186
+ declare class NotImplementedError extends HttpError {
187
+ constructor(message?: string, code?: string, errors?: Options['errors']);
188
+ }
189
+ declare class PayloadTooLargeError extends HttpError {
190
+ constructor(message?: string, code?: string, errors?: Options['errors']);
191
+ }
192
+ declare class PreconditionFailedError extends HttpError {
193
+ constructor(message?: string, code?: string, errors?: Options['errors']);
194
+ }
195
+ declare class RequestTimeoutError extends HttpError {
196
+ constructor(message?: string, code?: string, errors?: Options['errors']);
197
+ }
198
+ declare class ServiceUnavailableError extends HttpError {
199
+ constructor(message?: string, code?: string, errors?: Options['errors']);
200
+ }
201
+ declare class UnauthorizedError extends HttpError {
202
+ constructor(message?: string, code?: string, errors?: Options['errors']);
203
+ }
204
+ declare class UnprocessableEntityError extends HttpError {
205
+ constructor(message?: string, code?: string, errors?: Options['errors']);
206
+ }
207
+ declare class UnsupportedMediaTypeError extends HttpError {
208
+ constructor(message?: string, code?: string, errors?: Options['errors']);
209
+ }
210
+
63
211
  declare function isBoolean(arg: any): boolean;
64
212
  declare function isString(arg: any): boolean;
65
213
  declare function isNumber(arg: any): boolean;
@@ -146,16 +294,11 @@ declare function pickValidValues<T = string | number | boolean>(target: Record<s
146
294
  declare function removeObjectNil(target: Record<string, any>): Record<string, any>;
147
295
  declare function copyObjectValues(target: Record<string, any>, dist: Record<string, any>, keyMaps: Array<string | string[]>): void;
148
296
 
149
- declare enum RandomType {
150
- LOWER = 0,
151
- UPPER = 1,
152
- NUMERIC = 2,
153
- HEXIC = 3,
154
- LOWER_NUMERIC = 4,
155
- UPPER_NUMERIC = 5,
156
- ALPHANUMERIC = 6
157
- }
158
- declare function random(len?: number, type?: RandomType): string;
297
+ declare function random(len?: number, alphabet?: string): string;
298
+ declare function randomHexic(len: number): string;
299
+ declare function randomAlpha(len: number): string;
300
+ declare function randomNumeric(len: number): string;
301
+ declare function randomNumber(min: number, max: number): number;
159
302
 
160
303
  interface SlugifyOptions {
161
304
  replacement?: string;
@@ -169,4 +312,4 @@ declare function slugify(text: string, options?: SlugifyOptions): string;
169
312
 
170
313
  declare function type(obj: any): string;
171
314
 
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 };
315
+ export { BadGatewayError, BadRequestError, ConflictError, FILE_MIME_TYPES, ForbiddenError, GatewayTimeoutError, GoneError, HttpError, HttpStatus, HttpVersionNotSupportedError, IMAGE_MIME_TYPES, ImATeapotError, InternalServerError, MethodNotAllowedError, MisdirectedError, NotAcceptableError, NotFoundError, NotImplementedError, PayloadTooLargeError, PreconditionFailedError, RequestTimeoutError, ServiceUnavailableError, type SlugifyOptions, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, UnsupportedMediaTypeError, alpha, alphaHexToRgb, bytes, clone, clsx, 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, randomAlpha, randomHexic, randomNumber, randomNumeric, 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,12 +1,13 @@
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';
5
- import _isUUID from 'validator/lib/isUUID';
4
+ import { ClassValue } from 'clsx';
5
+ import _dayjs, { OpUnitType, QUnitType } from 'dayjs';
6
+ import { IsEmailOptions } from 'validator/lib/isEmail';
6
7
  import _isFQDN from 'validator/lib/isFQDN';
7
8
  import { IsNumericOptions } from 'validator/lib/isNumeric';
8
- import { IsEmailOptions } from 'validator/lib/isEmail';
9
9
  import { IsURLOptions } from 'validator/lib/isURL';
10
+ import _isUUID from 'validator/lib/isUUID';
10
11
  export { v4 as uuidv4, v5 as uuidv5 } from 'uuid';
11
12
  export { deepEqual } from 'fast-equals';
12
13
 
@@ -16,6 +17,8 @@ declare function formatBytes(value: string | number): string;
16
17
 
17
18
  declare function clone<T>(obj: T): T;
18
19
 
20
+ declare function clsx(...inputs: ClassValue[]): string;
21
+
19
22
  declare function isHexColor(color: string): boolean;
20
23
  declare function isRgba(color: string): boolean;
21
24
  declare function isRgb(color: string): boolean;
@@ -60,6 +63,151 @@ declare function isDateExpired(start: number, end: number, expire: string): bool
60
63
  declare function unixDiff(start: number, end: number, unit?: QUnitType | OpUnitType): number;
61
64
  declare function datePeriod(start: number, value?: number, unit?: OpUnitType): number;
62
65
 
66
+ declare enum HttpStatus {
67
+ CONTINUE = 100,
68
+ SWITCHING_PROTOCOLS = 101,
69
+ PROCESSING = 102,
70
+ EARLYHINTS = 103,
71
+ OK = 200,
72
+ CREATED = 201,
73
+ ACCEPTED = 202,
74
+ NON_AUTHORITATIVE_INFORMATION = 203,
75
+ NO_CONTENT = 204,
76
+ RESET_CONTENT = 205,
77
+ PARTIAL_CONTENT = 206,
78
+ MULTI_STATUS = 207,
79
+ ALREADY_REPORTED = 208,
80
+ CONTENT_DIFFERENT = 210,
81
+ AMBIGUOUS = 300,
82
+ MOVED_PERMANENTLY = 301,
83
+ FOUND = 302,
84
+ SEE_OTHER = 303,
85
+ NOT_MODIFIED = 304,
86
+ TEMPORARY_REDIRECT = 307,
87
+ PERMANENT_REDIRECT = 308,
88
+ BAD_REQUEST = 400,
89
+ UNAUTHORIZED = 401,
90
+ PAYMENT_REQUIRED = 402,
91
+ FORBIDDEN = 403,
92
+ NOT_FOUND = 404,
93
+ METHOD_NOT_ALLOWED = 405,
94
+ NOT_ACCEPTABLE = 406,
95
+ PROXY_AUTHENTICATION_REQUIRED = 407,
96
+ REQUEST_TIMEOUT = 408,
97
+ CONFLICT = 409,
98
+ GONE = 410,
99
+ LENGTH_REQUIRED = 411,
100
+ PRECONDITION_FAILED = 412,
101
+ PAYLOAD_TOO_LARGE = 413,
102
+ URI_TOO_LONG = 414,
103
+ UNSUPPORTED_MEDIA_TYPE = 415,
104
+ REQUESTED_RANGE_NOT_SATISFIABLE = 416,
105
+ EXPECTATION_FAILED = 417,
106
+ I_AM_A_TEAPOT = 418,
107
+ MISDIRECTED = 421,
108
+ UNPROCESSABLE_ENTITY = 422,
109
+ LOCKED = 423,
110
+ FAILED_DEPENDENCY = 424,
111
+ PRECONDITION_REQUIRED = 428,
112
+ TOO_MANY_REQUESTS = 429,
113
+ UNRECOVERABLE_ERROR = 456,
114
+ INTERNAL_SERVER_ERROR = 500,
115
+ NOT_IMPLEMENTED = 501,
116
+ BAD_GATEWAY = 502,
117
+ SERVICE_UNAVAILABLE = 503,
118
+ GATEWAY_TIMEOUT = 504,
119
+ HTTP_VERSION_NOT_SUPPORTED = 505,
120
+ INSUFFICIENT_STORAGE = 507,
121
+ LOOP_DETECTED = 508
122
+ }
123
+ interface Options {
124
+ status: HttpStatus;
125
+ code?: string;
126
+ errors?: Array<{
127
+ path?: string;
128
+ message: string;
129
+ }>;
130
+ }
131
+ declare class HttpError extends Error {
132
+ readonly status: HttpStatus;
133
+ readonly code: string;
134
+ readonly errors?: Options['errors'];
135
+ constructor(message: string, { status, code, errors }: Options);
136
+ getStatus(): number;
137
+ getCode(): string;
138
+ getErrors(): Array<{
139
+ path?: string;
140
+ message: string;
141
+ }> | undefined;
142
+ toJSON(): Record<string, any>;
143
+ }
144
+ declare class BadGatewayError extends HttpError {
145
+ constructor(message?: string, code?: string, errors?: Options['errors']);
146
+ }
147
+ declare class BadRequestError extends HttpError {
148
+ constructor(message?: string, code?: string, errors?: Options['errors']);
149
+ }
150
+ declare class ConflictError extends HttpError {
151
+ constructor(message?: string, code?: string, errors?: Options['errors']);
152
+ }
153
+ declare class ForbiddenError extends HttpError {
154
+ constructor(message?: string, code?: string, errors?: Options['errors']);
155
+ }
156
+ declare class TooManyRequestsError extends HttpError {
157
+ constructor(message?: string, code?: string, errors?: Options['errors']);
158
+ }
159
+ declare class GatewayTimeoutError extends HttpError {
160
+ constructor(message?: string, code?: string, errors?: Options['errors']);
161
+ }
162
+ declare class GoneError extends HttpError {
163
+ constructor(message?: string, code?: string, errors?: Options['errors']);
164
+ }
165
+ declare class HttpVersionNotSupportedError extends HttpError {
166
+ constructor(message?: string, code?: string, errors?: Options['errors']);
167
+ }
168
+ declare class ImATeapotError extends HttpError {
169
+ constructor(message?: string, code?: string, errors?: Options['errors']);
170
+ }
171
+ declare class InternalServerError extends HttpError {
172
+ constructor(message?: string, code?: string, errors?: Options['errors']);
173
+ }
174
+ declare class MethodNotAllowedError extends HttpError {
175
+ constructor(message?: string, code?: string, errors?: Options['errors']);
176
+ }
177
+ declare class MisdirectedError extends HttpError {
178
+ constructor(message?: string, code?: string, errors?: Options['errors']);
179
+ }
180
+ declare class NotAcceptableError extends HttpError {
181
+ constructor(message?: string, code?: string, errors?: Options['errors']);
182
+ }
183
+ declare class NotFoundError extends HttpError {
184
+ constructor(message?: string, code?: string, errors?: Options['errors']);
185
+ }
186
+ declare class NotImplementedError extends HttpError {
187
+ constructor(message?: string, code?: string, errors?: Options['errors']);
188
+ }
189
+ declare class PayloadTooLargeError extends HttpError {
190
+ constructor(message?: string, code?: string, errors?: Options['errors']);
191
+ }
192
+ declare class PreconditionFailedError extends HttpError {
193
+ constructor(message?: string, code?: string, errors?: Options['errors']);
194
+ }
195
+ declare class RequestTimeoutError extends HttpError {
196
+ constructor(message?: string, code?: string, errors?: Options['errors']);
197
+ }
198
+ declare class ServiceUnavailableError extends HttpError {
199
+ constructor(message?: string, code?: string, errors?: Options['errors']);
200
+ }
201
+ declare class UnauthorizedError extends HttpError {
202
+ constructor(message?: string, code?: string, errors?: Options['errors']);
203
+ }
204
+ declare class UnprocessableEntityError extends HttpError {
205
+ constructor(message?: string, code?: string, errors?: Options['errors']);
206
+ }
207
+ declare class UnsupportedMediaTypeError extends HttpError {
208
+ constructor(message?: string, code?: string, errors?: Options['errors']);
209
+ }
210
+
63
211
  declare function isBoolean(arg: any): boolean;
64
212
  declare function isString(arg: any): boolean;
65
213
  declare function isNumber(arg: any): boolean;
@@ -146,16 +294,11 @@ declare function pickValidValues<T = string | number | boolean>(target: Record<s
146
294
  declare function removeObjectNil(target: Record<string, any>): Record<string, any>;
147
295
  declare function copyObjectValues(target: Record<string, any>, dist: Record<string, any>, keyMaps: Array<string | string[]>): void;
148
296
 
149
- declare enum RandomType {
150
- LOWER = 0,
151
- UPPER = 1,
152
- NUMERIC = 2,
153
- HEXIC = 3,
154
- LOWER_NUMERIC = 4,
155
- UPPER_NUMERIC = 5,
156
- ALPHANUMERIC = 6
157
- }
158
- declare function random(len?: number, type?: RandomType): string;
297
+ declare function random(len?: number, alphabet?: string): string;
298
+ declare function randomHexic(len: number): string;
299
+ declare function randomAlpha(len: number): string;
300
+ declare function randomNumeric(len: number): string;
301
+ declare function randomNumber(min: number, max: number): number;
159
302
 
160
303
  interface SlugifyOptions {
161
304
  replacement?: string;
@@ -169,4 +312,4 @@ declare function slugify(text: string, options?: SlugifyOptions): string;
169
312
 
170
313
  declare function type(obj: any): string;
171
314
 
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 };
315
+ export { BadGatewayError, BadRequestError, ConflictError, FILE_MIME_TYPES, ForbiddenError, GatewayTimeoutError, GoneError, HttpError, HttpStatus, HttpVersionNotSupportedError, IMAGE_MIME_TYPES, ImATeapotError, InternalServerError, MethodNotAllowedError, MisdirectedError, NotAcceptableError, NotFoundError, NotImplementedError, PayloadTooLargeError, PreconditionFailedError, RequestTimeoutError, ServiceUnavailableError, type SlugifyOptions, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, UnsupportedMediaTypeError, alpha, alphaHexToRgb, bytes, clone, clsx, 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, randomAlpha, randomHexic, randomNumber, randomNumeric, removeObjectNil, rgbToHex, slugify, timestamp, toBool, toDuration, toFixed, toFloat, toInt, toInteger, toIntlNumber, toJSON, toMillisecond, toSecond, toURLParams, toURLQuery, type, unixDate, unixDiff };