@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.
- package/CHANGELOG.md +320 -0
- package/README.md +233 -0
- package/USAGE-GUIDE.md +800 -0
- package/dist/browser/async.js +15 -0
- package/dist/browser/async.js.map +1 -0
- package/dist/browser/chunk-4O7ZPIJN.js +383 -0
- package/dist/browser/chunk-4O7ZPIJN.js.map +1 -0
- package/dist/browser/chunk-75XNTC34.js +60 -0
- package/dist/browser/chunk-75XNTC34.js.map +1 -0
- package/dist/browser/chunk-C3D7YZVE.js +299 -0
- package/dist/browser/chunk-C3D7YZVE.js.map +1 -0
- package/dist/browser/chunk-CZL6C2EI.js +452 -0
- package/dist/browser/chunk-CZL6C2EI.js.map +1 -0
- package/dist/browser/chunk-D4FZFIVA.js +240 -0
- package/dist/browser/chunk-D4FZFIVA.js.map +1 -0
- package/dist/browser/chunk-IL7NG7IC.js +72 -0
- package/dist/browser/chunk-IL7NG7IC.js.map +1 -0
- package/dist/browser/chunk-NSBPE2FW.js +17 -0
- package/dist/browser/chunk-NSBPE2FW.js.map +1 -0
- package/dist/browser/chunk-SLQVNPTH.js +27 -0
- package/dist/browser/chunk-SLQVNPTH.js.map +1 -0
- package/dist/browser/chunk-WG7ILCUB.js +195 -0
- package/dist/browser/chunk-WG7ILCUB.js.map +1 -0
- package/dist/browser/chunk-WJA4JDMZ.js +278 -0
- package/dist/browser/chunk-WJA4JDMZ.js.map +1 -0
- package/dist/browser/chunk-ZFVYLUTT.js +65 -0
- package/dist/browser/chunk-ZFVYLUTT.js.map +1 -0
- package/dist/browser/chunk-ZYTSVMTI.js +263 -0
- package/dist/browser/chunk-ZYTSVMTI.js.map +1 -0
- package/dist/browser/dates.js +78 -0
- package/dist/browser/dates.js.map +1 -0
- package/dist/browser/environment-detection.js +21 -0
- package/dist/browser/environment-detection.js.map +1 -0
- package/dist/browser/environment.js +34 -0
- package/dist/browser/environment.js.map +1 -0
- package/dist/browser/errors.js +18 -0
- package/dist/browser/errors.js.map +1 -0
- package/dist/browser/index.js +412 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/math.js +51 -0
- package/dist/browser/math.js.map +1 -0
- package/dist/browser/number.js +10 -0
- package/dist/browser/number.js.map +1 -0
- package/dist/browser/objects.js +31 -0
- package/dist/browser/objects.js.map +1 -0
- package/dist/browser/strings.js +80 -0
- package/dist/browser/strings.js.map +1 -0
- package/dist/browser/validation-core.js +54 -0
- package/dist/browser/validation-core.js.map +1 -0
- package/dist/browser/validation-crypto.js +28 -0
- package/dist/browser/validation-crypto.js.map +1 -0
- package/dist/browser/validators.js +98 -0
- package/dist/browser/validators.js.map +1 -0
- package/dist/cjs/async.js +86 -0
- package/dist/cjs/async.js.map +1 -0
- package/dist/cjs/dates.js +285 -0
- package/dist/cjs/dates.js.map +1 -0
- package/dist/cjs/environment-detection.js +84 -0
- package/dist/cjs/environment-detection.js.map +1 -0
- package/dist/cjs/environment.js +261 -0
- package/dist/cjs/environment.js.map +1 -0
- package/dist/cjs/errors.js +80 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +2035 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/math.js +388 -0
- package/dist/cjs/math.js.map +1 -0
- package/dist/cjs/number.js +37 -0
- package/dist/cjs/number.js.map +1 -0
- package/dist/cjs/objects.js +249 -0
- package/dist/cjs/objects.js.map +1 -0
- package/dist/cjs/strings.js +253 -0
- package/dist/cjs/strings.js.map +1 -0
- package/dist/cjs/validation.js +450 -0
- package/dist/cjs/validation.js.map +1 -0
- package/dist/esm/async.js +15 -0
- package/dist/esm/async.js.map +1 -0
- package/dist/esm/chunk-4O7ZPIJN.js +383 -0
- package/dist/esm/chunk-4O7ZPIJN.js.map +1 -0
- package/dist/esm/chunk-75XNTC34.js +60 -0
- package/dist/esm/chunk-75XNTC34.js.map +1 -0
- package/dist/esm/chunk-BDOBKBKA.js +72 -0
- package/dist/esm/chunk-BDOBKBKA.js.map +1 -0
- package/dist/esm/chunk-C3D7YZVE.js +299 -0
- package/dist/esm/chunk-C3D7YZVE.js.map +1 -0
- package/dist/esm/chunk-CZL6C2EI.js +452 -0
- package/dist/esm/chunk-CZL6C2EI.js.map +1 -0
- package/dist/esm/chunk-EBLSTOEC.js +263 -0
- package/dist/esm/chunk-EBLSTOEC.js.map +1 -0
- package/dist/esm/chunk-NSBPE2FW.js +17 -0
- package/dist/esm/chunk-NSBPE2FW.js.map +1 -0
- package/dist/esm/chunk-SLQVNPTH.js +27 -0
- package/dist/esm/chunk-SLQVNPTH.js.map +1 -0
- package/dist/esm/chunk-WG7ILCUB.js +195 -0
- package/dist/esm/chunk-WG7ILCUB.js.map +1 -0
- package/dist/esm/chunk-WJA4JDMZ.js +278 -0
- package/dist/esm/chunk-WJA4JDMZ.js.map +1 -0
- package/dist/esm/chunk-ZFVYLUTT.js +65 -0
- package/dist/esm/chunk-ZFVYLUTT.js.map +1 -0
- package/dist/esm/dates.js +78 -0
- package/dist/esm/dates.js.map +1 -0
- package/dist/esm/environment-detection.js +21 -0
- package/dist/esm/environment-detection.js.map +1 -0
- package/dist/esm/environment.js +34 -0
- package/dist/esm/environment.js.map +1 -0
- package/dist/esm/errors.js +18 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +380 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/math.js +51 -0
- package/dist/esm/math.js.map +1 -0
- package/dist/esm/number.js +10 -0
- package/dist/esm/number.js.map +1 -0
- package/dist/esm/objects.js +31 -0
- package/dist/esm/objects.js.map +1 -0
- package/dist/esm/strings.js +80 -0
- package/dist/esm/strings.js.map +1 -0
- package/dist/esm/validation.js +54 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/node/async.js +93 -0
- package/dist/node/async.js.map +1 -0
- package/dist/node/csv.js +102 -0
- package/dist/node/csv.js.map +1 -0
- package/dist/node/data.js +880 -0
- package/dist/node/data.js.map +1 -0
- package/dist/node/dates.js +324 -0
- package/dist/node/dates.js.map +1 -0
- package/dist/node/environment.js +278 -0
- package/dist/node/environment.js.map +1 -0
- package/dist/node/errors.js +89 -0
- package/dist/node/errors.js.map +1 -0
- package/dist/node/index.js +3151 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/json.js +107 -0
- package/dist/node/json.js.map +1 -0
- package/dist/node/math.js +413 -0
- package/dist/node/math.js.map +1 -0
- package/dist/node/number.js +42 -0
- package/dist/node/number.js.map +1 -0
- package/dist/node/objects.js +264 -0
- package/dist/node/objects.js.map +1 -0
- package/dist/node/strings.js +293 -0
- package/dist/node/strings.js.map +1 -0
- package/dist/node/tree.js +89 -0
- package/dist/node/tree.js.map +1 -0
- package/dist/node/validation-core.js +477 -0
- package/dist/node/validation-core.js.map +1 -0
- package/dist/node/validation-crypto.js +179 -0
- package/dist/node/validation-crypto.js.map +1 -0
- package/dist/node/validation.js +677 -0
- package/dist/node/validation.js.map +1 -0
- package/dist/node/validators.js +123 -0
- package/dist/node/validators.js.map +1 -0
- package/dist/node-esm/async.js +15 -0
- package/dist/node-esm/async.js.map +1 -0
- package/dist/node-esm/chunk-3YOF7NPT.js +299 -0
- package/dist/node-esm/chunk-3YOF7NPT.js.map +1 -0
- package/dist/node-esm/chunk-64TBXJQS.js +263 -0
- package/dist/node-esm/chunk-64TBXJQS.js.map +1 -0
- package/dist/node-esm/chunk-75XNTC34.js +60 -0
- package/dist/node-esm/chunk-75XNTC34.js.map +1 -0
- package/dist/node-esm/chunk-C4PKXIPB.js +278 -0
- package/dist/node-esm/chunk-C4PKXIPB.js.map +1 -0
- package/dist/node-esm/chunk-CMDFZME3.js +452 -0
- package/dist/node-esm/chunk-CMDFZME3.js.map +1 -0
- package/dist/node-esm/chunk-DZZPUYMP.js +74 -0
- package/dist/node-esm/chunk-DZZPUYMP.js.map +1 -0
- package/dist/node-esm/chunk-HTSEHRHI.js +195 -0
- package/dist/node-esm/chunk-HTSEHRHI.js.map +1 -0
- package/dist/node-esm/chunk-JCAUVOPH.js +27 -0
- package/dist/node-esm/chunk-JCAUVOPH.js.map +1 -0
- package/dist/node-esm/chunk-KBHE3K2F.js +505 -0
- package/dist/node-esm/chunk-KBHE3K2F.js.map +1 -0
- package/dist/node-esm/chunk-LYTET5NX.js +65 -0
- package/dist/node-esm/chunk-LYTET5NX.js.map +1 -0
- package/dist/node-esm/chunk-PZ5AY32C.js +10 -0
- package/dist/node-esm/chunk-PZ5AY32C.js.map +1 -0
- package/dist/node-esm/chunk-UKGXL2QO.js +383 -0
- package/dist/node-esm/chunk-UKGXL2QO.js.map +1 -0
- package/dist/node-esm/chunk-XAEYT23H.js +164 -0
- package/dist/node-esm/chunk-XAEYT23H.js.map +1 -0
- package/dist/node-esm/csv.js +63 -0
- package/dist/node-esm/csv.js.map +1 -0
- package/dist/node-esm/data.js +32 -0
- package/dist/node-esm/data.js.map +1 -0
- package/dist/node-esm/dates.js +78 -0
- package/dist/node-esm/dates.js.map +1 -0
- package/dist/node-esm/environment.js +34 -0
- package/dist/node-esm/environment.js.map +1 -0
- package/dist/node-esm/errors.js +18 -0
- package/dist/node-esm/errors.js.map +1 -0
- package/dist/node-esm/index.js +426 -0
- package/dist/node-esm/index.js.map +1 -0
- package/dist/node-esm/json.js +68 -0
- package/dist/node-esm/json.js.map +1 -0
- package/dist/node-esm/math.js +51 -0
- package/dist/node-esm/math.js.map +1 -0
- package/dist/node-esm/number.js +10 -0
- package/dist/node-esm/number.js.map +1 -0
- package/dist/node-esm/objects.js +31 -0
- package/dist/node-esm/objects.js.map +1 -0
- package/dist/node-esm/strings.js +80 -0
- package/dist/node-esm/strings.js.map +1 -0
- package/dist/node-esm/tree.js +8 -0
- package/dist/node-esm/tree.js.map +1 -0
- package/dist/node-esm/validation-core.js +54 -0
- package/dist/node-esm/validation-core.js.map +1 -0
- package/dist/node-esm/validation-crypto.js +26 -0
- package/dist/node-esm/validation-crypto.js.map +1 -0
- package/dist/node-esm/validation.js +606 -0
- package/dist/node-esm/validation.js.map +1 -0
- package/dist/node-esm/validators.js +98 -0
- package/dist/node-esm/validators.js.map +1 -0
- package/dist/types/async-C8gvbSG-.d.ts +453 -0
- package/dist/types/async.d.ts +1 -0
- package/dist/types/csv.d.ts +226 -0
- package/dist/types/data.d.ts +1561 -0
- package/dist/types/dates-hTiE0Z11.d.ts +298 -0
- package/dist/types/dates.d.ts +1 -0
- package/dist/types/environment-B8eLS7KT.d.ts +420 -0
- package/dist/types/environment-detection.d.ts +102 -0
- package/dist/types/environment.d.ts +1 -0
- package/dist/types/errors.d.ts +147 -0
- package/dist/types/index.d.ts +211 -0
- package/dist/types/json.d.ts +284 -0
- package/dist/types/math-BQ9Lwdp7.d.ts +2060 -0
- package/dist/types/math.d.ts +1 -0
- package/dist/types/number-CYnQfLWj.d.ts +44 -0
- package/dist/types/number.d.ts +1 -0
- package/dist/types/objects-BohS8GCS.d.ts +1185 -0
- package/dist/types/objects.d.ts +1 -0
- package/dist/types/strings-CiqRPYLL.d.ts +1349 -0
- package/dist/types/strings.d.ts +1 -0
- package/dist/types/tree.d.ts +284 -0
- package/dist/types/validation-core-DfHF8rCG.d.ts +238 -0
- package/dist/types/validation-crypto-browser.d.ts +56 -0
- package/dist/types/validation-crypto-node.d.ts +31 -0
- package/dist/types/validation.d.ts +1 -0
- package/dist/types/validators.d.ts +216 -0
- package/package.json +253 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection utilities for universal browser/Node.js compatibility
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Detailed criteria used for environment debugging and analysis
|
|
6
|
+
*/
|
|
7
|
+
interface EnvironmentCriteria {
|
|
8
|
+
/** True if hostname is localhost, 127.0.0.1, ::1, or .localhost/.local domain */
|
|
9
|
+
isLocalhost: boolean;
|
|
10
|
+
/** True if hostname is within private IP ranges (10.x, 192.168.x, 172.16-31.x) */
|
|
11
|
+
isPrivateIP: boolean;
|
|
12
|
+
/** True if port is in development range (3000-9999) */
|
|
13
|
+
isDevelopmentPort: boolean;
|
|
14
|
+
/** True if development tools are detected (Vue DevTools, __DEV__ global) */
|
|
15
|
+
hasDevtools: boolean;
|
|
16
|
+
/** Current NODE_ENV value (Node.js only) */
|
|
17
|
+
nodeEnv?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Complete environment information with platform detection and debugging criteria
|
|
21
|
+
*/
|
|
22
|
+
interface EnvironmentInfo {
|
|
23
|
+
/** Runtime platform: 'browser', 'node', or 'unknown' */
|
|
24
|
+
platform: 'browser' | 'node' | 'unknown';
|
|
25
|
+
/** Detected environment: 'development', 'production', or 'test' */
|
|
26
|
+
environment: 'development' | 'production' | 'test';
|
|
27
|
+
/** Protocol used (http/https) - from location or request headers */
|
|
28
|
+
protocol?: string;
|
|
29
|
+
/** Hostname - from location or request headers */
|
|
30
|
+
hostname?: string;
|
|
31
|
+
/** Browser user agent string (browser only) */
|
|
32
|
+
userAgent?: string;
|
|
33
|
+
/** Detailed debugging criteria */
|
|
34
|
+
criteria?: EnvironmentCriteria;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detects if the current runtime is Node.js environment
|
|
38
|
+
*
|
|
39
|
+
* Checks for the presence of Node.js-specific globals (process, process.versions.node)
|
|
40
|
+
* and absence of browser globals (window).
|
|
41
|
+
*
|
|
42
|
+
* @returns True if running in Node.js, false otherwise
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* if (isNodeEnvironment()) {
|
|
47
|
+
* // Node.js specific code
|
|
48
|
+
* const fs = require('fs')
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare function isNodeEnvironment(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Detects if the current runtime is a browser environment
|
|
55
|
+
*
|
|
56
|
+
* Checks for the presence of browser-specific globals (window, document).
|
|
57
|
+
* Also handles testing environments that may mock these globals.
|
|
58
|
+
*
|
|
59
|
+
* @returns True if running in browser, false otherwise
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* if (isBrowserEnvironment()) {
|
|
64
|
+
* // Browser specific code
|
|
65
|
+
* const url = window.location.href
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
declare function isBrowserEnvironment(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Detects if the application is running in development mode
|
|
72
|
+
*
|
|
73
|
+
* Uses sophisticated detection logic based on multiple criteria:
|
|
74
|
+
* - Node.js: NODE_ENV variable, request headers (for Express), hostname/protocol analysis
|
|
75
|
+
* - Browser: __DEV__ global, development ports (3000-9999), localhost/private IPs, dev tools
|
|
76
|
+
*
|
|
77
|
+
* Handles reverse proxies correctly by checking forwarded headers.
|
|
78
|
+
*
|
|
79
|
+
* @param req - Optional Express request object for server-side detection
|
|
80
|
+
* @returns True if in development mode, false if production
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Node.js - simple check
|
|
85
|
+
* if (isDevelopment()) {
|
|
86
|
+
* console.log('Development mode')
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* // Express - with request context
|
|
93
|
+
* app.get('/api/status', (req, res) => {
|
|
94
|
+
* const isDev = isDevelopment(req)
|
|
95
|
+
* res.json({ environment: isDev ? 'dev' : 'prod' })
|
|
96
|
+
* })
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // Browser - automatic detection
|
|
102
|
+
* if (isDevelopment()) {
|
|
103
|
+
* // Enable debug logging, dev tools, etc.
|
|
104
|
+
* enableDebugMode()
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
declare function isDevelopment(req?: any): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Detects if the application is running in production mode
|
|
111
|
+
*
|
|
112
|
+
* Simple inverse of isDevelopment() with additional NODE_ENV validation for Node.js.
|
|
113
|
+
*
|
|
114
|
+
* @returns True if in production mode, false if development
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* if (isProduction()) {
|
|
119
|
+
* // Enable performance optimizations
|
|
120
|
+
* enableProductionMode()
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
declare function isProduction(): boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Detects if the application is running in test mode
|
|
127
|
+
*
|
|
128
|
+
* Checks explicitly for NODE_ENV === 'test' in Node.js environments.
|
|
129
|
+
* Vitest and Jest automatically set this value when running tests.
|
|
130
|
+
*
|
|
131
|
+
* @returns True if NODE_ENV is 'test', false otherwise
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* if (isTest()) {
|
|
136
|
+
* // Test-specific behavior (mocks, fixtures, etc.)
|
|
137
|
+
* enableTestMode()
|
|
138
|
+
* }
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* // Conditional imports for testing
|
|
144
|
+
* if (isTest()) {
|
|
145
|
+
* const { mockAPI } = await import('./test/mocks')
|
|
146
|
+
* mockAPI.setup()
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
declare function isTest(): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Detects if the application is NOT running in production mode
|
|
153
|
+
*
|
|
154
|
+
* Returns true for development, test, undefined, or any non-production environment.
|
|
155
|
+
* Useful for enabling debugging, logging, or development-only features
|
|
156
|
+
* across all non-production environments.
|
|
157
|
+
*
|
|
158
|
+
* @returns True if not in production (development, test, or undefined)
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* if (isNonProduction()) {
|
|
163
|
+
* // Enable debug logging for dev and test
|
|
164
|
+
* console.log('Debug mode enabled')
|
|
165
|
+
* enableVerboseLogging()
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Security: Disable strict checks in non-production
|
|
172
|
+
* if (isNonProduction()) {
|
|
173
|
+
* allowSelfSignedCertificates()
|
|
174
|
+
* disableCSRFProtection()
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function isNonProduction(): boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Detects the protocol (HTTP/HTTPS) from browser location or request headers
|
|
181
|
+
*
|
|
182
|
+
* Handles reverse proxies correctly by checking forwarded headers in priority order:
|
|
183
|
+
* 1. X-Forwarded-Proto (most common)
|
|
184
|
+
* 2. X-Forwarded-Protocol
|
|
185
|
+
* 3. X-Url-Scheme
|
|
186
|
+
* 4. Front-End-Https
|
|
187
|
+
* 5. CF-Visitor (Cloudflare specific)
|
|
188
|
+
*
|
|
189
|
+
* @param req - Optional Express request object with headers
|
|
190
|
+
* @returns Protocol as 'http' or 'https'
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Browser usage
|
|
195
|
+
* const protocol = detectProtocol() // 'https' from window.location
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Express server with proxy
|
|
201
|
+
* app.get('/api', (req, res) => {
|
|
202
|
+
* const protocol = detectProtocol(req) // Detects from X-Forwarded-Proto
|
|
203
|
+
* const fullUrl = `${protocol}://${req.get('host')}${req.path}`
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
declare function detectProtocol(req?: any): 'http' | 'https';
|
|
208
|
+
/**
|
|
209
|
+
* Extracts hostname from browser location or request headers
|
|
210
|
+
*
|
|
211
|
+
* Handles reverse proxies by checking forwarded headers in priority order:
|
|
212
|
+
* 1. X-Forwarded-Host (most common, supports multiple hosts)
|
|
213
|
+
* 2. X-Original-Host
|
|
214
|
+
* 3. Host header
|
|
215
|
+
*
|
|
216
|
+
* Automatically strips port numbers and handles multiple comma-separated hosts.
|
|
217
|
+
*
|
|
218
|
+
* @param req - Optional Express request object with headers
|
|
219
|
+
* @returns Hostname without port number
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Browser usage
|
|
224
|
+
* const hostname = detectHostname() // 'example.com' from window.location
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```typescript
|
|
229
|
+
* // Express server behind proxy
|
|
230
|
+
* app.get('/api', (req, res) => {
|
|
231
|
+
* const hostname = detectHostname(req) // 'api.example.com' from X-Forwarded-Host
|
|
232
|
+
* const isLocal = isLocalhost(hostname)
|
|
233
|
+
* })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function detectHostname(req?: any): string;
|
|
237
|
+
/**
|
|
238
|
+
* Checks if a hostname represents localhost or local development
|
|
239
|
+
*
|
|
240
|
+
* Recognizes various localhost representations:
|
|
241
|
+
* - 'localhost' (standard)
|
|
242
|
+
* - '127.0.0.1' (IPv4 loopback)
|
|
243
|
+
* - '::1' (IPv6 loopback)
|
|
244
|
+
* - '*.localhost' (local development domains)
|
|
245
|
+
* - '*.local' (mDNS local domains)
|
|
246
|
+
*
|
|
247
|
+
* @param hostname - Hostname to check
|
|
248
|
+
* @returns True if hostname represents localhost
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* isLocalhost('localhost') // true
|
|
253
|
+
* isLocalhost('127.0.0.1') // true
|
|
254
|
+
* isLocalhost('app.localhost') // true
|
|
255
|
+
* isLocalhost('macbook.local') // true
|
|
256
|
+
* isLocalhost('example.com') // false
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
declare function isLocalhost(hostname: string): boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Checks if a hostname is within private IP address ranges
|
|
262
|
+
*
|
|
263
|
+
* Recognizes private/internal IP ranges according to RFC 1918:
|
|
264
|
+
* - IPv4: 10.x.x.x, 192.168.x.x, 172.16-31.x.x, 127.x.x.x (loopback)
|
|
265
|
+
* - IPv6: ::1 (loopback), fc00::/7 (unique local), fe80::/10 (link-local)
|
|
266
|
+
* - Also includes localhost detection
|
|
267
|
+
*
|
|
268
|
+
* @param hostname - Hostname or IP address to check
|
|
269
|
+
* @returns True if hostname is private/local, false if public
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* isPrivateIP('192.168.1.1') // true
|
|
274
|
+
* isPrivateIP('10.0.0.1') // true
|
|
275
|
+
* isPrivateIP('172.16.0.1') // true
|
|
276
|
+
* isPrivateIP('localhost') // true
|
|
277
|
+
* isPrivateIP('8.8.8.8') // false
|
|
278
|
+
* isPrivateIP('example.com') // false
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
declare function isPrivateIP(hostname: string): boolean;
|
|
282
|
+
/**
|
|
283
|
+
* Gathers complete environment information for debugging and analysis
|
|
284
|
+
*
|
|
285
|
+
* Returns comprehensive environment data including platform detection,
|
|
286
|
+
* development/production status, protocol/hostname information, and
|
|
287
|
+
* detailed debugging criteria.
|
|
288
|
+
*
|
|
289
|
+
* @param req - Optional Express request object for server-side context
|
|
290
|
+
* @returns Complete environment information object
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* // Basic usage
|
|
295
|
+
* const env = getEnvironmentInfo()
|
|
296
|
+
* console.log(env.platform) // 'node' | 'browser' | 'unknown'
|
|
297
|
+
* console.log(env.environment) // 'development' | 'production' | 'test'
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* // Express server usage
|
|
303
|
+
* app.get('/api/debug', (req, res) => {
|
|
304
|
+
* const envInfo = getEnvironmentInfo(req)
|
|
305
|
+
* res.json({
|
|
306
|
+
* platform: envInfo.platform,
|
|
307
|
+
* isDev: envInfo.environment === 'development',
|
|
308
|
+
* protocol: envInfo.protocol,
|
|
309
|
+
* host: envInfo.hostname,
|
|
310
|
+
* criteria: envInfo.criteria
|
|
311
|
+
* })
|
|
312
|
+
* })
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* // Conditional features based on environment
|
|
318
|
+
* const env = getEnvironmentInfo()
|
|
319
|
+
* if (env.criteria?.hasDevtools) {
|
|
320
|
+
* enableVueDevtools()
|
|
321
|
+
* }
|
|
322
|
+
* if (env.criteria?.isDevelopmentPort) {
|
|
323
|
+
* enableHotReload()
|
|
324
|
+
* }
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
declare function getEnvironmentInfo(req?: any): EnvironmentInfo;
|
|
328
|
+
/**
|
|
329
|
+
* Alias for isNodeEnvironment() - detects Node.js runtime
|
|
330
|
+
* @see {@link isNodeEnvironment}
|
|
331
|
+
*/
|
|
332
|
+
declare const isNode: typeof isNodeEnvironment;
|
|
333
|
+
/**
|
|
334
|
+
* Alias for isBrowserEnvironment() - detects browser runtime
|
|
335
|
+
* @see {@link isBrowserEnvironment}
|
|
336
|
+
*/
|
|
337
|
+
declare const isBrowser: typeof isBrowserEnvironment;
|
|
338
|
+
/**
|
|
339
|
+
* Parses environment variable string values to their native JavaScript types
|
|
340
|
+
*
|
|
341
|
+
* Automatically detects and converts:
|
|
342
|
+
* - Booleans: 'true', 'false', 'yes', 'no', '1', '0'
|
|
343
|
+
* - Numbers: '42', '3.14', '-100'
|
|
344
|
+
* - JSON arrays: '[1,2,3]', '["a","b"]'
|
|
345
|
+
* - JSON objects: '{"key":"value"}'
|
|
346
|
+
* - Comma-separated arrays: 'item1,item2,item3' (when not valid JSON)
|
|
347
|
+
* - null/undefined: 'null', 'undefined', empty string
|
|
348
|
+
*
|
|
349
|
+
* Falls back to original string if no conversion applies.
|
|
350
|
+
*
|
|
351
|
+
* @param value - Environment variable string value to parse
|
|
352
|
+
* @returns Parsed value with appropriate native type
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* // Boolean conversion
|
|
357
|
+
* parseEnvValue('true') // true
|
|
358
|
+
* parseEnvValue('false') // false
|
|
359
|
+
* parseEnvValue('yes') // true
|
|
360
|
+
* parseEnvValue('1') // true (as boolean)
|
|
361
|
+
*
|
|
362
|
+
* // Number conversion
|
|
363
|
+
* parseEnvValue('42') // 42
|
|
364
|
+
* parseEnvValue('3.14') // 3.14
|
|
365
|
+
* parseEnvValue('-100') // -100
|
|
366
|
+
*
|
|
367
|
+
* // JSON arrays
|
|
368
|
+
* parseEnvValue('[1,2,3]') // [1, 2, 3]
|
|
369
|
+
* parseEnvValue('["a","b"]') // ['a', 'b']
|
|
370
|
+
*
|
|
371
|
+
* // JSON objects
|
|
372
|
+
* parseEnvValue('{"port":3000,"host":"localhost"}')
|
|
373
|
+
* // { port: 3000, host: 'localhost' }
|
|
374
|
+
*
|
|
375
|
+
* // Comma-separated arrays (fallback when not JSON)
|
|
376
|
+
* parseEnvValue('red,green,blue') // ['red', 'green', 'blue']
|
|
377
|
+
*
|
|
378
|
+
* // Null/undefined
|
|
379
|
+
* parseEnvValue('null') // null
|
|
380
|
+
* parseEnvValue('undefined') // undefined
|
|
381
|
+
* parseEnvValue('') // undefined
|
|
382
|
+
*
|
|
383
|
+
* // Strings (no conversion)
|
|
384
|
+
* parseEnvValue('hello') // 'hello'
|
|
385
|
+
* ```
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* // Real-world usage with process.env
|
|
390
|
+
* const config = {
|
|
391
|
+
* debug: parseEnvValue(process.env.DEBUG), // 'true' → true
|
|
392
|
+
* port: parseEnvValue(process.env.PORT), // '3000' → 3000
|
|
393
|
+
* features: parseEnvValue(process.env.FEATURES), // 'auth,api' → ['auth', 'api']
|
|
394
|
+
* database: parseEnvValue(process.env.DB_CONFIG), // '{"host":"localhost"}' → object
|
|
395
|
+
* }
|
|
396
|
+
* ```
|
|
397
|
+
*/
|
|
398
|
+
declare function parseEnvValue(value: string | undefined): any;
|
|
399
|
+
|
|
400
|
+
type environment_EnvironmentCriteria = EnvironmentCriteria;
|
|
401
|
+
type environment_EnvironmentInfo = EnvironmentInfo;
|
|
402
|
+
declare const environment_detectHostname: typeof detectHostname;
|
|
403
|
+
declare const environment_detectProtocol: typeof detectProtocol;
|
|
404
|
+
declare const environment_getEnvironmentInfo: typeof getEnvironmentInfo;
|
|
405
|
+
declare const environment_isBrowser: typeof isBrowser;
|
|
406
|
+
declare const environment_isBrowserEnvironment: typeof isBrowserEnvironment;
|
|
407
|
+
declare const environment_isDevelopment: typeof isDevelopment;
|
|
408
|
+
declare const environment_isLocalhost: typeof isLocalhost;
|
|
409
|
+
declare const environment_isNode: typeof isNode;
|
|
410
|
+
declare const environment_isNodeEnvironment: typeof isNodeEnvironment;
|
|
411
|
+
declare const environment_isNonProduction: typeof isNonProduction;
|
|
412
|
+
declare const environment_isPrivateIP: typeof isPrivateIP;
|
|
413
|
+
declare const environment_isProduction: typeof isProduction;
|
|
414
|
+
declare const environment_isTest: typeof isTest;
|
|
415
|
+
declare const environment_parseEnvValue: typeof parseEnvValue;
|
|
416
|
+
declare namespace environment {
|
|
417
|
+
export { type environment_EnvironmentCriteria as EnvironmentCriteria, type environment_EnvironmentInfo as EnvironmentInfo, environment_detectHostname as detectHostname, environment_detectProtocol as detectProtocol, environment_getEnvironmentInfo as getEnvironmentInfo, environment_isBrowser as isBrowser, environment_isBrowserEnvironment as isBrowserEnvironment, environment_isDevelopment as isDevelopment, environment_isLocalhost as isLocalhost, environment_isNode as isNode, environment_isNodeEnvironment as isNodeEnvironment, environment_isNonProduction as isNonProduction, environment_isPrivateIP as isPrivateIP, environment_isProduction as isProduction, environment_isTest as isTest, environment_parseEnvValue as parseEnvValue };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export { type EnvironmentInfo as E, isNodeEnvironment as a, type EnvironmentCriteria as b, isDevelopment as c, isProduction as d, environment as e, isTest as f, isNonProduction as g, detectProtocol as h, isBrowserEnvironment as i, detectHostname as j, isLocalhost as k, isPrivateIP as l, getEnvironmentInfo as m, isNode as n, isBrowser as o, parseEnvValue as p };
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { i as isBrowserEnvironment, a as isNodeEnvironment } from './environment-B8eLS7KT.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Universal crypto capabilities detection utilities
|
|
5
|
+
* Safe for all environments with comprehensive fallbacks
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Enhanced browser environment detection with additional checks
|
|
10
|
+
* @returns true if running in a browser environment
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* if (isBrowserEnv()) {
|
|
14
|
+
* console.log('Running in browser')
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
declare const isBrowserEnv: typeof isBrowserEnvironment;
|
|
19
|
+
/**
|
|
20
|
+
* Enhanced Node.js environment detection with additional checks
|
|
21
|
+
* @returns true if running in Node.js environment
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* if (isNodeEnv()) {
|
|
25
|
+
* console.log('Running in Node.js')
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare const isNodeEnv: typeof isNodeEnvironment;
|
|
30
|
+
/**
|
|
31
|
+
* Detects if running in Worker environment (Web Workers, Service Workers)
|
|
32
|
+
* @returns true if running in a Worker context
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* if (isWorkerEnvironment()) {
|
|
36
|
+
* console.log('Running in Web Worker')
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare const isWorkerEnvironment: () => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Detects if Web Crypto API is available in the current environment
|
|
43
|
+
* @returns true if crypto.getRandomValues and crypto.subtle are available
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* if (isWebCryptoAvailable()) {
|
|
47
|
+
* const array = new Uint8Array(16)
|
|
48
|
+
* crypto.getRandomValues(array)
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare const isWebCryptoAvailable: () => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Detects if Node.js crypto module is available
|
|
55
|
+
* @returns true if Node.js crypto module with hash and random functions is available
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* if (isNodeCryptoAvailable()) {
|
|
59
|
+
* const crypto = require('crypto')
|
|
60
|
+
* const hash = crypto.createHash('sha256')
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare const isNodeCryptoAvailable: () => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the current environment type with automatic detection
|
|
67
|
+
* @returns The detected environment type
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* const env = getEnvironmentType()
|
|
71
|
+
* switch (env) {
|
|
72
|
+
* case 'node': console.log('Server-side'); break
|
|
73
|
+
* case 'browser': console.log('Client-side'); break
|
|
74
|
+
* case 'worker': console.log('Worker thread'); break
|
|
75
|
+
* case 'unknown': console.log('Unknown environment'); break
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare const getEnvironmentType: () => "node" | "browser" | "worker" | "unknown";
|
|
80
|
+
/**
|
|
81
|
+
* Gets available crypto capabilities for the current environment
|
|
82
|
+
* @returns Object containing crypto capability information
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* const caps = getCryptoCapabilities()
|
|
86
|
+
* console.log(caps)
|
|
87
|
+
* // {
|
|
88
|
+
* // webCrypto: true,
|
|
89
|
+
* // nodeCrypto: false,
|
|
90
|
+
* // fallbackOnly: false,
|
|
91
|
+
* // environment: 'browser'
|
|
92
|
+
* // }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
declare const getCryptoCapabilities: () => {
|
|
96
|
+
webCrypto: boolean;
|
|
97
|
+
nodeCrypto: boolean;
|
|
98
|
+
fallbackOnly: boolean;
|
|
99
|
+
environment: "node" | "browser" | "worker" | "unknown";
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export { getCryptoCapabilities, getEnvironmentType, isBrowserEnv, isNodeCryptoAvailable, isNodeEnv, isWebCryptoAvailable, isWorkerEnvironment };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { b as EnvironmentCriteria, E as EnvironmentInfo, j as detectHostname, h as detectProtocol, m as getEnvironmentInfo, o as isBrowser, i as isBrowserEnvironment, c as isDevelopment, k as isLocalhost, n as isNode, a as isNodeEnvironment, g as isNonProduction, l as isPrivateIP, d as isProduction, f as isTest, p as parseEnvValue } from './environment-B8eLS7KT.js';
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error handling utilities with specific error types and codes
|
|
3
|
+
* Provides structured error handling for validation, data processing, and environment issues
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Enumeration of specific error codes for different failure scenarios
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // Using error codes for type-safe error handling
|
|
10
|
+
* try {
|
|
11
|
+
* validateNIF('invalid')
|
|
12
|
+
* } catch (error) {
|
|
13
|
+
* if (error.code === TsHelpersErrorCode.VALIDATION_FAILED) {
|
|
14
|
+
* console.log('Validation error:', error.data)
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare enum TsHelpersErrorCode {
|
|
20
|
+
/** Validation of input data failed (NIF, email, etc.) */
|
|
21
|
+
VALIDATION_FAILED = "VALIDATION_FAILED",
|
|
22
|
+
/** Error processing data (CSV, JSON, aggregations, etc.) */
|
|
23
|
+
DATA_PROCESSING_FAILED = "DATA_PROCESSING_FAILED",
|
|
24
|
+
/** Current environment doesn't support the operation */
|
|
25
|
+
ENVIRONMENT_NOT_SUPPORTED = "ENVIRONMENT_NOT_SUPPORTED",
|
|
26
|
+
/** File format not supported for import/export */
|
|
27
|
+
UNSUPPORTED_FORMAT = "UNSUPPORTED_FORMAT",
|
|
28
|
+
/** File system operation failed */
|
|
29
|
+
FILE_ERROR = "FILE_ERROR",
|
|
30
|
+
/** Network or fetch operation failed */
|
|
31
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
32
|
+
/** Invalid operation or function call */
|
|
33
|
+
INVALID_OPERATION = "INVALID_OPERATION",
|
|
34
|
+
/** Crypto operation failed (hash, token generation) */
|
|
35
|
+
CRYPTO_ERROR = "CRYPTO_ERROR",
|
|
36
|
+
/** Math calculation failed (invalid input, division by zero) */
|
|
37
|
+
MATH_ERROR = "MATH_ERROR",
|
|
38
|
+
/** Generic unknown error */
|
|
39
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for creating TsHelpersError instances
|
|
43
|
+
*/
|
|
44
|
+
interface TsHelpersErrorOptions {
|
|
45
|
+
/** Specific error code for categorization */
|
|
46
|
+
code?: TsHelpersErrorCode;
|
|
47
|
+
/** Additional data about the error context */
|
|
48
|
+
data?: any;
|
|
49
|
+
/** Original error that caused this error */
|
|
50
|
+
cause?: Error;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Main error class for @g10/ts-helpers with structured error information
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* // Creating structured errors
|
|
57
|
+
* throw new TsHelpersError('Invalid NIF format', {
|
|
58
|
+
* code: TsHelpersErrorCode.VALIDATION_FAILED,
|
|
59
|
+
* data: { input: '12345', expected: '8 digits + letter' }
|
|
60
|
+
* })
|
|
61
|
+
*
|
|
62
|
+
* // Error handling with type checking
|
|
63
|
+
* try {
|
|
64
|
+
* someOperation()
|
|
65
|
+
* } catch (error) {
|
|
66
|
+
* if (error instanceof TsHelpersError) {
|
|
67
|
+
* console.log('Error code:', error.code)
|
|
68
|
+
* console.log('Error data:', error.data)
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
declare class TsHelpersError extends Error {
|
|
74
|
+
readonly code?: TsHelpersErrorCode;
|
|
75
|
+
readonly data?: any;
|
|
76
|
+
readonly cause?: Error;
|
|
77
|
+
constructor(message: string, options?: TsHelpersErrorOptions);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Specialized error class for data processing operations
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* // Data processing errors
|
|
84
|
+
* throw new DataError(
|
|
85
|
+
* 'Failed to parse CSV',
|
|
86
|
+
* TsHelpersErrorCode.DATA_PROCESSING_FAILED,
|
|
87
|
+
* { line: 5, column: 'amount' }
|
|
88
|
+
* )
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare class DataError extends TsHelpersError {
|
|
92
|
+
constructor(message: string, code?: TsHelpersErrorCode, data?: any);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates a validation error with structured information
|
|
96
|
+
* @param message - Descriptive error message
|
|
97
|
+
* @param field - Field name that failed validation
|
|
98
|
+
* @param value - Value that failed validation
|
|
99
|
+
* @returns TsHelpersError with validation context
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* // Using in validation functions
|
|
103
|
+
* if (!isValidEmail(email)) {
|
|
104
|
+
* throw createValidationError('Invalid email format', 'email', email)
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* // Error contains structured data
|
|
108
|
+
* // error.code === TsHelpersErrorCode.VALIDATION_FAILED
|
|
109
|
+
* // error.data === { field: 'email', value: 'invalid-email' }
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function createValidationError(message: string, field: string, value: any): TsHelpersError;
|
|
113
|
+
/**
|
|
114
|
+
* Creates a crypto operation error
|
|
115
|
+
* @param message - Descriptive error message
|
|
116
|
+
* @param operation - Crypto operation that failed
|
|
117
|
+
* @param details - Additional error details
|
|
118
|
+
* @returns TsHelpersError with crypto context
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* // Using in crypto functions
|
|
122
|
+
* if (!crypto.getRandomValues) {
|
|
123
|
+
* throw createCryptoError('Web Crypto API not available', 'generateSecureToken', {
|
|
124
|
+
* environment: 'browser',
|
|
125
|
+
* fallback: 'Math.random'
|
|
126
|
+
* })
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
declare function createCryptoError(message: string, operation: string, details?: any): TsHelpersError;
|
|
131
|
+
/**
|
|
132
|
+
* Creates a math calculation error
|
|
133
|
+
* @param message - Descriptive error message
|
|
134
|
+
* @param operation - Math operation that failed
|
|
135
|
+
* @param input - Input data that caused the error
|
|
136
|
+
* @returns TsHelpersError with math context
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* // Using in math functions
|
|
140
|
+
* if (values.length === 0) {
|
|
141
|
+
* throw createMathError('Cannot calculate median of empty array', 'calculateMedian', values)
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
declare function createMathError(message: string, operation: string, input?: any): TsHelpersError;
|
|
146
|
+
|
|
147
|
+
export { DataError, TsHelpersError, TsHelpersErrorCode, type TsHelpersErrorOptions, createCryptoError, createMathError, createValidationError };
|