@naman_deep_singh/utils 2.3.0 → 2.6.0

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.
Files changed (58) hide show
  1. package/README.md +228 -129
  2. package/dist/cjs/array/arrayExtensions.js +23 -23
  3. package/dist/cjs/core/index.js +14 -16
  4. package/dist/cjs/errors/CompressionError.js +19 -0
  5. package/dist/cjs/errors/ConnectionError.js +21 -0
  6. package/dist/cjs/errors/PoolError.js +20 -0
  7. package/dist/cjs/errors/TimeoutError.js +24 -0
  8. package/dist/cjs/errors/ValidationError.js +22 -0
  9. package/dist/cjs/errors/index.js +13 -0
  10. package/dist/cjs/extensions/index.js +9 -18
  11. package/dist/cjs/init/index.js +7 -16
  12. package/dist/cjs/init/initializer.js +10 -10
  13. package/dist/cjs/number/numberExtensions.js +23 -23
  14. package/dist/cjs/object/objectExtensions.js +14 -14
  15. package/dist/cjs/string/stringExtensions.js +22 -22
  16. package/dist/cjs/types/index.js +0 -17
  17. package/dist/cjs/utils/compression.js +455 -0
  18. package/dist/cjs/utils/index.js +35 -18
  19. package/dist/cjs/utils/pool.js +375 -0
  20. package/dist/cjs/utils/timeout.js +133 -0
  21. package/dist/esm/array/arrayExtensions.js +1 -1
  22. package/dist/esm/core/index.js +3 -2
  23. package/dist/esm/errors/CompressionError.js +15 -0
  24. package/dist/esm/errors/ConnectionError.js +17 -0
  25. package/dist/esm/errors/PoolError.js +16 -0
  26. package/dist/esm/errors/TimeoutError.js +20 -0
  27. package/dist/esm/errors/ValidationError.js +18 -0
  28. package/dist/esm/errors/index.js +5 -0
  29. package/dist/esm/extensions/index.js +4 -4
  30. package/dist/esm/init/index.js +2 -2
  31. package/dist/esm/init/initializer.js +5 -5
  32. package/dist/esm/number/numberExtensions.js +2 -2
  33. package/dist/esm/object/objectExtensions.js +1 -1
  34. package/dist/esm/string/stringExtensions.js +1 -1
  35. package/dist/esm/types/index.js +1 -3
  36. package/dist/esm/utils/compression.js +415 -0
  37. package/dist/esm/utils/index.js +16 -4
  38. package/dist/esm/utils/pool.js +370 -0
  39. package/dist/esm/utils/timeout.js +128 -0
  40. package/dist/types/core/index.d.ts +3 -2
  41. package/dist/types/errors/CompressionError.d.ts +8 -0
  42. package/dist/types/errors/ConnectionError.d.ts +9 -0
  43. package/dist/types/errors/PoolError.d.ts +8 -0
  44. package/dist/types/errors/TimeoutError.d.ts +12 -0
  45. package/dist/types/errors/ValidationError.d.ts +9 -0
  46. package/dist/types/errors/index.d.ts +5 -0
  47. package/dist/types/extensions/index.d.ts +4 -4
  48. package/dist/types/init/index.d.ts +2 -2
  49. package/dist/types/init/initializer.d.ts +1 -1
  50. package/dist/types/init/options.d.ts +1 -1
  51. package/dist/types/types/extensionTypes.d.ts +1 -1
  52. package/dist/types/types/index.d.ts +1 -2
  53. package/dist/types/utils/compression.d.ts +164 -0
  54. package/dist/types/utils/config.d.ts +1 -1
  55. package/dist/types/utils/index.d.ts +11 -3
  56. package/dist/types/utils/pool.d.ts +157 -0
  57. package/dist/types/utils/timeout.d.ts +64 -0
  58. package/package.json +2 -1
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PoolError = void 0;
4
+ const errors_1 = require("@naman_deep_singh/errors");
5
+ /**
6
+ * Pool error - when pool operations fail
7
+ */
8
+ class PoolError extends errors_1.AppError {
9
+ constructor(message, poolName, details, cause) {
10
+ super(errors_1.ERROR_CODES.RESOURCE_EXHAUSTED, 503, // 503 = Service Unavailable
11
+ {
12
+ message,
13
+ poolName,
14
+ ...(details ? { details } : {}),
15
+ }, cause);
16
+ this.poolName = poolName;
17
+ this.name = 'PoolError';
18
+ }
19
+ }
20
+ exports.PoolError = PoolError;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Utility-specific error classes
4
+ * @packageDocumentation
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.TimeoutError = void 0;
8
+ const errors_1 = require("@naman_deep_singh/errors");
9
+ /**
10
+ * Timeout error - when operation times out
11
+ */
12
+ class TimeoutError extends errors_1.AppError {
13
+ constructor(message = 'Operation timed out', timeoutMs, details, cause) {
14
+ super(errors_1.ERROR_CODES.TIMEOUT_ERROR, 408, // 408 = Request Timeout
15
+ {
16
+ message,
17
+ timeoutMs,
18
+ ...(details ? { details } : {}),
19
+ }, cause);
20
+ this.timeoutMs = timeoutMs;
21
+ this.name = 'TimeoutError';
22
+ }
23
+ }
24
+ exports.TimeoutError = TimeoutError;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = void 0;
4
+ const errors_1 = require("@naman_deep_singh/errors");
5
+ /**
6
+ * Validation error - when utility input validation fails
7
+ */
8
+ class ValidationError extends errors_1.AppError {
9
+ constructor(message, field, value, details, cause) {
10
+ super(errors_1.ERROR_CODES.VALIDATION_FAILED, 400, // 400 = Bad Request
11
+ {
12
+ message,
13
+ field,
14
+ value,
15
+ ...(details ? { details } : {}),
16
+ }, cause);
17
+ this.field = field;
18
+ this.value = value;
19
+ this.name = 'ValidationError';
20
+ }
21
+ }
22
+ exports.ValidationError = ValidationError;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidationError = exports.TimeoutError = exports.PoolError = exports.ConnectionError = exports.CompressionError = void 0;
4
+ var CompressionError_js_1 = require("./CompressionError.js");
5
+ Object.defineProperty(exports, "CompressionError", { enumerable: true, get: function () { return CompressionError_js_1.CompressionError; } });
6
+ var ConnectionError_js_1 = require("./ConnectionError.js");
7
+ Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return ConnectionError_js_1.ConnectionError; } });
8
+ var PoolError_js_1 = require("./PoolError.js");
9
+ Object.defineProperty(exports, "PoolError", { enumerable: true, get: function () { return PoolError_js_1.PoolError; } });
10
+ var TimeoutError_js_1 = require("./TimeoutError.js");
11
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return TimeoutError_js_1.TimeoutError; } });
12
+ var ValidationError_js_1 = require("./ValidationError.js");
13
+ Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return ValidationError_js_1.ValidationError; } });
@@ -1,21 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extendNumber = exports.extendObject = exports.extendArray = exports.extendString = void 0;
17
4
  // Re-export all extensions
