@gzl10/ts-helpers 4.2.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.
Files changed (240) hide show
  1. package/CHANGELOG.md +320 -0
  2. package/README.md +233 -0
  3. package/USAGE-GUIDE.md +800 -0
  4. package/dist/browser/async.js +15 -0
  5. package/dist/browser/async.js.map +1 -0
  6. package/dist/browser/chunk-4O7ZPIJN.js +383 -0
  7. package/dist/browser/chunk-4O7ZPIJN.js.map +1 -0
  8. package/dist/browser/chunk-75XNTC34.js +60 -0
  9. package/dist/browser/chunk-75XNTC34.js.map +1 -0
  10. package/dist/browser/chunk-C3D7YZVE.js +299 -0
  11. package/dist/browser/chunk-C3D7YZVE.js.map +1 -0
  12. package/dist/browser/chunk-CZL6C2EI.js +452 -0
  13. package/dist/browser/chunk-CZL6C2EI.js.map +1 -0
  14. package/dist/browser/chunk-D4FZFIVA.js +240 -0
  15. package/dist/browser/chunk-D4FZFIVA.js.map +1 -0
  16. package/dist/browser/chunk-IL7NG7IC.js +72 -0
  17. package/dist/browser/chunk-IL7NG7IC.js.map +1 -0
  18. package/dist/browser/chunk-NSBPE2FW.js +17 -0
  19. package/dist/browser/chunk-NSBPE2FW.js.map +1 -0
  20. package/dist/browser/chunk-SLQVNPTH.js +27 -0
  21. package/dist/browser/chunk-SLQVNPTH.js.map +1 -0
  22. package/dist/browser/chunk-WG7ILCUB.js +195 -0
  23. package/dist/browser/chunk-WG7ILCUB.js.map +1 -0
  24. package/dist/browser/chunk-WJA4JDMZ.js +278 -0
  25. package/dist/browser/chunk-WJA4JDMZ.js.map +1 -0
  26. package/dist/browser/chunk-ZFVYLUTT.js +65 -0
  27. package/dist/browser/chunk-ZFVYLUTT.js.map +1 -0
  28. package/dist/browser/chunk-ZYTSVMTI.js +263 -0
  29. package/dist/browser/chunk-ZYTSVMTI.js.map +1 -0
  30. package/dist/browser/dates.js +78 -0
  31. package/dist/browser/dates.js.map +1 -0
  32. package/dist/browser/environment-detection.js +21 -0
  33. package/dist/browser/environment-detection.js.map +1 -0
  34. package/dist/browser/environment.js +34 -0
  35. package/dist/browser/environment.js.map +1 -0
  36. package/dist/browser/errors.js +18 -0
  37. package/dist/browser/errors.js.map +1 -0
  38. package/dist/browser/index.js +412 -0
  39. package/dist/browser/index.js.map +1 -0
  40. package/dist/browser/math.js +51 -0
  41. package/dist/browser/math.js.map +1 -0
  42. package/dist/browser/number.js +10 -0
  43. package/dist/browser/number.js.map +1 -0
  44. package/dist/browser/objects.js +31 -0
  45. package/dist/browser/objects.js.map +1 -0
  46. package/dist/browser/strings.js +80 -0
  47. package/dist/browser/strings.js.map +1 -0
  48. package/dist/browser/validation-core.js +54 -0
  49. package/dist/browser/validation-core.js.map +1 -0
  50. package/dist/browser/validation-crypto.js +28 -0
  51. package/dist/browser/validation-crypto.js.map +1 -0
  52. package/dist/browser/validators.js +98 -0
  53. package/dist/browser/validators.js.map +1 -0
  54. package/dist/cjs/async.js +86 -0
  55. package/dist/cjs/async.js.map +1 -0
  56. package/dist/cjs/dates.js +285 -0
  57. package/dist/cjs/dates.js.map +1 -0
  58. package/dist/cjs/environment-detection.js +84 -0
  59. package/dist/cjs/environment-detection.js.map +1 -0
  60. package/dist/cjs/environment.js +261 -0
  61. package/dist/cjs/environment.js.map +1 -0
  62. package/dist/cjs/errors.js +80 -0
  63. package/dist/cjs/errors.js.map +1 -0
  64. package/dist/cjs/index.js +2035 -0
  65. package/dist/cjs/index.js.map +1 -0
  66. package/dist/cjs/math.js +388 -0
  67. package/dist/cjs/math.js.map +1 -0
  68. package/dist/cjs/number.js +37 -0
  69. package/dist/cjs/number.js.map +1 -0
  70. package/dist/cjs/objects.js +249 -0
  71. package/dist/cjs/objects.js.map +1 -0
  72. package/dist/cjs/strings.js +253 -0
  73. package/dist/cjs/strings.js.map +1 -0
  74. package/dist/cjs/validation.js +450 -0
  75. package/dist/cjs/validation.js.map +1 -0
  76. package/dist/esm/async.js +15 -0
  77. package/dist/esm/async.js.map +1 -0
  78. package/dist/esm/chunk-4O7ZPIJN.js +383 -0
  79. package/dist/esm/chunk-4O7ZPIJN.js.map +1 -0
  80. package/dist/esm/chunk-75XNTC34.js +60 -0
  81. package/dist/esm/chunk-75XNTC34.js.map +1 -0
  82. package/dist/esm/chunk-BDOBKBKA.js +72 -0
  83. package/dist/esm/chunk-BDOBKBKA.js.map +1 -0
  84. package/dist/esm/chunk-C3D7YZVE.js +299 -0
  85. package/dist/esm/chunk-C3D7YZVE.js.map +1 -0
  86. package/dist/esm/chunk-CZL6C2EI.js +452 -0
  87. package/dist/esm/chunk-CZL6C2EI.js.map +1 -0
  88. package/dist/esm/chunk-EBLSTOEC.js +263 -0
  89. package/dist/esm/chunk-EBLSTOEC.js.map +1 -0
  90. package/dist/esm/chunk-NSBPE2FW.js +17 -0
  91. package/dist/esm/chunk-NSBPE2FW.js.map +1 -0
  92. package/dist/esm/chunk-SLQVNPTH.js +27 -0
  93. package/dist/esm/chunk-SLQVNPTH.js.map +1 -0
  94. package/dist/esm/chunk-WG7ILCUB.js +195 -0
  95. package/dist/esm/chunk-WG7ILCUB.js.map +1 -0
  96. package/dist/esm/chunk-WJA4JDMZ.js +278 -0
  97. package/dist/esm/chunk-WJA4JDMZ.js.map +1 -0
  98. package/dist/esm/chunk-ZFVYLUTT.js +65 -0
  99. package/dist/esm/chunk-ZFVYLUTT.js.map +1 -0
  100. package/dist/esm/dates.js +78 -0
  101. package/dist/esm/dates.js.map +1 -0
  102. package/dist/esm/environment-detection.js +21 -0
  103. package/dist/esm/environment-detection.js.map +1 -0
  104. package/dist/esm/environment.js +34 -0
  105. package/dist/esm/environment.js.map +1 -0
  106. package/dist/esm/errors.js +18 -0
  107. package/dist/esm/errors.js.map +1 -0
  108. package/dist/esm/index.js +380 -0
  109. package/dist/esm/index.js.map +1 -0
  110. package/dist/esm/math.js +51 -0
  111. package/dist/esm/math.js.map +1 -0
  112. package/dist/esm/number.js +10 -0
  113. package/dist/esm/number.js.map +1 -0
  114. package/dist/esm/objects.js +31 -0
  115. package/dist/esm/objects.js.map +1 -0
  116. package/dist/esm/strings.js +80 -0
  117. package/dist/esm/strings.js.map +1 -0
  118. package/dist/esm/validation.js +54 -0
  119. package/dist/esm/validation.js.map +1 -0
  120. package/dist/node/async.js +93 -0
  121. package/dist/node/async.js.map +1 -0
  122. package/dist/node/csv.js +102 -0
  123. package/dist/node/csv.js.map +1 -0
  124. package/dist/node/data.js +880 -0
  125. package/dist/node/data.js.map +1 -0
  126. package/dist/node/dates.js +324 -0
  127. package/dist/node/dates.js.map +1 -0
  128. package/dist/node/environment.js +278 -0
  129. package/dist/node/environment.js.map +1 -0
  130. package/dist/node/errors.js +89 -0
  131. package/dist/node/errors.js.map +1 -0
  132. package/dist/node/index.js +3151 -0
  133. package/dist/node/index.js.map +1 -0
  134. package/dist/node/json.js +107 -0
  135. package/dist/node/json.js.map +1 -0
  136. package/dist/node/math.js +413 -0
  137. package/dist/node/math.js.map +1 -0
  138. package/dist/node/number.js +42 -0
  139. package/dist/node/number.js.map +1 -0
  140. package/dist/node/objects.js +264 -0
  141. package/dist/node/objects.js.map +1 -0
  142. package/dist/node/strings.js +293 -0
  143. package/dist/node/strings.js.map +1 -0
  144. package/dist/node/tree.js +89 -0
  145. package/dist/node/tree.js.map +1 -0
  146. package/dist/node/validation-core.js +477 -0
  147. package/dist/node/validation-core.js.map +1 -0
  148. package/dist/node/validation-crypto.js +179 -0
  149. package/dist/node/validation-crypto.js.map +1 -0
  150. package/dist/node/validation.js +677 -0
  151. package/dist/node/validation.js.map +1 -0
  152. package/dist/node/validators.js +123 -0
  153. package/dist/node/validators.js.map +1 -0
  154. package/dist/node-esm/async.js +15 -0
  155. package/dist/node-esm/async.js.map +1 -0
  156. package/dist/node-esm/chunk-3YOF7NPT.js +299 -0
  157. package/dist/node-esm/chunk-3YOF7NPT.js.map +1 -0
  158. package/dist/node-esm/chunk-64TBXJQS.js +263 -0
  159. package/dist/node-esm/chunk-64TBXJQS.js.map +1 -0
  160. package/dist/node-esm/chunk-75XNTC34.js +60 -0
  161. package/dist/node-esm/chunk-75XNTC34.js.map +1 -0
  162. package/dist/node-esm/chunk-C4PKXIPB.js +278 -0
  163. package/dist/node-esm/chunk-C4PKXIPB.js.map +1 -0
  164. package/dist/node-esm/chunk-CMDFZME3.js +452 -0
  165. package/dist/node-esm/chunk-CMDFZME3.js.map +1 -0
  166. package/dist/node-esm/chunk-DZZPUYMP.js +74 -0
  167. package/dist/node-esm/chunk-DZZPUYMP.js.map +1 -0
  168. package/dist/node-esm/chunk-HTSEHRHI.js +195 -0
  169. package/dist/node-esm/chunk-HTSEHRHI.js.map +1 -0
  170. package/dist/node-esm/chunk-JCAUVOPH.js +27 -0
  171. package/dist/node-esm/chunk-JCAUVOPH.js.map +1 -0
  172. package/dist/node-esm/chunk-KBHE3K2F.js +505 -0
  173. package/dist/node-esm/chunk-KBHE3K2F.js.map +1 -0
  174. package/dist/node-esm/chunk-LYTET5NX.js +65 -0
  175. package/dist/node-esm/chunk-LYTET5NX.js.map +1 -0
  176. package/dist/node-esm/chunk-PZ5AY32C.js +10 -0
  177. package/dist/node-esm/chunk-PZ5AY32C.js.map +1 -0
  178. package/dist/node-esm/chunk-UKGXL2QO.js +383 -0
  179. package/dist/node-esm/chunk-UKGXL2QO.js.map +1 -0
  180. package/dist/node-esm/chunk-XAEYT23H.js +164 -0
  181. package/dist/node-esm/chunk-XAEYT23H.js.map +1 -0
  182. package/dist/node-esm/csv.js +63 -0
  183. package/dist/node-esm/csv.js.map +1 -0
  184. package/dist/node-esm/data.js +32 -0
  185. package/dist/node-esm/data.js.map +1 -0
  186. package/dist/node-esm/dates.js +78 -0
  187. package/dist/node-esm/dates.js.map +1 -0
  188. package/dist/node-esm/environment.js +34 -0
  189. package/dist/node-esm/environment.js.map +1 -0
  190. package/dist/node-esm/errors.js +18 -0
  191. package/dist/node-esm/errors.js.map +1 -0
  192. package/dist/node-esm/index.js +426 -0
  193. package/dist/node-esm/index.js.map +1 -0
  194. package/dist/node-esm/json.js +68 -0
  195. package/dist/node-esm/json.js.map +1 -0
  196. package/dist/node-esm/math.js +51 -0
  197. package/dist/node-esm/math.js.map +1 -0
  198. package/dist/node-esm/number.js +10 -0
  199. package/dist/node-esm/number.js.map +1 -0
  200. package/dist/node-esm/objects.js +31 -0
  201. package/dist/node-esm/objects.js.map +1 -0
  202. package/dist/node-esm/strings.js +80 -0
  203. package/dist/node-esm/strings.js.map +1 -0
  204. package/dist/node-esm/tree.js +8 -0
  205. package/dist/node-esm/tree.js.map +1 -0
  206. package/dist/node-esm/validation-core.js +54 -0
  207. package/dist/node-esm/validation-core.js.map +1 -0
  208. package/dist/node-esm/validation-crypto.js +26 -0
  209. package/dist/node-esm/validation-crypto.js.map +1 -0
  210. package/dist/node-esm/validation.js +606 -0
  211. package/dist/node-esm/validation.js.map +1 -0
  212. package/dist/node-esm/validators.js +98 -0
  213. package/dist/node-esm/validators.js.map +1 -0
  214. package/dist/types/async-C8gvbSG-.d.ts +453 -0
  215. package/dist/types/async.d.ts +1 -0
  216. package/dist/types/csv.d.ts +226 -0
  217. package/dist/types/data.d.ts +1561 -0
  218. package/dist/types/dates-hTiE0Z11.d.ts +298 -0
  219. package/dist/types/dates.d.ts +1 -0
  220. package/dist/types/environment-B8eLS7KT.d.ts +420 -0
  221. package/dist/types/environment-detection.d.ts +102 -0
  222. package/dist/types/environment.d.ts +1 -0
  223. package/dist/types/errors.d.ts +147 -0
  224. package/dist/types/index.d.ts +211 -0
  225. package/dist/types/json.d.ts +284 -0
  226. package/dist/types/math-BQ9Lwdp7.d.ts +2060 -0
  227. package/dist/types/math.d.ts +1 -0
  228. package/dist/types/number-CYnQfLWj.d.ts +44 -0
  229. package/dist/types/number.d.ts +1 -0
  230. package/dist/types/objects-BohS8GCS.d.ts +1185 -0
  231. package/dist/types/objects.d.ts +1 -0
  232. package/dist/types/strings-CiqRPYLL.d.ts +1349 -0
  233. package/dist/types/strings.d.ts +1 -0
  234. package/dist/types/tree.d.ts +284 -0
  235. package/dist/types/validation-core-DfHF8rCG.d.ts +238 -0
  236. package/dist/types/validation-crypto-browser.d.ts +56 -0
  237. package/dist/types/validation-crypto-node.d.ts +31 -0
  238. package/dist/types/validation.d.ts +1 -0
  239. package/dist/types/validators.d.ts +216 -0
  240. package/package.json +253 -0
