@catbee/utils 0.0.8-rc.1 → 0.0.8-rc.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/build/esm/config.d.ts +0 -1
- package/build/esm/config.js +6 -7
- package/build/esm/index.d.ts +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/servers/server.builder.d.ts +0 -1
- package/build/esm/servers/server.builder.js +99 -147
- package/build/esm/servers/server.d.ts +0 -1
- package/build/esm/servers/server.js +591 -876
- package/build/esm/types/api-response.d.ts +0 -1
- package/build/esm/types/api-response.js +0 -1
- package/build/esm/types/index.d.ts +0 -1
- package/build/esm/types/index.js +0 -1
- package/build/esm/types/server.d.ts +0 -1
- package/build/esm/types/server.js +0 -1
- package/build/esm/utils/array.utils.d.ts +0 -1
- package/build/esm/utils/array.utils.js +48 -86
- package/build/esm/utils/async.utils.d.ts +0 -1
- package/build/esm/utils/async.utils.js +247 -524
- package/build/esm/utils/cache.utils.d.ts +0 -1
- package/build/esm/utils/cache.utils.js +96 -301
- package/build/esm/utils/context-store.utils.d.ts +0 -1
- package/build/esm/utils/context-store.utils.js +62 -79
- package/build/esm/utils/crypto.utils.d.ts +0 -1
- package/build/esm/utils/crypto.utils.js +78 -175
- package/build/esm/utils/date.utils.d.ts +0 -1
- package/build/esm/utils/date.utils.js +47 -53
- package/build/esm/utils/decorators.utils.d.ts +30 -27
- package/build/esm/utils/decorators.utils.js +417 -461
- package/build/esm/utils/dir.utils.d.ts +0 -1
- package/build/esm/utils/dir.utils.js +264 -786
- package/build/esm/utils/env.utils.d.ts +0 -1
- package/build/esm/utils/env.utils.js +180 -271
- package/build/esm/utils/exception.utils.d.ts +0 -1
- package/build/esm/utils/exception.utils.js +112 -289
- package/build/esm/utils/fs.utils.d.ts +0 -1
- package/build/esm/utils/fs.utils.js +169 -401
- package/build/esm/utils/http-status-codes.d.ts +0 -1
- package/build/esm/utils/http-status-codes.js +0 -1
- package/build/esm/utils/id.utils.d.ts +0 -1
- package/build/esm/utils/id.utils.js +5 -9
- package/build/esm/utils/logger.utils.d.ts +0 -1
- package/build/esm/utils/logger.utils.js +34 -71
- package/build/esm/utils/middleware.utils.d.ts +0 -1
- package/build/esm/utils/middleware.utils.js +65 -155
- package/build/esm/utils/obj.utils.d.ts +0 -1
- package/build/esm/utils/obj.utils.js +69 -176
- package/build/esm/utils/performance.utils.d.ts +0 -1
- package/build/esm/utils/performance.utils.js +92 -195
- package/build/esm/utils/request.utils.d.ts +0 -1
- package/build/esm/utils/request.utils.js +41 -74
- package/build/esm/utils/response.utils.d.ts +0 -1
- package/build/esm/utils/response.utils.js +84 -107
- package/build/esm/utils/stream.utils.d.ts +0 -1
- package/build/esm/utils/stream.utils.js +38 -113
- package/build/esm/utils/string.utils.d.ts +0 -1
- package/build/esm/utils/string.utils.js +6 -11
- package/build/esm/utils/type.utils.d.ts +0 -1
- package/build/esm/utils/type.utils.js +8 -12
- package/build/esm/utils/url.utils.d.ts +0 -1
- package/build/esm/utils/url.utils.js +49 -127
- package/build/esm/utils/validate.utils.d.ts +0 -1
- package/build/esm/utils/validate.utils.js +23 -40
- package/package.json +3 -33
- package/build/esm/config.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/servers/server.builder.js.map +0 -1
- package/build/esm/servers/server.js.map +0 -1
- package/build/esm/types/api-response.js.map +0 -1
- package/build/esm/types/index.js.map +0 -1
- package/build/esm/types/server.js.map +0 -1
- package/build/esm/utils/array.utils.js.map +0 -1
- package/build/esm/utils/async.utils.js.map +0 -1
- package/build/esm/utils/cache.utils.js.map +0 -1
- package/build/esm/utils/context-store.utils.js.map +0 -1
- package/build/esm/utils/crypto.utils.js.map +0 -1
- package/build/esm/utils/date.utils.js.map +0 -1
- package/build/esm/utils/decorators.utils.js.map +0 -1
- package/build/esm/utils/dir.utils.js.map +0 -1
- package/build/esm/utils/env.utils.js.map +0 -1
- package/build/esm/utils/exception.utils.js.map +0 -1
- package/build/esm/utils/fs.utils.js.map +0 -1
- package/build/esm/utils/http-status-codes.js.map +0 -1
- package/build/esm/utils/id.utils.js.map +0 -1
- package/build/esm/utils/logger.utils.js.map +0 -1
- package/build/esm/utils/middleware.utils.js.map +0 -1
- package/build/esm/utils/obj.utils.js.map +0 -1
- package/build/esm/utils/performance.utils.js.map +0 -1
- package/build/esm/utils/request.utils.js.map +0 -1
- package/build/esm/utils/response.utils.js.map +0 -1
- package/build/esm/utils/stream.utils.js.map +0 -1
- package/build/esm/utils/string.utils.js.map +0 -1
- package/build/esm/utils/type.utils.js.map +0 -1
- package/build/esm/utils/url.utils.js.map +0 -1
- package/build/esm/utils/validate.utils.js.map +0 -1
- package/build/esnext/config.d.ts +0 -122
- package/build/esnext/config.js +0 -133
- package/build/esnext/config.js.map +0 -1
- package/build/esnext/index.d.ts +0 -27
- package/build/esnext/index.js +0 -50
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/servers/server.builder.d.ts +0 -508
- package/build/esnext/servers/server.builder.js +0 -657
- package/build/esnext/servers/server.builder.js.map +0 -1
- package/build/esnext/servers/server.d.ts +0 -256
- package/build/esnext/servers/server.js +0 -955
- package/build/esnext/servers/server.js.map +0 -1
- package/build/esnext/types/api-response.d.ts +0 -152
- package/build/esnext/types/api-response.js +0 -34
- package/build/esnext/types/api-response.js.map +0 -1
- package/build/esnext/types/index.d.ts +0 -125
- package/build/esnext/types/index.js +0 -25
- package/build/esnext/types/index.js.map +0 -1
- package/build/esnext/types/server.d.ts +0 -268
- package/build/esnext/types/server.js +0 -25
- package/build/esnext/types/server.js.map +0 -1
- package/build/esnext/utils/array.utils.d.ts +0 -168
- package/build/esnext/utils/array.utils.js +0 -345
- package/build/esnext/utils/array.utils.js.map +0 -1
- package/build/esnext/utils/async.utils.d.ts +0 -265
- package/build/esnext/utils/async.utils.js +0 -620
- package/build/esnext/utils/async.utils.js.map +0 -1
- package/build/esnext/utils/cache.utils.d.ts +0 -153
- package/build/esnext/utils/cache.utils.js +0 -293
- package/build/esnext/utils/cache.utils.js.map +0 -1
- package/build/esnext/utils/context-store.utils.d.ts +0 -189
- package/build/esnext/utils/context-store.utils.js +0 -289
- package/build/esnext/utils/context-store.utils.js.map +0 -1
- package/build/esnext/utils/crypto.utils.d.ts +0 -160
- package/build/esnext/utils/crypto.utils.js +0 -276
- package/build/esnext/utils/crypto.utils.js.map +0 -1
- package/build/esnext/utils/date.utils.d.ts +0 -159
- package/build/esnext/utils/date.utils.js +0 -384
- package/build/esnext/utils/date.utils.js.map +0 -1
- package/build/esnext/utils/decorators.utils.d.ts +0 -508
- package/build/esnext/utils/decorators.utils.js +0 -877
- package/build/esnext/utils/decorators.utils.js.map +0 -1
- package/build/esnext/utils/dir.utils.d.ts +0 -196
- package/build/esnext/utils/dir.utils.js +0 -477
- package/build/esnext/utils/dir.utils.js.map +0 -1
- package/build/esnext/utils/env.utils.d.ts +0 -377
- package/build/esnext/utils/env.utils.js +0 -785
- package/build/esnext/utils/env.utils.js.map +0 -1
- package/build/esnext/utils/exception.utils.d.ts +0 -230
- package/build/esnext/utils/exception.utils.js +0 -381
- package/build/esnext/utils/exception.utils.js.map +0 -1
- package/build/esnext/utils/fs.utils.d.ts +0 -164
- package/build/esnext/utils/fs.utils.js +0 -349
- package/build/esnext/utils/fs.utils.js.map +0 -1
- package/build/esnext/utils/http-status-codes.d.ts +0 -266
- package/build/esnext/utils/http-status-codes.js +0 -295
- package/build/esnext/utils/http-status-codes.js.map +0 -1
- package/build/esnext/utils/id.utils.d.ts +0 -36
- package/build/esnext/utils/id.utils.js +0 -84
- package/build/esnext/utils/id.utils.js.map +0 -1
- package/build/esnext/utils/logger.utils.d.ts +0 -160
- package/build/esnext/utils/logger.utils.js +0 -300
- package/build/esnext/utils/logger.utils.js.map +0 -1
- package/build/esnext/utils/middleware.utils.d.ts +0 -100
- package/build/esnext/utils/middleware.utils.js +0 -236
- package/build/esnext/utils/middleware.utils.js.map +0 -1
- package/build/esnext/utils/obj.utils.d.ts +0 -124
- package/build/esnext/utils/obj.utils.js +0 -413
- package/build/esnext/utils/obj.utils.js.map +0 -1
- package/build/esnext/utils/performance.utils.d.ts +0 -136
- package/build/esnext/utils/performance.utils.js +0 -271
- package/build/esnext/utils/performance.utils.js.map +0 -1
- package/build/esnext/utils/request.utils.d.ts +0 -86
- package/build/esnext/utils/request.utils.js +0 -186
- package/build/esnext/utils/request.utils.js.map +0 -1
- package/build/esnext/utils/response.utils.d.ts +0 -163
- package/build/esnext/utils/response.utils.js +0 -247
- package/build/esnext/utils/response.utils.js.map +0 -1
- package/build/esnext/utils/stream.utils.d.ts +0 -88
- package/build/esnext/utils/stream.utils.js +0 -210
- package/build/esnext/utils/stream.utils.js.map +0 -1
- package/build/esnext/utils/string.utils.d.ts +0 -93
- package/build/esnext/utils/string.utils.js +0 -165
- package/build/esnext/utils/string.utils.js.map +0 -1
- package/build/esnext/utils/type.utils.d.ts +0 -90
- package/build/esnext/utils/type.utils.js +0 -187
- package/build/esnext/utils/type.utils.js.map +0 -1
- package/build/esnext/utils/url.utils.d.ts +0 -141
- package/build/esnext/utils/url.utils.js +0 -304
- package/build/esnext/utils/url.utils.js.map +0 -1
- package/build/esnext/utils/validate.utils.d.ts +0 -177
- package/build/esnext/utils/validate.utils.js +0 -320
- package/build/esnext/utils/validate.utils.js.map +0 -1
- package/build/src/config.d.ts +0 -122
- package/build/src/config.js +0 -138
- package/build/src/config.js.map +0 -1
- package/build/src/index.d.ts +0 -27
- package/build/src/index.js +0 -69
- package/build/src/index.js.map +0 -1
- package/build/src/servers/server.builder.d.ts +0 -508
- package/build/src/servers/server.builder.js +0 -661
- package/build/src/servers/server.builder.js.map +0 -1
- package/build/src/servers/server.d.ts +0 -256
- package/build/src/servers/server.js +0 -962
- package/build/src/servers/server.js.map +0 -1
- package/build/src/types/api-response.d.ts +0 -152
- package/build/src/types/api-response.js +0 -37
- package/build/src/types/api-response.js.map +0 -1
- package/build/src/types/index.d.ts +0 -125
- package/build/src/types/index.js +0 -26
- package/build/src/types/index.js.map +0 -1
- package/build/src/types/server.d.ts +0 -268
- package/build/src/types/server.js +0 -26
- package/build/src/types/server.js.map +0 -1
- package/build/src/utils/array.utils.d.ts +0 -168
- package/build/src/utils/array.utils.js +0 -364
- package/build/src/utils/array.utils.js.map +0 -1
- package/build/src/utils/async.utils.d.ts +0 -265
- package/build/src/utils/async.utils.js +0 -641
- package/build/src/utils/async.utils.js.map +0 -1
- package/build/src/utils/cache.utils.d.ts +0 -153
- package/build/src/utils/cache.utils.js +0 -297
- package/build/src/utils/cache.utils.js.map +0 -1
- package/build/src/utils/context-store.utils.d.ts +0 -189
- package/build/src/utils/context-store.utils.js +0 -296
- package/build/src/utils/context-store.utils.js.map +0 -1
- package/build/src/utils/crypto.utils.d.ts +0 -160
- package/build/src/utils/crypto.utils.js +0 -293
- package/build/src/utils/crypto.utils.js.map +0 -1
- package/build/src/utils/date.utils.d.ts +0 -159
- package/build/src/utils/date.utils.js +0 -396
- package/build/src/utils/date.utils.js.map +0 -1
- package/build/src/utils/decorators.utils.d.ts +0 -508
- package/build/src/utils/decorators.utils.js +0 -896
- package/build/src/utils/decorators.utils.js.map +0 -1
- package/build/src/utils/dir.utils.d.ts +0 -196
- package/build/src/utils/dir.utils.js +0 -501
- package/build/src/utils/dir.utils.js.map +0 -1
- package/build/src/utils/env.utils.d.ts +0 -377
- package/build/src/utils/env.utils.js +0 -789
- package/build/src/utils/env.utils.js.map +0 -1
- package/build/src/utils/exception.utils.d.ts +0 -230
- package/build/src/utils/exception.utils.js +0 -407
- package/build/src/utils/exception.utils.js.map +0 -1
- package/build/src/utils/fs.utils.d.ts +0 -164
- package/build/src/utils/fs.utils.js +0 -372
- package/build/src/utils/fs.utils.js.map +0 -1
- package/build/src/utils/http-status-codes.d.ts +0 -266
- package/build/src/utils/http-status-codes.js +0 -298
- package/build/src/utils/http-status-codes.js.map +0 -1
- package/build/src/utils/id.utils.d.ts +0 -36
- package/build/src/utils/id.utils.js +0 -91
- package/build/src/utils/id.utils.js.map +0 -1
- package/build/src/utils/logger.utils.d.ts +0 -160
- package/build/src/utils/logger.utils.js +0 -346
- package/build/src/utils/logger.utils.js.map +0 -1
- package/build/src/utils/middleware.utils.d.ts +0 -100
- package/build/src/utils/middleware.utils.js +0 -244
- package/build/src/utils/middleware.utils.js.map +0 -1
- package/build/src/utils/obj.utils.d.ts +0 -124
- package/build/src/utils/obj.utils.js +0 -429
- package/build/src/utils/obj.utils.js.map +0 -1
- package/build/src/utils/performance.utils.d.ts +0 -136
- package/build/src/utils/performance.utils.js +0 -278
- package/build/src/utils/performance.utils.js.map +0 -1
- package/build/src/utils/request.utils.d.ts +0 -86
- package/build/src/utils/request.utils.js +0 -195
- package/build/src/utils/request.utils.js.map +0 -1
- package/build/src/utils/response.utils.d.ts +0 -163
- package/build/src/utils/response.utils.js +0 -260
- package/build/src/utils/response.utils.js.map +0 -1
- package/build/src/utils/stream.utils.d.ts +0 -88
- package/build/src/utils/stream.utils.js +0 -218
- package/build/src/utils/stream.utils.js.map +0 -1
- package/build/src/utils/string.utils.d.ts +0 -93
- package/build/src/utils/string.utils.js +0 -179
- package/build/src/utils/string.utils.js.map +0 -1
- package/build/src/utils/type.utils.d.ts +0 -90
- package/build/src/utils/type.utils.js +0 -196
- package/build/src/utils/type.utils.js.map +0 -1
- package/build/src/utils/url.utils.d.ts +0 -141
- package/build/src/utils/url.utils.js +0 -317
- package/build/src/utils/url.utils.js.map +0 -1
- package/build/src/utils/validate.utils.d.ts +0 -177
- package/build/src/utils/validate.utils.js +0 -345
- package/build/src/utils/validate.utils.js.map +0 -1
|
@@ -21,21 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
var __extends = (this && this.__extends) || (function () {
|
|
25
|
-
var extendStatics = function (d, b) {
|
|
26
|
-
extendStatics = Object.setPrototypeOf ||
|
|
27
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
28
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
29
|
-
return extendStatics(d, b);
|
|
30
|
-
};
|
|
31
|
-
return function (d, b) {
|
|
32
|
-
if (typeof b !== "function" && b !== null)
|
|
33
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
34
|
-
extendStatics(d, b);
|
|
35
|
-
function __() { this.constructor = d; }
|
|
36
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
24
|
import { getRequestId } from './context-store.utils';
|
|
40
25
|
import { Env } from './env.utils';
|
|
41
26
|
import { uuid } from './id.utils';
|
|
@@ -45,70 +30,74 @@ import { uuid } from './id.utils';
|
|
|
45
30
|
*
|
|
46
31
|
* @typeParam T - The shape of the data returned in the response.
|
|
47
32
|
*/
|
|
48
|
-
|
|
33
|
+
export class SuccessResponse {
|
|
34
|
+
/** Message describing the result of the operation. */
|
|
35
|
+
message = 'Success';
|
|
36
|
+
/** Whether the response is an error. Always false in success responses. */
|
|
37
|
+
error = false;
|
|
38
|
+
/** The payload returned from the API. */
|
|
39
|
+
data = null;
|
|
40
|
+
/** Timestamp when the response was generated, in ISO format. */
|
|
41
|
+
timestamp = new Date().toISOString();
|
|
42
|
+
/** Unique identifier for this response, useful for request tracing. */
|
|
43
|
+
requestId = getRequestId() ?? uuid();
|
|
49
44
|
/**
|
|
50
45
|
* Constructs a new success response.
|
|
51
46
|
*
|
|
52
47
|
* @param {string} message - Optional message to override the default.
|
|
53
48
|
* @param {T} [data] - Optional data payload.
|
|
54
49
|
*/
|
|
55
|
-
|
|
56
|
-
var _a;
|
|
57
|
-
/** Message describing the result of the operation. */
|
|
58
|
-
this.message = 'Success';
|
|
59
|
-
/** Whether the response is an error. Always false in success responses. */
|
|
60
|
-
this.error = false;
|
|
61
|
-
/** The payload returned from the API. */
|
|
62
|
-
this.data = null;
|
|
63
|
-
/** Timestamp when the response was generated, in ISO format. */
|
|
64
|
-
this.timestamp = new Date().toISOString();
|
|
65
|
-
/** Unique identifier for this response, useful for request tracing. */
|
|
66
|
-
this.requestId = (_a = getRequestId()) !== null && _a !== void 0 ? _a : uuid();
|
|
50
|
+
constructor(message, data) {
|
|
67
51
|
if (message)
|
|
68
52
|
this.message = message;
|
|
69
|
-
this.data = data
|
|
53
|
+
this.data = data ?? null;
|
|
70
54
|
}
|
|
71
|
-
|
|
72
|
-
}());
|
|
73
|
-
export { SuccessResponse };
|
|
55
|
+
}
|
|
74
56
|
/**
|
|
75
57
|
* Wrapper for error responses that extends the native `Error` object.
|
|
76
58
|
* Implements `ApiResponse` but omits the `data` field (which should not be present in errors).
|
|
77
59
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
60
|
+
export class ErrorResponse extends Error {
|
|
61
|
+
/** HTTP status code associated with the error (e.g., 404, 500). */
|
|
62
|
+
status;
|
|
63
|
+
/** Indicates that this is an error. Always true. */
|
|
64
|
+
error = true;
|
|
65
|
+
/** Timestamp when the error occurred, in ISO format. */
|
|
66
|
+
timestamp = new Date().toISOString();
|
|
67
|
+
/** Unique identifier for this error instance. */
|
|
68
|
+
requestId = getRequestId() ?? uuid();
|
|
80
69
|
/**
|
|
81
70
|
* Constructs a new error response.
|
|
82
71
|
*
|
|
83
72
|
* @param {string} message - The error message to display or log.
|
|
84
73
|
* @param {number} [status=500] - Optional HTTP status code (defaults to 500).
|
|
85
74
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
_this.error = true;
|
|
92
|
-
/** Timestamp when the error occurred, in ISO format. */
|
|
93
|
-
_this.timestamp = new Date().toISOString();
|
|
94
|
-
/** Unique identifier for this error instance. */
|
|
95
|
-
_this.requestId = (_a = getRequestId()) !== null && _a !== void 0 ? _a : uuid();
|
|
96
|
-
_this.status = status;
|
|
97
|
-
_this.name = _this.constructor.name;
|
|
98
|
-
Error.captureStackTrace(_this, _this.constructor);
|
|
99
|
-
return _this;
|
|
75
|
+
constructor(message, status = 500) {
|
|
76
|
+
super(message);
|
|
77
|
+
this.status = status;
|
|
78
|
+
this.name = this.constructor.name;
|
|
79
|
+
Error.captureStackTrace(this, this.constructor);
|
|
100
80
|
}
|
|
101
|
-
|
|
102
|
-
}(Error));
|
|
103
|
-
export { ErrorResponse };
|
|
81
|
+
}
|
|
104
82
|
/**
|
|
105
83
|
* Response with paginated data extending the standard success response.
|
|
106
84
|
* Useful for APIs that return large collections of data.
|
|
107
85
|
*
|
|
108
86
|
* @typeParam T - The shape of each item in the paginated collection.
|
|
109
87
|
*/
|
|
110
|
-
|
|
111
|
-
|
|
88
|
+
export class PaginatedResponse extends SuccessResponse {
|
|
89
|
+
/** Total number of items across all pages */
|
|
90
|
+
total;
|
|
91
|
+
/** Current page number (1-based) */
|
|
92
|
+
page;
|
|
93
|
+
/** Number of items per page */
|
|
94
|
+
pageSize;
|
|
95
|
+
/** Total number of pages */
|
|
96
|
+
totalPages;
|
|
97
|
+
/** Whether there's a next page available */
|
|
98
|
+
hasNext;
|
|
99
|
+
/** Whether there's a previous page available */
|
|
100
|
+
hasPrevious;
|
|
112
101
|
/**
|
|
113
102
|
* Constructs a new paginated response.
|
|
114
103
|
*
|
|
@@ -119,60 +108,52 @@ var PaginatedResponse = /** @class */ (function (_super) {
|
|
|
119
108
|
* @param {number} pagination.pageSize - Number of items per page.
|
|
120
109
|
* @param {string} [message="Success"] - Optional custom message.
|
|
121
110
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
_this.hasPrevious = _this.page > 1;
|
|
131
|
-
return _this;
|
|
111
|
+
constructor(items, pagination, message = 'Success') {
|
|
112
|
+
super(message, items);
|
|
113
|
+
this.total = pagination.total;
|
|
114
|
+
this.page = pagination.page;
|
|
115
|
+
this.pageSize = pagination.pageSize;
|
|
116
|
+
this.totalPages = Math.ceil(this.total / this.pageSize);
|
|
117
|
+
this.hasNext = this.page < this.totalPages;
|
|
118
|
+
this.hasPrevious = this.page > 1;
|
|
132
119
|
}
|
|
133
|
-
|
|
134
|
-
}(SuccessResponse));
|
|
135
|
-
export { PaginatedResponse };
|
|
120
|
+
}
|
|
136
121
|
/**
|
|
137
122
|
* Specialized response for operations that don't return data (HTTP 204).
|
|
138
123
|
*/
|
|
139
|
-
|
|
140
|
-
__extends(NoContentResponse, _super);
|
|
124
|
+
export class NoContentResponse extends SuccessResponse {
|
|
141
125
|
/**
|
|
142
126
|
* Constructs a new no-content response.
|
|
143
127
|
*
|
|
144
128
|
* @param {string} [message="Operation completed successfully"] - Optional custom message.
|
|
145
129
|
*/
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
return _super.call(this, message, null) || this;
|
|
130
|
+
constructor(message = 'Operation completed successfully') {
|
|
131
|
+
super(message, null);
|
|
149
132
|
}
|
|
150
|
-
|
|
151
|
-
}(SuccessResponse));
|
|
152
|
-
export { NoContentResponse };
|
|
133
|
+
}
|
|
153
134
|
/**
|
|
154
135
|
* Specialized response for redirects.
|
|
155
136
|
*/
|
|
156
|
-
|
|
137
|
+
export class RedirectResponse {
|
|
138
|
+
/** The URL to redirect to */
|
|
139
|
+
redirectUrl;
|
|
140
|
+
/** HTTP status code for the redirect (301, 302, 303, 307, 308) */
|
|
141
|
+
statusCode;
|
|
142
|
+
/** Whether the response is a redirect */
|
|
143
|
+
isRedirect = true;
|
|
144
|
+
/** Unique identifier for this response */
|
|
145
|
+
requestId = getRequestId() ?? uuid();
|
|
157
146
|
/**
|
|
158
147
|
* Constructs a new redirect response.
|
|
159
148
|
*
|
|
160
149
|
* @param {string} url - The URL to redirect to.
|
|
161
150
|
* @param {number} [statusCode=302] - HTTP status code for the redirect.
|
|
162
151
|
*/
|
|
163
|
-
|
|
164
|
-
if (statusCode === void 0) { statusCode = 302; }
|
|
165
|
-
var _a;
|
|
166
|
-
/** Whether the response is a redirect */
|
|
167
|
-
this.isRedirect = true;
|
|
168
|
-
/** Unique identifier for this response */
|
|
169
|
-
this.requestId = (_a = getRequestId()) !== null && _a !== void 0 ? _a : uuid();
|
|
152
|
+
constructor(url, statusCode = 302) {
|
|
170
153
|
this.redirectUrl = url;
|
|
171
154
|
this.statusCode = statusCode;
|
|
172
155
|
}
|
|
173
|
-
|
|
174
|
-
}());
|
|
175
|
-
export { RedirectResponse };
|
|
156
|
+
}
|
|
176
157
|
/**
|
|
177
158
|
* Creates a standard success response.
|
|
178
159
|
*
|
|
@@ -181,8 +162,7 @@ export { RedirectResponse };
|
|
|
181
162
|
* @param {string} [message="Success"] - Optional custom message.
|
|
182
163
|
* @returns {SuccessResponse<T>} A properly formatted success response.
|
|
183
164
|
*/
|
|
184
|
-
export function createSuccessResponse(data, message) {
|
|
185
|
-
if (message === void 0) { message = 'Success'; }
|
|
165
|
+
export function createSuccessResponse(data, message = 'Success') {
|
|
186
166
|
return new SuccessResponse(message, data);
|
|
187
167
|
}
|
|
188
168
|
/**
|
|
@@ -192,8 +172,7 @@ export function createSuccessResponse(data, message) {
|
|
|
192
172
|
* @param {number} [statusCode=500] - HTTP status code for the error.
|
|
193
173
|
* @returns {ErrorResponse} A properly formatted error response.
|
|
194
174
|
*/
|
|
195
|
-
export function createErrorResponse(message, statusCode) {
|
|
196
|
-
if (statusCode === void 0) { statusCode = 500; }
|
|
175
|
+
export function createErrorResponse(message, statusCode = 500) {
|
|
197
176
|
return new ErrorResponse(message, statusCode);
|
|
198
177
|
}
|
|
199
178
|
/**
|
|
@@ -207,19 +186,19 @@ export function createErrorResponse(message, statusCode) {
|
|
|
207
186
|
* @returns A properly formatted final error response.
|
|
208
187
|
*/
|
|
209
188
|
export function createFinalErrorResponse(req, status, message, error, options) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
189
|
+
const isDev = Env.isDev();
|
|
190
|
+
const includeDetails = options?.includeDetails && isDev;
|
|
191
|
+
const response = {
|
|
213
192
|
error: true,
|
|
214
|
-
message
|
|
193
|
+
message,
|
|
215
194
|
timestamp: new Date().toISOString(),
|
|
216
|
-
requestId:
|
|
217
|
-
status
|
|
195
|
+
requestId: error?.requestId || req?.id || uuid(),
|
|
196
|
+
status,
|
|
218
197
|
path: req.originalUrl || req.url
|
|
219
198
|
};
|
|
220
199
|
// Include stack trace in development mode if requested
|
|
221
|
-
if (includeDetails &&
|
|
222
|
-
response.stack = error.stack.split('\n').map(
|
|
200
|
+
if (includeDetails && error?.stack) {
|
|
201
|
+
response.stack = error.stack.split('\n').map((line) => line.trim());
|
|
223
202
|
}
|
|
224
203
|
return response;
|
|
225
204
|
}
|
|
@@ -233,16 +212,15 @@ export function createFinalErrorResponse(req, status, message, error, options) {
|
|
|
233
212
|
* @param {string} [message="Success"] - Optional custom message.
|
|
234
213
|
* @returns {PaginatedResponse<T>} A properly formatted paginated response.
|
|
235
214
|
*/
|
|
236
|
-
export function createPaginatedResponse(allItems, page, pageSize, message) {
|
|
237
|
-
if (message === void 0) { message = 'Success'; }
|
|
215
|
+
export function createPaginatedResponse(allItems, page, pageSize, message = 'Success') {
|
|
238
216
|
// Ensure valid pagination parameters
|
|
239
|
-
|
|
240
|
-
|
|
217
|
+
const validPage = Math.max(1, page);
|
|
218
|
+
const validPageSize = Math.max(1, pageSize);
|
|
241
219
|
// Calculate slice indices
|
|
242
|
-
|
|
243
|
-
|
|
220
|
+
const startIndex = (validPage - 1) * validPageSize;
|
|
221
|
+
const endIndex = startIndex + validPageSize;
|
|
244
222
|
// Get current page items
|
|
245
|
-
|
|
223
|
+
const pageItems = allItems.slice(startIndex, endIndex);
|
|
246
224
|
return new PaginatedResponse(pageItems, {
|
|
247
225
|
total: allItems.length,
|
|
248
226
|
page: validPage,
|
|
@@ -263,7 +241,7 @@ export function sendResponse(res, apiResponse) {
|
|
|
263
241
|
}
|
|
264
242
|
// Handle errors
|
|
265
243
|
if ('error' in apiResponse && apiResponse.error) {
|
|
266
|
-
|
|
244
|
+
const errorResponse = apiResponse;
|
|
267
245
|
res.status(errorResponse.status).json({
|
|
268
246
|
error: true,
|
|
269
247
|
message: errorResponse.message,
|
|
@@ -273,7 +251,7 @@ export function sendResponse(res, apiResponse) {
|
|
|
273
251
|
return;
|
|
274
252
|
}
|
|
275
253
|
// Handle success responses
|
|
276
|
-
|
|
254
|
+
const successResponse = apiResponse;
|
|
277
255
|
// No content (204) shouldn't return a body
|
|
278
256
|
if (successResponse instanceof NoContentResponse) {
|
|
279
257
|
res.status(204).end();
|
|
@@ -281,4 +259,3 @@ export function sendResponse(res, apiResponse) {
|
|
|
281
259
|
}
|
|
282
260
|
res.status(200).json(successResponse);
|
|
283
261
|
}
|
|
284
|
-
//# sourceMappingURL=response.utils.js.map
|
|
@@ -21,53 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
25
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
26
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
27
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
28
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
29
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
30
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
34
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
35
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
36
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
37
|
-
function step(op) {
|
|
38
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
39
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
40
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
41
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
42
|
-
switch (op[0]) {
|
|
43
|
-
case 0: case 1: t = op; break;
|
|
44
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
45
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
46
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
47
|
-
default:
|
|
48
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
49
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
50
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
51
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
52
|
-
if (t[2]) _.ops.pop();
|
|
53
|
-
_.trys.pop(); continue;
|
|
54
|
-
}
|
|
55
|
-
op = body.call(thisArg, _);
|
|
56
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
57
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
var __values = (this && this.__values) || function(o) {
|
|
61
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
62
|
-
if (m) return m.call(o);
|
|
63
|
-
if (o && typeof o.length === "number") return {
|
|
64
|
-
next: function () {
|
|
65
|
-
if (o && i >= o.length) o = void 0;
|
|
66
|
-
return { value: o && o[i++], done: !o };
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
70
|
-
};
|
|
71
24
|
import { Readable, Transform } from 'stream';
|
|
72
25
|
/**
|
|
73
26
|
* Convert a buffer or string to a readable stream.
|
|
@@ -83,7 +36,7 @@ import { Readable, Transform } from 'stream';
|
|
|
83
36
|
* ```
|
|
84
37
|
*/
|
|
85
38
|
export function bufferToStream(data) {
|
|
86
|
-
|
|
39
|
+
const readable = new Readable();
|
|
87
40
|
readable.push(data);
|
|
88
41
|
readable.push(null); // End of stream
|
|
89
42
|
return readable;
|
|
@@ -100,16 +53,12 @@ export function bufferToStream(data) {
|
|
|
100
53
|
* console.log(buffer.toString()); // Contents of file.txt
|
|
101
54
|
* ```
|
|
102
55
|
*/
|
|
103
|
-
export function streamToBuffer(stream) {
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
stream.on('end', function () { return resolve(Buffer.concat(chunks)); });
|
|
110
|
-
stream.on('error', reject);
|
|
111
|
-
})];
|
|
112
|
-
});
|
|
56
|
+
export async function streamToBuffer(stream) {
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
const chunks = [];
|
|
59
|
+
stream.on('data', chunk => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
|
|
60
|
+
stream.on('end', () => resolve(Buffer.concat(chunks)));
|
|
61
|
+
stream.on('error', reject);
|
|
113
62
|
});
|
|
114
63
|
}
|
|
115
64
|
/**
|
|
@@ -125,19 +74,9 @@ export function streamToBuffer(stream) {
|
|
|
125
74
|
* console.log(content); // Contents of file.txt as string
|
|
126
75
|
* ```
|
|
127
76
|
*/
|
|
128
|
-
export function streamToString(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (encoding === void 0) { encoding = 'utf8'; }
|
|
132
|
-
return __generator(this, function (_a) {
|
|
133
|
-
switch (_a.label) {
|
|
134
|
-
case 0: return [4 /*yield*/, streamToBuffer(stream)];
|
|
135
|
-
case 1:
|
|
136
|
-
buffer = _a.sent();
|
|
137
|
-
return [2 /*return*/, buffer.toString(encoding)];
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
77
|
+
export async function streamToString(stream, encoding = 'utf8') {
|
|
78
|
+
const buffer = await streamToBuffer(stream);
|
|
79
|
+
return buffer.toString(encoding);
|
|
141
80
|
}
|
|
142
81
|
/**
|
|
143
82
|
* Create a transform stream that limits the rate of data flow.
|
|
@@ -146,13 +85,13 @@ export function streamToString(stream_1) {
|
|
|
146
85
|
* @returns Transform stream that throttles data flow
|
|
147
86
|
*/
|
|
148
87
|
export function createThrottleStream(bytesPerSecond) {
|
|
149
|
-
|
|
150
|
-
|
|
88
|
+
let bytesSent = 0;
|
|
89
|
+
let startTime = Date.now();
|
|
151
90
|
return new Transform({
|
|
152
|
-
transform
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
91
|
+
transform(chunk, _encoding, callback) {
|
|
92
|
+
const elapsedSeconds = (Date.now() - startTime) / 1000;
|
|
93
|
+
const targetBytes = bytesPerSecond * elapsedSeconds;
|
|
94
|
+
const chunkSize = chunk.length;
|
|
156
95
|
// If we've sent fewer bytes than our target, just send the chunk
|
|
157
96
|
if (bytesSent + chunkSize <= targetBytes) {
|
|
158
97
|
bytesSent += chunkSize;
|
|
@@ -160,8 +99,8 @@ export function createThrottleStream(bytesPerSecond) {
|
|
|
160
99
|
return;
|
|
161
100
|
}
|
|
162
101
|
// Otherwise we need to throttle
|
|
163
|
-
|
|
164
|
-
setTimeout(
|
|
102
|
+
const delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1000;
|
|
103
|
+
setTimeout(() => {
|
|
165
104
|
bytesSent += chunkSize;
|
|
166
105
|
callback(null, chunk);
|
|
167
106
|
}, delay);
|
|
@@ -184,15 +123,14 @@ export function createThrottleStream(bytesPerSecond) {
|
|
|
184
123
|
* .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
|
|
185
124
|
* ```
|
|
186
125
|
*/
|
|
187
|
-
export function createBatchStream(size, options) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
var bufferSize = 0;
|
|
126
|
+
export function createBatchStream(size, options = {}) {
|
|
127
|
+
const objectMode = options.objectMode !== false;
|
|
128
|
+
let batch = [];
|
|
129
|
+
let buffers = [];
|
|
130
|
+
let bufferSize = 0;
|
|
193
131
|
return new Transform({
|
|
194
|
-
objectMode
|
|
195
|
-
transform
|
|
132
|
+
objectMode,
|
|
133
|
+
transform(chunk, _encoding, callback) {
|
|
196
134
|
if (objectMode) {
|
|
197
135
|
batch.push(chunk);
|
|
198
136
|
if (batch.length >= size) {
|
|
@@ -201,11 +139,11 @@ export function createBatchStream(size, options) {
|
|
|
201
139
|
}
|
|
202
140
|
}
|
|
203
141
|
else {
|
|
204
|
-
|
|
142
|
+
const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
205
143
|
buffers.push(buffer);
|
|
206
144
|
bufferSize += buffer.length;
|
|
207
145
|
// Emit batches of exact size
|
|
208
|
-
|
|
146
|
+
let combined = Buffer.concat(buffers, bufferSize);
|
|
209
147
|
while (combined.length >= size) {
|
|
210
148
|
this.push(combined.slice(0, size));
|
|
211
149
|
combined = combined.slice(size);
|
|
@@ -215,12 +153,12 @@ export function createBatchStream(size, options) {
|
|
|
215
153
|
}
|
|
216
154
|
callback();
|
|
217
155
|
},
|
|
218
|
-
flush
|
|
156
|
+
flush(callback) {
|
|
219
157
|
if (objectMode && batch.length > 0) {
|
|
220
158
|
this.push(batch);
|
|
221
159
|
}
|
|
222
160
|
else if (!objectMode && buffers.length > 0 && bufferSize > 0) {
|
|
223
|
-
|
|
161
|
+
let combined = Buffer.concat(buffers, bufferSize);
|
|
224
162
|
while (combined.length >= size) {
|
|
225
163
|
this.push(combined.slice(0, size));
|
|
226
164
|
combined = combined.slice(size);
|
|
@@ -247,33 +185,21 @@ export function createBatchStream(size, options) {
|
|
|
247
185
|
* .on('data', line => console.log(`Line: ${line}`));
|
|
248
186
|
* ```
|
|
249
187
|
*/
|
|
250
|
-
export function createLineStream(options) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
var buffer = '';
|
|
188
|
+
export function createLineStream(options = {}) {
|
|
189
|
+
const { encoding = 'utf8', includeNewlines = false } = options;
|
|
190
|
+
let buffer = '';
|
|
254
191
|
return new Transform({
|
|
255
192
|
objectMode: true,
|
|
256
|
-
transform
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
var lines = str.split(/\r?\n/);
|
|
193
|
+
transform(chunk, _encoding, callback) {
|
|
194
|
+
const str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);
|
|
195
|
+
const lines = str.split(/\r?\n/);
|
|
260
196
|
buffer = lines.pop() || '';
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var line = lines_1_1.value;
|
|
264
|
-
this.push(includeNewlines ? line + '\n' : line);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
268
|
-
finally {
|
|
269
|
-
try {
|
|
270
|
-
if (lines_1_1 && !lines_1_1.done && (_a = lines_1.return)) _a.call(lines_1);
|
|
271
|
-
}
|
|
272
|
-
finally { if (e_1) throw e_1.error; }
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
this.push(includeNewlines ? line + '\n' : line);
|
|
273
199
|
}
|
|
274
200
|
callback();
|
|
275
201
|
},
|
|
276
|
-
flush
|
|
202
|
+
flush(callback) {
|
|
277
203
|
if (buffer) {
|
|
278
204
|
this.push(buffer);
|
|
279
205
|
}
|
|
@@ -281,4 +207,3 @@ export function createLineStream(options) {
|
|
|
281
207
|
}
|
|
282
208
|
});
|
|
283
209
|
}
|
|
284
|
-
//# sourceMappingURL=stream.utils.js.map
|
|
@@ -50,7 +50,7 @@ export function toKebabCase(str) {
|
|
|
50
50
|
* @returns {string} The camelCased string.
|
|
51
51
|
*/
|
|
52
52
|
export function toCamelCase(str) {
|
|
53
|
-
return str.replace(/[-_](.)/g,
|
|
53
|
+
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase());
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
|
|
@@ -109,17 +109,14 @@ export function toSnakeCase(str) {
|
|
|
109
109
|
* @param {string} [maskChar="*"] - Character to use for masking.
|
|
110
110
|
* @returns {string} The masked string.
|
|
111
111
|
*/
|
|
112
|
-
export function mask(str, visibleStart, visibleEnd, maskChar) {
|
|
113
|
-
if (visibleStart === void 0) { visibleStart = 0; }
|
|
114
|
-
if (visibleEnd === void 0) { visibleEnd = 0; }
|
|
115
|
-
if (maskChar === void 0) { maskChar = '*'; }
|
|
112
|
+
export function mask(str, visibleStart = 0, visibleEnd = 0, maskChar = '*') {
|
|
116
113
|
if (!str || str.length === 0)
|
|
117
114
|
return '';
|
|
118
115
|
if (visibleStart >= str.length)
|
|
119
116
|
return str;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
const start = str.slice(0, visibleStart);
|
|
118
|
+
const end = visibleEnd > 0 ? str.slice(-visibleEnd) : '';
|
|
119
|
+
const masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
|
|
123
120
|
return start + masked + end;
|
|
124
121
|
}
|
|
125
122
|
/**
|
|
@@ -158,12 +155,10 @@ export function reverse(str) {
|
|
|
158
155
|
* @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
|
|
159
156
|
* @returns {number} Number of occurrences.
|
|
160
157
|
*/
|
|
161
|
-
export function countOccurrences(str, substring, caseSensitive) {
|
|
162
|
-
if (caseSensitive === void 0) { caseSensitive = true; }
|
|
158
|
+
export function countOccurrences(str, substring, caseSensitive = true) {
|
|
163
159
|
if (!caseSensitive) {
|
|
164
160
|
str = str.toLowerCase();
|
|
165
161
|
substring = substring.toLowerCase();
|
|
166
162
|
}
|
|
167
163
|
return str.split(substring).length - 1;
|
|
168
164
|
}
|
|
169
|
-
//# sourceMappingURL=string.utils.js.map
|