18
- __exportStar(require("../string/index.js"), exports);
19
- __exportStar(require("../array/index.js"), exports);
20
- __exportStar(require("../object/index.js"), exports);
21
- __exportStar(require("../number/index.js"), exports);
5
+ var index_js_1 = require("../string/index.js");
6
+ Object.defineProperty(exports, "extendString", { enumerable: true, get: function () { return index_js_1.extendString; } });
7
+ var index_js_2 = require("../array/index.js");
8
+ Object.defineProperty(exports, "extendArray", { enumerable: true, get: function () { return index_js_2.extendArray; } });
9
+ var index_js_3 = require("../object/index.js");
10
+ Object.defineProperty(exports, "extendObject", { enumerable: true, get: function () { return index_js_3.extendObject; } });
11
+ var index_js_4 = require("../number/index.js");
12
+ Object.defineProperty(exports, "extendNumber", { enumerable: true, get: function () { return index_js_4.extendNumber; } });
@@ -1,19 +1,10 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createExtensionOptions = exports.validateExtensionOptions = exports.extendAll = exports.initExtensions = void 0;
17
4
  // Re-export initialization logic
18
- __exportStar(require("./initializer.js"), exports);
19
- __exportStar(require("./options.js"), exports);
5
+ var initializer_js_1 = require("./initializer.js");
6
+ Object.defineProperty(exports, "initExtensions", { enumerable: true, get: function () { return initializer_js_1.initExtensions; } });
7
+ Object.defineProperty(exports, "extendAll", { enumerable: true, get: function () { return initializer_js_1.extendAll; } });
8
+ var options_js_1 = require("./options.js");
9
+ Object.defineProperty(exports, "validateExtensionOptions", { enumerable: true, get: function () { return options_js_1.validateExtensionOptions; } });
10
+ Object.defineProperty(exports, "createExtensionOptions", { enumerable: true, get: function () { return options_js_1.createExtensionOptions; } });
@@ -2,25 +2,25 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.initExtensions = initExtensions;
4
4
  exports.extendAll = extendAll;