@@ -0,0 +1,211 @@
1
+ export { b as generateAlphaNumericString, a as generateAlphaString, c as generateComplexString, l as generateEmail, n as generateHexColor, m as generatePassword, g as generateRandomInteger, i as generateSpanishCIF, k as generateSpanishIBAN, h as generateSpanishNIE, f as generateSpanishNIF, j as generateSpanishPostalCode, e as generateUsername, d as generateUsernameFromEmail, r as isValidCIF, u as isValidEmail, x as isValidJSON, q as isValidNIE, o as isValidNIF, y as isValidSpanishIBAN, t as isValidSpanishPhone, s as isValidSpanishPostalCode, w as isValidURL, p as validateNIF, v as validation } from './validation-core-DfHF8rCG.js';
2
+ export { j as capitalizeEachWord, i as capitalizeFirst, c as cleanJsonChars, o as contains, C as countOccurrences, q as endsWith, e as ensureEndsWith, d as ensureStartsWith, K as envKeyToPath, H as escapeHtmlChars, E as isEmail, D as isEmpty, J as matchPathPattern, v as padEnd, r as padStart, L as pathToEnvKey, G as removeAccents, A as repeatString, B as replaceAllOccurrences, z as reverseString, a as sanitizeString, p as startsWith, s as strings, b as stripFromEnd, f as stripFromStart, k as toCamelCase, m as toKebabCase, g as toLowerCase, n as toPascalCase, l as toSnakeCase, h as toUpperCase, F as toUrlSlug, w as trim, y as trimEnd, x as trimStart, t as truncateString, I as unescapeHtmlChars, u as unescapeUnicode } from './strings-CiqRPYLL.js';
3
+ export { a as calculateDifferences, c as comparator, d as deepEqual, i as deleteArrayElementsBy, f as formatToReadableString, b as generateCrcHash, j as getDeepValue, g as getShallowProperties, h as hasSameType, o as objects, s as setDeepValue, e as updateArrayElementById, u as updateArrayElementsBy } from './objects-BohS8GCS.js';
4
+ export { p as addDays, v as addMonths, s as addNowDays, x as addNowMonths, u as addNowSeconds, z as addNowYears, q as addSeconds, y as addYears, r as areDatesEqualWithTolerance, d as dates, g as dayOfWeek, j as diffBusinessDays, h as diffDays, o as diffMilliSeconds, k as diffMonths, m as diffYears, A as excelToDate, a as format, E as formatForMysql, f as formatNow, e as fromNow, I as getFirstDayOfYear, H as getFirstWorkdayAfterMonths, F as getFirstWorkdayOfMonth, J as getLastDayOfYear, G as getLastWorkdayOfMonth, B as isDateTime, C as isEqualsDateTimeByDay, D as isExpired, i as isNew, K as isWeekday, l as longString, n as now, t as toDate, b as toDateFromString, c as toISO, w as weekOfYear } from './dates-hTiE0Z11.js';
5
+ import { I as IMathOp } from './math-BQ9Lwdp7.js';
6
+ export { c as calculateAggregations, q as calculateAnnuityPayment, k as calculateCorrelation, u as calculateEuclideanDistance, o as calculateFutureValue, t as calculateHistogram, i as calculateIQR, n as calculateIRR, v as calculateManhattanDistance, b as calculateMedian, d as calculateMode, l as calculateNPV, g as calculatePercentile, p as calculatePresentValue, h as calculateQuartiles, e as calculateStandardDeviation, a as calculateTrendSlope, f as calculateVariance, j as detectOutliers, m as math, r as normalizeToRange, s as scaleToRange, w as simpleKMeans } from './math-BQ9Lwdp7.js';
7
+ export { a as async, h as handleOperation, r as runBatch, s as sleep, w as wait } from './async-C8gvbSG-.js';
8
+ import { i as isBrowserEnvironment, a as isNodeEnvironment, E as EnvironmentInfo } from './environment-B8eLS7KT.js';
9
+ export { b as EnvironmentCriteria, j as detectHostname, h as detectProtocol, e as environment, m as getEnvironmentInfo, o as isBrowser, c as isDevelopment, k as isLocalhost, n as isNode, g as isNonProduction, l as isPrivateIP, d as isProduction, f as isTest, p as parseEnvValue } from './environment-B8eLS7KT.js';
10
+ export { i as isNumericValue, n as number, r as roundToDecimals } from './number-CYnQfLWj.js';
11
+ export { getCryptoCapabilities, getEnvironmentType, isBrowserEnv, isNodeCryptoAvailable, isNodeEnv, isWebCryptoAvailable, isWorkerEnvironment } from './environment-detection.js';
12
+
13
+ /**
14
+ * Universal exports - Safe for all environments
15
+ * No crypto dependencies - browser and Node.js compatible
16
+ */
17
+
18
+ declare const g: {
19
+ isBrowserEnv: typeof isBrowserEnvironment;
20
+ isNodeEnv: typeof isNodeEnvironment;
21
+ isWorkerEnvironment: () => boolean;
22
+ isWebCryptoAvailable: () => boolean;
23
+ isNodeCryptoAvailable: () => boolean;
24
+ getEnvironmentType: () => "node" | "browser" | "worker" | "unknown";
25
+ getCryptoCapabilities: () => {
26
+ webCrypto: boolean;
27
+ nodeCrypto: boolean;
28
+ fallbackOnly: boolean;
29
+ environment: "node" | "browser" | "worker" | "unknown";
30
+ };
31
+ isNodeEnvironment(): boolean;
32
+ isBrowserEnvironment(): boolean;
33
+ isDevelopment(req?: any): boolean;
34
+ isProduction(): boolean;
35
+ isTest(): boolean;
36
+ isNonProduction(): boolean;
37
+ detectProtocol(req?: any): "http" | "https";
38
+ detectHostname(req?: any): string;
39
+ isLocalhost(hostname: string): boolean;
40
+ isPrivateIP(hostname: string): boolean;
41
+ getEnvironmentInfo(req?: any): EnvironmentInfo;
42
+ parseEnvValue(value: string | undefined): any;
43
+ isNode: typeof isNodeEnvironment;
44
+ isBrowser: typeof isBrowserEnvironment;
45
+ isNumericValue(value: any): boolean;
46
+ roundToDecimals(num: number, decimals?: number): number;
47
+ runBatch<T>(jobs: Promise<T>[], batchSize?: number): Promise<T[]>;
48
+ handleOperation<T>(target: Record<string, any>, operation: string, ...args: any[]): Promise<T>;
49
+ sleep: (ms: number) => Promise<void>;
50
+ wait: (ms: number) => Promise<void>;
51
+ calculateTrendSlope(y: number[], x: number[]): number;
52
+ calculateAggregations: (operations: IMathOp, pgroupBy: string[], inData: any[], appendOperationToField?: boolean) => any;
53
+ calculateMedian: (values: number[]) => number;
54
+ calculateMode: (values: number[]) => number | null;
55
+ calculateStandardDeviation: (values: number[], sample?: boolean) => number;
56
+ calculateVariance: (values: number[], sample?: boolean) => number;
57
+ calculatePercentile: (values: number[], percentile: number) => number;
58
+ calculateQuartiles: (values: number[]) => {
59
+ Q1: number;
60
+ Q2: number;
61
+ Q3: number;
62
+ };
63
+ calculateIQR: (values: number[]) => number;
64
+ detectOutliers: (values: number[], multiplier?: number) => number[];
65
+ calculateCorrelation: (x: number[], y: number[]) => number;
66
+ calculateNPV: (cashFlows: number[], discountRate: number) => number;
67
+ calculateIRR: (cashFlows: number[], initialGuess?: number, maxIterations?: number, tolerance?: number) => number;
68
+ calculateFutureValue: (presentValue: number, interestRate: number, periods: number) => number;
69
+ calculatePresentValue: (futureValue: number, interestRate: number, periods: number) => number;
70
+ calculateAnnuityPayment: (presentValue: number, interestRate: number, periods: number) => number;
71
+ normalizeToRange: (values: number[]) => number[];
72
+ scaleToRange: (values: number[], minRange: number, maxRange: number) => number[];
73
+ calculateHistogram: (values: number[], bins: number) => Array<{
74
+ range: [number, number];
75
+ count: number;
76
+ }>;
77
+ calculateEuclideanDistance: (point1: number[], point2: number[]) => number;
78
+ calculateManhattanDistance: (point1: number[], point2: number[]) => number;
79
+ simpleKMeans: (points: number[][], k: number, maxIterations?: number) => {
80
+ centroids: number[][];
81
+ clusters: number[];
82
+ };
83
+ formatNow: (formatStr?: string) => string;
84
+ format: (value: any, formatStr?: string) => string;
85
+ longString: (value?: any) => string;
86
+ toDate: (value: any, isUtc?: boolean) => Date;
87
+ toDateFromString: (dateString: string, format: "DD/MM/YYYY" | "YYYY-MM-DD" | "MM/DD/YYYY" | "YYYY/MM/DD" | "DD-MM-YYYY" | "MM-DD-YYYY" | "YYYYMMDD" | "DDMMYYYY" | "MMDDYYYY" | "YYYY.MM.DD" | "DD.MM.YYYY" | "MM.DD.YYYY") => Date | null;
88
+ now: () => Date;
89
+ isNew: (value: any, daysnew?: number) => boolean;
90
+ toISO: (value?: any, isUtc?: boolean) => string;
91
+ fromNow: (value: any) => string;
92
+ dayOfWeek: (value?: any) => string;
93
+ weekOfYear: (value?: any) => string;
94
+ diffDays: (start: any, end?: any, precise?: boolean) => number;
95
+ diffBusinessDays: (start: any, end?: any, precise?: boolean) => number;
96
+ diffMonths: (value: any, valueRefOrNow?: any, precise?: boolean) => number;
97
+ diffYears: (value: any, valueRefOrNow?: any, precise?: boolean) => number;
98
+ diffMilliSeconds: (value: any, valueRefOrNow?: any) => number;
99
+ addDays: (value: any, nDays?: number) => Date;
100
+ addSeconds: (value: any, nSeconds?: number) => Date;
101
+ areDatesEqualWithTolerance: (date1: Date, date2: Date) => boolean;
102
+ addNowDays: (nDays?: number) => Date;
103
+ addNowSeconds: (nSeconds?: number) => Date;
104
+ addMonths: (value: any, nMonths?: number) => Date;
105
+ addNowMonths: (nMonths?: number) => Date;
106
+ addYears: (value: any, nYears?: number) => Date;
107
+ addNowYears: (nYears?: number) => Date;
108
+ excelToDate: (value: any) => Date | null;
109
+ isDateTime: (value: any) => boolean;
110
+ isEqualsDateTimeByDay: (value1: any, value2: any) => boolean;
111
+ isExpired: (value: any, valueRefOrNow?: any) => boolean;
112
+ formatForMysql: (fecha: Date | null) => string | null;
113
+ getFirstWorkdayOfMonth: (month?: number) => Date;
114
+ getLastWorkdayOfMonth: (month?: number) => Date;
115
+ getFirstWorkdayAfterMonths: (initialDate: Date, n: number) => Date;
116
+ getFirstDayOfYear: () => Date;
117
+ getLastDayOfYear: () => Date;
118
+ isWeekday: (date: any) => boolean;
119
+ setDeepValue<T = any>(obj: T, path: string, value: any): T;
120
+ getDeepValue<T = any>(obj: any, path: string, defaultValue?: T): T | undefined;
121
+ comparator: (data1: any, data2: any) => boolean;
122
+ deepEqual: (data1: any, data2: any) => boolean;
123
+ formatToReadableString: (data: {
124
+ [key: string]: any;
125
+ }) => string;
126
+ getShallowProperties: (obj: any) => any;
127
+ calculateDifferences: (oldObj: any, newObj: any) => any;
128
+ generateCrcHash: (str: string | Buffer | Uint8Array | any) => string;
129
+ hasSameType: (sourceTarget: any, destinationTarget: any) => boolean;
130
+ updateArrayElementsBy: (data: any[], objUpd: any, objSearch: any) => any[];
131
+ updateArrayElementById: (data: any[], objUpd: any, idField: string) => void;
132
+ deleteArrayElementsBy: (data: any[], objSearch: any) => any[];
133
+ matchPathPattern(path: string, pattern: string): boolean;
134
+ envKeyToPath(envKey: string, prefix?: string): string;
135
+ pathToEnvKey(path: string, prefix?: string): string;
136
+ sanitizeString: (instr: string | null) => string;
137
+ cleanJsonChars: (texto: string | null) => string;
138
+ truncateString: (str: string, maxlength?: number, suffix?: string) => string;
139
+ unescapeUnicode: (input: string) => string;
140
+ ensureEndsWith: (str: string, trailing: string) => string;
141
+ stripFromEnd: (str: string, trailing: string) => string;
142
+ ensureStartsWith: (str: string, leading: string) => string;
143
+ stripFromStart: (str: string, leading: string) => string;
144
+ toLowerCase: (str: string) => string;
145
+ toUpperCase: (str: string) => string;
146
+ capitalizeFirst: (str: string) => string;
147
+ capitalizeEachWord: (str: string) => string;
148
+ toCamelCase: (str: string) => string;
149
+ toSnakeCase: (str: string) => string;
150
+ toKebabCase: (str: string) => string;
151
+ toPascalCase: (str: string) => string;
152
+ contains: (str: string, searchStr: string, caseSensitive?: boolean) => boolean;
153
+ startsWith: (str: string, searchStr: string, caseSensitive?: boolean) => boolean;
154
+ endsWith: (str: string, searchStr: string, caseSensitive?: boolean) => boolean;
155
+ padStart: (str: string, length: number, padChar?: string) => string;
156
+ padEnd: (str: string, length: number, padChar?: string) => string;
157
+ trim: (str: string) => string;
158
+ trimStart: (str: string) => string;
159
+ trimEnd: (str: string) => string;
160
+ reverseString: (str: string) => string;
161
+ repeatString: (str: string, times: number) => string;
162
+ replaceAllOccurrences: (str: string, searchStr: string, replaceStr: string) => string;
163
+ countOccurrences: (str: string, searchStr: string) => number;
164
+ isEmpty: (str: string | null | undefined) => boolean;
165
+ isEmail: (str: string) => boolean;
166
+ toUrlSlug: (str: string) => string;
167
+ removeAccents: (str: string) => string;
168
+ escapeHtmlChars: (str: string) => string;
169
+ unescapeHtmlChars: (str: string) => string;
170
+ generateRandomInteger: (min?: number, max?: number) => number;
171
+ generateAlphaString: (options?: {
172
+ length?: number;
173
+ casing?: "upper" | "lower" | undefined;
174
+ }) => string;
175
+ generateAlphaNumericString: (options?: {
176
+ length?: number;
177
+ casing?: "upper" | "lower" | undefined;
178
+ }) => string;
179
+ generateComplexString: (options?: {
180
+ length?: number;
181
+ casing?: "upper" | "lower" | undefined;
182
+ }) => string;
183
+ generateUsernameFromEmail: (email: string, randomDigits?: number) => string;
184
+ generateUsername: (separator?: string, randomDigits?: number, length?: number) => string;
185
+ generateSpanishNIF: () => string;
186
+ generateSpanishNIE: () => string;
187
+ generateSpanishCIF: () => string;
188
+ generateSpanishPostalCode: () => string;
189
+ generateSpanishIBAN: () => string;
190
+ generateEmail: (domain?: string) => string;
191
+ generatePassword: (options?: {
192
+ length?: number;
193
+ includeUppercase?: boolean;
194
+ includeLowercase?: boolean;
195
+ includeNumbers?: boolean;
196
+ includeSymbols?: boolean;
197
+ }) => string;
198
+ generateHexColor: (shortFormat?: boolean) => string;
199
+ isValidNIF: (nif: string) => boolean;
200
+ validateNIF: (nif: string) => boolean;
201
+ isValidNIE: (nie: string) => boolean;
202
+ isValidCIF: (cif: string) => boolean;
203
+ isValidSpanishPostalCode: (postalCode: string) => boolean;
204
+ isValidSpanishPhone: (phone: string) => boolean;
205
+ isValidEmail: (email: string) => boolean;
206
+ isValidURL: (url: string) => boolean;
207
+ isValidJSON: (str: string) => boolean;
208
+ isValidSpanishIBAN: (iban: string) => boolean;
209
+ };
210
+
211
+ export { EnvironmentInfo, IMathOp, g as default, isBrowserEnvironment, isNodeEnvironment };
@@ -0,0 +1,284 @@
1
+ /**
2
+ * JSON Import/Export utilities
3
+ *
4
+ * Provides reliable JSON file operations for both Node.js and Browser environments.
5
+ * Features:
6
+ * - UTF-8 encoding for international character support
7
+ * - Pretty-printing with configurable indentation
8
+ * - Dual-mode: filesystem (Node.js) vs download trigger (Browser)
9
+ * - Native JSON.stringify/parse for maximum compatibility
10
+ *
11
+ * @module json
12
+ */
13
+ /**
14
+ * Exports data as JSON file with UTF-8 encoding
15
+ *
16
+ * Works in both Node.js (writes to filesystem) and Browser (triggers download).
17
+ * Uses native JSON.stringify for serialization with optional pretty-printing.
18
+ *
19
+ * Features:
20
+ * - UTF-8 encoding for international characters
21
+ * - Configurable indentation (default: 2 spaces)
22
+ * - Automatic filename extraction in browser
23
+ * - Pretty-printed by default for readability
24
+ *
25
+ * Environment behavior:
26
+ * - **Node.js**: Writes file to filesystem at specified path
27
+ * - **Browser**: Triggers automatic download with filename extracted from path
28
+ *
29
+ * ⚠️ WARNING: Cannot serialize:
30
+ * - Functions (removed silently)
31
+ * - Symbols (removed silently)
32
+ * - Circular references (throws TypeError)
33
+ * - undefined values (removed from objects, converted to null in arrays)
34
+ * - BigInt values (throws TypeError unless custom replacer provided)
35
+ *
36
+ * @param data - Any serializable JavaScript value (object, array, primitive)
37
+ * @param filePath - File path (Node.js) or download filename (Browser)
38
+ * @param options - Export options (optional)
39
+ * @param options.indent - Number of spaces for indentation (default: 2, use 0 for compact)
40
+ * @returns Promise that resolves when export completes
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Basic export - Object
45
+ * const config = {
46
+ * database: { host: 'localhost', port: 5432 },
47
+ * features: { auth: true, payments: false }
48
+ * }
49
+ *
50
+ * // Node.js - Write to file
51
+ * await exportJSON(config, './config/app.json')
52
+ * // Creates: ./config/app.json with 2-space indentation
53
+ *
54
+ * // Browser - Trigger download
55
+ * await exportJSON(config, 'app-config.json')
56
+ * // Downloads: app-config.json to browser's download folder
57
+ *
58
+ * // Compact output (no pretty-printing)
59
+ * await exportJSON(config, 'config.json', { indent: 0 })
60
+ * // Single-line JSON: {"database":{"host":"localhost","port":5432}}
61
+ * ```
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // Array export
66
+ * const users = [
67
+ * { id: 1, name: 'Alice', email: 'alice@example.com' },
68
+ * { id: 2, name: 'Bob', email: 'bob@example.com' }
69
+ * ]
70
+ * await exportJSON(users, 'users.json')
71
+ * ```
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // Real-world: Configuration backup system
76
+ * async function backupConfiguration(config: AppConfig) {
77
+ * const timestamp = new Date().toISOString().split('T')[0]
78
+ * const filename = `config-backup-${timestamp}.json`
79
+ *
80
+ * try {
81
+ * await exportJSON(config, `./backups/${filename}`, { indent: 2 })
82
+ * console.log(`✅ Configuration backed up to ${filename}`)
83
+ * } catch (error) {
84
+ * console.error('❌ Backup failed:', error)
85
+ * throw error
86
+ * }
87
+ * }
88
+ * ```
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * // Real-world: Export API response for debugging
93
+ * async function debugApiResponse(endpoint: string, data: any) {
94
+ * const filename = `api-${endpoint.replace(/\//g, '-')}.json`
95
+ * await exportJSON({
96
+ * endpoint,
97
+ * timestamp: new Date().toISOString(),
98
+ * data
99
+ * }, filename)
100
+ * }
101
+ * ```
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // Handle circular references
106
+ * const obj = { name: 'test' }
107
+ * obj.self = obj // Circular reference
108
+ *
109
+ * try {
110
+ * await exportJSON(obj, 'circular.json')
111
+ * } catch (error) {
112
+ * console.error('Cannot serialize circular structure')
113
+ * // Use custom replacer to handle circular refs
114
+ * }
115
+ * ```
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Different indentation levels
120
+ * await exportJSON(data, 'compact.json', { indent: 0 }) // Single line
121
+ * await exportJSON(data, 'readable.json', { indent: 2 }) // 2 spaces (default)
122
+ * await exportJSON(data, 'spacious.json', { indent: 4 }) // 4 spaces
123
+ * ```
124
+ *
125
+ * @throws {TypeError} If data contains circular references or BigInt values
126
+ * @throws {Error} If file write fails in Node.js (permissions, disk space, etc.)
127
+ * @see {@link importJSON} for importing JSON files
128
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify JSON.stringify Documentation}
129
+ */
130
+ declare function exportJSON(data: any, filePath: string, options?: {
131
+ indent?: number;
132
+ }): Promise<void>;
133
+ /**
134
+ * Imports JSON file and parses it to JavaScript value
135
+ *
136
+ * Reads JSON file from filesystem (Node.js only) and parses using native JSON.parse.
137
+ * Returns the parsed JavaScript value (object, array, primitive).
138
+ *
139
+ * Features:
140
+ * - UTF-8 encoding support for international characters
141
+ * - Native JSON.parse for standard-compliant parsing
142
+ * - Automatic type inference
143
+ * - Whitespace and comment tolerance (standard JSON only)
144
+ *
145
+ * ⚠️ BROWSER LIMITATION: File reading from filesystem is not supported in browsers
146
+ * for security reasons. For browser file uploads, use `readFileAsText()` with a File object
147
+ * obtained from an input[type="file"] element.
148
+ *
149
+ * @param filePath - Path to JSON file (Node.js only)
150
+ * @param _options - Reserved for future options (currently unused)
151
+ * @returns Promise<any> Parsed JavaScript value (object, array, primitive, null)
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * // Basic import - Node.js only
156
+ * const config = await importJSON('./config/app.json')
157
+ * // Returns: { database: { host: 'localhost', port: 5432 }, ... }
158
+ *
159
+ * console.log(config.database.host) // 'localhost'
160
+ *
161
+ * // Array import
162
+ * const users = await importJSON('./data/users.json')
163
+ * // Returns: [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }]
164
+ *
165
+ * // Primitive values (valid JSON)
166
+ * const version = await importJSON('./version.json') // "1.2.3"
167
+ * const enabled = await importJSON('./feature.json') // true
168
+ * const count = await importJSON('./count.json') // 42
169
+ * ```
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * // Real-world: Load configuration with fallback
174
+ * async function loadConfiguration(configPath: string): Promise<AppConfig> {
175
+ * try {
176
+ * const config = await importJSON(configPath)
177
+ *
178
+ * // Validate loaded config
179
+ * if (!config.database || !config.database.host) {
180
+ * throw new Error('Invalid configuration: missing database.host')
181
+ * }
182
+ *
183
+ * return config
184
+ * } catch (error) {
185
+ * console.warn(`Failed to load config from ${configPath}:`, error)
186
+ * console.log('Using default configuration')
187
+ * return getDefaultConfig()
188
+ * }
189
+ * }
190
+ * ```
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * // Real-world: Restore configuration backup
195
+ * async function restoreBackup(backupFile: string) {
196
+ * console.log(`Restoring configuration from ${backupFile}...`)
197
+ *
198
+ * const backup = await importJSON(`./backups/${backupFile}`)
199
+ *
200
+ * // Verify backup integrity
201
+ * if (!backup.timestamp || !backup.config) {
202
+ * throw new Error('Invalid backup file format')
203
+ * }
204
+ *
205
+ * // Restore configuration
206
+ * await saveConfiguration(backup.config)
207
+ *
208
+ * console.log(`✅ Configuration restored from ${backup.timestamp}`)
209
+ * }
210
+ * ```
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * // Browser alternative using File API
215
+ * // HTML: <input type="file" id="jsonFile" accept=".json">
216
+ *
217
+ * document.getElementById('jsonFile').addEventListener('change', async (e) => {
218
+ * const file = e.target.files[0]
219
+ *
220
+ * // Read file content
221
+ * const content = await readFileAsText(file)
222
+ *
223
+ * // Parse JSON
224
+ * try {
225
+ * const data = JSON.parse(content)
226
+ * console.log('Imported JSON:', data)
227
+ * } catch (error) {
228
+ * console.error('Invalid JSON file:', error)
229
+ * }
230
+ * })
231
+ * ```
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * // Handle parsing errors
236
+ * async function safeImportJSON(filePath: string): Promise<any | null> {
237
+ * try {
238
+ * return await importJSON(filePath)
239
+ * } catch (error) {
240
+ * if (error.message.includes('not supported in browser')) {
241
+ * console.error('Use File API for browser uploads')
242
+ * } else if (error.code === 'ENOENT') {
243
+ * console.error(`File not found: ${filePath}`)
244
+ * } else if (error instanceof SyntaxError) {
245
+ * console.error(`Invalid JSON syntax in ${filePath}:`, error.message)
246
+ * } else {
247
+ * console.error('JSON import failed:', error)
248
+ * }
249
+ * return null
250
+ * }
251
+ * }
252
+ * ```
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * // Type-safe import with validation
257
+ * interface DatabaseConfig {
258
+ * host: string
259
+ * port: number
260
+ * database: string
261
+ * }
262
+ *
263
+ * async function loadDatabaseConfig(path: string): Promise<DatabaseConfig> {
264
+ * const raw = await importJSON(path)
265
+ *
266
+ * // Runtime validation
267
+ * if (typeof raw.host !== 'string' || typeof raw.port !== 'number') {
268
+ * throw new Error('Invalid database configuration structure')
269
+ * }
270
+ *
271
+ * return raw as DatabaseConfig
272
+ * }
273
+ * ```
274
+ *
275
+ * @throws {Error} 'JSON import not supported in browser' when called in browser environment
276
+ * @throws {SyntaxError} If file contains invalid JSON syntax
277
+ * @throws {Error} File system errors (ENOENT, EACCES, etc.) in Node.js
278
+ * @see {@link exportJSON} for exporting JSON files
279
+ * @see {@link readFileAsText} for browser file reading
280
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse JSON.parse Documentation}
281
+ */
282
+ declare function importJSON(filePath: string, _options?: any): Promise<any>;
283
+
284
+ export { exportJSON, importJSON };