5
- const index_js_1 = require("../array/index.js");
6
- const index_js_2 = require("../core/index.js");
7
- const index_js_3 = require("../number/index.js");
8
- const index_js_4 = require("../object/index.js");
9
- const index_js_5 = require("../string/index.js");
5
+ const arrayExtensions_js_1 = require("../array/arrayExtensions.js");
6
+ const performance_js_1 = require("../core/performance.js");
7
+ const numberExtensions_js_1 = require("../number/numberExtensions.js");
8
+ const objectExtensions_js_1 = require("../object/objectExtensions.js");
9
+ const stringExtensions_js_1 = require("../string/stringExtensions.js");
10
10
  function initExtensions(options = {}) {
11
11
  const { string = true, array = true, object = true, number = true, performance, } = options;
12
12
  if (performance) {
13
13
  // Set performance config if provided
14
- (0, index_js_2.setPerformanceConfig)(performance);
14
+ (0, performance_js_1.setPerformanceConfig)(performance);
15
15
  }
16
16
  if (string)
17
- (0, index_js_5.extendString)();
17
+ (0, stringExtensions_js_1.extendString)();
18
18
  if (array)
19
- (0, index_js_1.extendArray)();
19
+ (0, arrayExtensions_js_1.extendArray)();
20
20
  if (object)
21
- (0, index_js_4.extendObject)();
21
+ (0, objectExtensions_js_1.extendObject)();
22
22
  if (number)
23
- (0, index_js_3.extendNumber)();
23
+ (0, numberExtensions_js_1.extendNumber)();
24
24
  }
25
25
  function extendAll() {
26
26
  initExtensions();
@@ -1,36 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extendNumber = extendNumber;
4
- const index_js_1 = require("../core/index.js");
5
- const index_js_2 = require("../utils/index.js");
4
+ const performance_js_1 = require("../core/performance.js");
5
+ const defineExtension_js_1 = require("../utils/defineExtension.js");
6
6
  let numberExtended = false;
7
7
  function extendNumber() {
8
8
  if (numberExtended)
9
9
  return;
10
10
  numberExtended = true;
11
- (0, index_js_2.defineExtension)(Number.prototype, 'toPercent', function (decimals = 2) {
11
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'toPercent', function (decimals = 2) {
12
12
  return `${(this * 100).toFixed(decimals)}%`;
13
13
  });
14
- (0, index_js_2.defineExtension)(Number.prototype, 'toCurrency', function (currency = 'USD', locale = 'en-US') {
14
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'toCurrency', function (currency = 'USD', locale = 'en-US') {
15
15
  return new Intl.NumberFormat(locale, {
16
16
  style: 'currency',
17
17
  currency,
18
18
  }).format(this);
19
19
  });
20
- (0, index_js_2.defineExtension)(Number.prototype, 'clamp', function (min, max) {
20
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'clamp', function (min, max) {
21
21
  if (min > max)
22
22
  throw new RangeError(`clamp: min (${min}) cannot be greater than max (${max})`);
23
23
  return Math.min(Math.max(this, min), max);
24
24
  });
25
- (0, index_js_2.defineExtension)(Number.prototype, 'isEven', function () {
25
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'isEven', function () {
26
26
  return this % 2 === 0;
27
27
  });
28
- (0, index_js_2.defineExtension)(Number.prototype, 'isOdd', function () {
28
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'isOdd', function () {
29
29
  return this % 2 !== 0;
30
30
  });
31
- (0, index_js_2.defineExtension)(Number.prototype, 'isPrime', function () {
31
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'isPrime', function () {
32
32
  const num = this;
33
- return (0, index_js_1.withCache)((0, index_js_1.makeInternalCacheKey)('prime', num), () => {
33
+ return (0, performance_js_1.withCache)((0, performance_js_1.makeInternalCacheKey)('prime', num), () => {
34
34
  if (num < 2)
35
35
  return false;
36
36
  for (let i = 2; i <= Math.sqrt(num); i++)
@@ -39,9 +39,9 @@ function extendNumber() {
39
39
  return true;
40
40
  });
41
41
  });
42
- (0, index_js_2.defineExtension)(Number.prototype, 'factorial', function () {
42
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'factorial', function () {
43
43
  const num = Math.floor(this);
44
- return (0, index_js_1.withCache)((0, index_js_1.makeInternalCacheKey)('factorial', num), () => {
44
+ return (0, performance_js_1.withCache)((0, performance_js_1.makeInternalCacheKey)('factorial', num), () => {
45
45
  if (num < 0)
46
46
  return NaN;
47
47
  if (num <= 1)
@@ -52,19 +52,19 @@ function extendNumber() {
52
52
  return result;
53
53
  });
54
54
  });
55
- (0, index_js_2.defineExtension)(Number.prototype, 'toOrdinal', function () {
55
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'toOrdinal', function () {
56
56
  const num = Math.floor(this);
57
57
  const suffix = ['th', 'st', 'nd', 'rd'];
58
58
  const v = num % 100;
59
59
  return num + (suffix[(v - 20) % 10] || suffix[v] || suffix[0]);
60
60
  });
61
- (0, index_js_2.defineExtension)(Number.prototype, 'toRoman', function () {
61
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'toRoman', function () {
62
62
  const num = Math.floor(this);
63
63
  if (num <= 0)
64
64
  throw new RangeError('toRoman: number must be positive');
65
65
  if (num >= 4000)
66
66
  throw new RangeError('toRoman: number must be less than 4000');
67
- return (0, index_js_1.withCache)((0, index_js_1.makeInternalCacheKey)('roman', num), () => {
67
+ return (0, performance_js_1.withCache)((0, performance_js_1.makeInternalCacheKey)('roman', num), () => {
68
68
  const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
69
69
  const symbols = [
70
70
  'M',
@@ -92,47 +92,47 @@ function extendNumber() {
92
92
  return result;
93
93
  });
94
94
  });
95
- (0, index_js_2.defineExtension)(Number.prototype, 'inRange', function (min, max) {
95
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'inRange', function (min, max) {
96
96
  return this >= min && this <= max;
97
97
  });
98
- (0, index_js_2.defineExtension)(Number.prototype, 'round', function (decimals = 0) {
98
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'round', function (decimals = 0) {
99
99
  if (!Number.isInteger(decimals) || decimals < 0)
100
100
  throw new TypeError('round: decimals must be non-negative integer');
101
101
  const factor = Math.pow(10, decimals);
102
102
  return Math.round(this * factor) / factor;
103
103
  });
104
- (0, index_js_2.defineExtension)(Number.prototype, 'ceil', function (decimals = 0) {
104
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'ceil', function (decimals = 0) {
105
105
  if (!Number.isInteger(decimals) || decimals < 0)
106
106
  throw new TypeError('ceil: decimals must be non-negative integer');
107
107
  const factor = Math.pow(10, decimals);
108
108
  return Math.ceil(this * factor) / factor;
109
109
  });
110
- (0, index_js_2.defineExtension)(Number.prototype, 'floor', function (decimals = 0) {
110
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'floor', function (decimals = 0) {
111
111
  if (!Number.isInteger(decimals) || decimals < 0)
112
112
  throw new TypeError('floor: decimals must be non-negative integer');
113
113
  const factor = Math.pow(10, decimals);
114
114
  return Math.floor(this * factor) / factor;
115
115
  });
116
- (0, index_js_2.defineExtension)(Number.prototype, 'abs', function () {
116
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'abs', function () {
117
117
  return Math.abs(this);
118
118
  });
119
- (0, index_js_2.defineExtension)(Number.prototype, 'sign', function () {
119
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'sign', function () {
120
120
  return Math.sign(this);
121
121
  });
122
- (0, index_js_2.defineExtension)(Number.prototype, 'times', function (callback) {
122
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'times', function (callback) {
123
123
  if (typeof callback !== 'function')
124
124
  throw new TypeError('times: callback must be a function');
125
125
  for (let i = 0; i < Math.floor(this); i++)
126
126
  callback(i);
127
127
  });
128
- (0, index_js_2.defineExtension)(Number.prototype, 'toFixedNumber', function (decimals = 0) {
128
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'toFixedNumber', function (decimals = 0) {
129
129
  if (!Number.isInteger(decimals) || decimals < 0) {
130
130
  throw new TypeError(`toFixedNumber: decimals must be a non-negative integer, got ${decimals}`);
131
131
  }
132
132
  const factor = Math.pow(10, decimals);
133
133
  return Math.round(this.valueOf() * factor) / factor;
134
134
  });
135
- (0, index_js_2.defineExtension)(Number.prototype, 'randomUpTo', function () {
135
+ (0, defineExtension_js_1.defineExtension)(Number.prototype, 'randomUpTo', function () {
136
136
  const max = this.valueOf();
137
137
  if (!Number.isFinite(max)) {
138
138
  throw new TypeError(`randomUpTo: number must be finite, got ${max}`);
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extendObject = extendObject;
4
- const index_js_1 = require("../utils/index.js");
4
+ const defineExtension_js_1 = require("../utils/defineExtension.js");
5
5
  let objectExtended = false;
6
6
  function extendObject() {
7
7
  if (objectExtended)
8
8
  return;
9
9
  objectExtended = true;
10
- (0, index_js_1.defineExtension)(Object.prototype, 'isEmpty', function () {
10
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'isEmpty', function () {
11
11
  return Object.keys(this).length === 0;
12
12
  });
13
- (0, index_js_1.defineExtension)(Object.prototype, 'pick', function (keys) {
13
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'pick', function (keys) {
14
14
  if (!Array.isArray(keys))
15
15
  throw new TypeError('pick: keys must be an array');
16
16
  if (!keys.length)
@@ -22,7 +22,7 @@ function extendObject() {
22
22
  });
23
23
  return result;
24
24
  });
25
- (0, index_js_1.defineExtension)(Object.prototype, 'omit', function (keys) {
25
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'omit', function (keys) {
26
26
  if (!Array.isArray(keys))
27
27
  throw new TypeError('omit: keys must be an array');
28
28
  if (!keys.length)
@@ -31,7 +31,7 @@ function extendObject() {
31
31
  keys.forEach((key) => delete result[key]);
32
32
  return result;
33
33
  });
34
- (0, index_js_1.defineExtension)(Object.prototype, 'deepClone', function () {
34
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'deepClone', function () {
35
35
  const visited = new WeakSet();
36
36
  function deepCloneSafe(obj) {
37
37
  if (obj === null || typeof obj !== 'object')
@@ -51,10 +51,10 @@ function extendObject() {
51
51
  }
52
52
  return deepCloneSafe(this);
53
53
  });
54
- (0, index_js_1.defineExtension)(Object.prototype, 'merge', function (other) {
54
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'merge', function (other) {
55
55
  return { ...this, ...other };
56
56
  });
57
- (0, index_js_1.defineExtension)(Object.prototype, 'deepFreeze', function () {
57
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'deepFreeze', function () {
58
58
  Object.getOwnPropertyNames(this).forEach((name) => {
59
59
  const value = this[name];
60
60
  if (value && typeof value === 'object')
@@ -62,7 +62,7 @@ function extendObject() {
62
62
  });
63
63
  return Object.freeze(this);
64
64
  });
65
- (0, index_js_1.defineExtension)(Object.prototype, 'hasPath', function (path) {
65
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'hasPath', function (path) {
66
66
  if (!path.trim())
67
67
  throw new TypeError('hasPath: path cannot be empty');
68
68
  let current = this;
@@ -73,14 +73,14 @@ function extendObject() {
73
73
  return true;
74
74
  });
75
75
  });
76
- (0, index_js_1.defineExtension)(Object.prototype, 'getPath', function (path, defaultValue) {
76
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'getPath', function (path, defaultValue) {
77
77
  if (!path.trim())
78
78
  throw new TypeError('getPath: path cannot be empty');
79
79
  return path
80
80
  .split('.')
81
81
  .reduce((acc, key) => (acc && key in acc ? acc[key] : defaultValue), this);
82
82
  });
83
- (0, index_js_1.defineExtension)(Object.prototype, 'setPath', function (path, value) {
83
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'setPath', function (path, value) {
84
84
  if (!path.trim())
85
85
  throw new TypeError('setPath: path cannot be empty');
86
86
  const keys = path.split('.');
@@ -93,7 +93,7 @@ function extendObject() {
93
93
  current[keys[keys.length - 1]] = value;
94
94
  return this;
95
95
  });
96
- (0, index_js_1.defineExtension)(Object.prototype, 'mapValues', function (fn) {
96
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'mapValues', function (fn) {
97
97
  if (typeof fn !== 'function') {
98
98
  throw new TypeError(`mapValues: fn must be a function, got ${typeof fn}`);
99
99
  }
@@ -105,7 +105,7 @@ function extendObject() {
105
105
  }
106
106
  return result;
107
107
  });
108
- (0, index_js_1.defineExtension)(Object.prototype, 'mapKeys', function (fn) {
108
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'mapKeys', function (fn) {
109
109
  if (typeof fn !== 'function') {
110
110
  throw new TypeError(`mapKeys: fn must be a function, got ${typeof fn}`);
111
111
  }
@@ -118,7 +118,7 @@ function extendObject() {
118
118
  }
119
119
  return result;
120
120
  });
121
- (0, index_js_1.defineExtension)(Object.prototype, 'filterKeys', function (keys) {
121
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'filterKeys', function (keys) {
122
122
  if (!Array.isArray(keys)) {
123
123
  throw new TypeError(`filterKeys: keys must be an array, got ${typeof keys}`);
124
124
  }
@@ -130,7 +130,7 @@ function extendObject() {
130
130
  }
131
131
  return result;
132
132
  });
133
- (0, index_js_1.defineExtension)(Object.prototype, 'filterValues', function (fn) {
133
+ (0, defineExtension_js_1.defineExtension)(Object.prototype, 'filterValues', function (fn) {
134
134
  if (typeof fn !== 'function') {
135
135
  throw new TypeError(`filterValues: fn must be a function, got ${typeof fn}`);
136
136
  }
@@ -1,29 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extendString = extendString;
4
- const index_js_1 = require("../utils/index.js");
4
+ const defineExtension_js_1 = require("../utils/defineExtension.js");
5
5
  let stringExtended = false;
6
6
  function extendString() {
7
7
  if (stringExtended)
8
8
  return;
9
9
  stringExtended = true;
10
- (0, index_js_1.defineExtension)(String.prototype, 'toCapitalize', function () {
10
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'toCapitalize', function () {
11
11
  return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
12
12
  });
13
- (0, index_js_1.defineExtension)(String.prototype, 'toCamelCase', function () {
13
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'toCamelCase', function () {
14
14
  return this.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : '');
15
15
  });
16
- (0, index_js_1.defineExtension)(String.prototype, 'toKebabCase', function () {
16
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'toKebabCase', function () {
17
17
  return this.replace(/([a-z])([A-Z])/g, '$1-$2')
18
18
  .replace(/[\s_]+/g, '-')
19
19
  .toLowerCase();
20
20
  });
21
- (0, index_js_1.defineExtension)(String.prototype, 'toSnakeCase', function () {
21
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'toSnakeCase', function () {
22
22
  return this.replace(/([a-z])([A-Z])/g, '$1_$2')
23
23
  .replace(/[\s-]+/g, '_')
24
24
  .toLowerCase();
25
25
  });
26
- (0, index_js_1.defineExtension)(String.prototype, 'truncate', function (length, suffix = '...') {
26
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'truncate', function (length, suffix = '...') {
27
27
  if (!Number.isInteger(length) || length < 0) {
28
28
  throw new TypeError(`truncate: length must be a non-negative integer, got ${length}`);
29
29
  }
@@ -31,11 +31,11 @@ function extendString() {
31
31
  ? this.substring(0, length) + suffix
32
32
  : this.toString();
33
33
  });
34
- (0, index_js_1.defineExtension)(String.prototype, 'isEmail', function () {
34
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'isEmail', function () {
35
35
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
36
36
  return emailRegex.test(this.toString());
37
37
  });
38
- (0, index_js_1.defineExtension)(String.prototype, 'isUrl', function () {
38
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'isUrl', function () {
39
39
  try {
40
40
  new URL(this.toString());
41
41
  return true;
@@ -44,23 +44,23 @@ function extendString() {
44
44
  return false;
45
45
  }
46
46
  });
47
- (0, index_js_1.defineExtension)(String.prototype, 'removeWhitespace', function () {
47
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'removeWhitespace', function () {
48
48
  return this.replace(/\s+/g, '');
49
49
  });
50
- (0, index_js_1.defineExtension)(String.prototype, 'reverse', function () {
50
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'reverse', function () {
51
51
  return this.split('').reverse().join('');
52
52
  });
53
- (0, index_js_1.defineExtension)(String.prototype, 'isPalindrome', function () {
53
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'isPalindrome', function () {
54
54
  const cleaned = this.toLowerCase().replace(/[^a-z0-9]/g, '');
55
55
  return cleaned === cleaned.split('').reverse().join('');
56
56
  });
57
- (0, index_js_1.defineExtension)(String.prototype, 'toTitleCase', function () {
57
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'toTitleCase', function () {
58
58
  return this.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
59
59
  });
60
- (0, index_js_1.defineExtension)(String.prototype, 'stripHtml', function () {
60
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'stripHtml', function () {
61
61
  return this.replace(/<[^>]*>/g, '');
62
62
  });
63
- (0, index_js_1.defineExtension)(String.prototype, 'padStart', function (targetLength, padString = ' ') {
63
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'padStart', function (targetLength, padString = ' ') {
64
64
  if (!Number.isInteger(targetLength) || targetLength < 0) {
65
65
  throw new TypeError(`padStart: targetLength must be a non-negative integer, got ${targetLength}`);
66
66
  }
@@ -72,7 +72,7 @@ function extendString() {
72
72
  }
73
73
  return this.toString().padStart(targetLength, padString);
74
74
  });
75
- (0, index_js_1.defineExtension)(String.prototype, 'padEnd', function (targetLength, padString = ' ') {
75
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'padEnd', function (targetLength, padString = ' ') {
76
76
  if (!Number.isInteger(targetLength) || targetLength < 0) {
77
77
  throw new TypeError(`padEnd: targetLength must be a non-negative integer, got ${targetLength}`);
78
78
  }
@@ -84,7 +84,7 @@ function extendString() {
84
84
  }
85
85
  return this.toString().padEnd(targetLength, padString);
86
86
  });
87
- (0, index_js_1.defineExtension)(String.prototype, 'count', function (substring) {
87
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'count', function (substring) {
88
88
  if (typeof substring !== 'string') {
89
89
  throw new TypeError(`count: substring must be a string, got ${typeof substring}`);
90
90
  }
@@ -94,21 +94,21 @@ function extendString() {
94
94
  const escaped = substring.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
95
95
  return (this.match(new RegExp(escaped, 'g')) || []).length;
96
96
  });
97
- (0, index_js_1.defineExtension)(String.prototype, 'words', function () {
97
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'words', function () {
98
98
  return this.trim()
99
99
  .split(/\s+/)
100
100
  .filter((word) => word.length > 0);
101
101
  });
102
- (0, index_js_1.defineExtension)(String.prototype, 'lines', function () {
102
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'lines', function () {
103
103
  return this.split(/\r?\n/);
104
104
  });
105
- (0, index_js_1.defineExtension)(String.prototype, 'capitalizeWords', function () {
105
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'capitalizeWords', function () {
106
106
  return this.toString().replace(/\b\w/g, (char) => char.toUpperCase());
107
107
  });
108
- (0, index_js_1.defineExtension)(String.prototype, 'reverseWords', function () {
108
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'reverseWords', function () {
109
109
  return this.toString().split(/\s+/).reverse().join(' ');
110
110
  });
111
- (0, index_js_1.defineExtension)(String.prototype, 'truncateWords', function (count, suffix = '...') {
111
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'truncateWords', function (count, suffix = '...') {
112
112
  if (!Number.isInteger(count) || count < 0) {
113
113
  throw new TypeError(`truncateWords: count must be a non-negative integer, got ${count}`);
114
114
  }
@@ -117,7 +117,7 @@ function extendString() {
117
117
  return this.toString();
118
118
  return words.slice(0, count).join(' ') + suffix;
119
119
  });
120
- (0, index_js_1.defineExtension)(String.prototype, 'slugify', function () {
120
+ (0, defineExtension_js_1.defineExtension)(String.prototype, 'slugify', function () {
121
121
  return this.toString()
122
122
  .toLowerCase()
123
123
  .replace(/[^\w\s-]/g, '')
@@ -1,19 +1,2 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- // Re-export all types
18
- __exportStar(require("./extensionTypes.js"), exports);
19
- __exportStar(require("./globalAugmentations.js"), exports);