@gzl10/ts-helpers 4.2.1 → 4.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -189
- package/dist/types/environment-detection.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -4,230 +4,96 @@
|
|
|
4
4
|
[](https://gitlab.gzl10.com/oss/ts-helpers/-/pipelines)
|
|
5
5
|
[](LICENSE)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
entornos JavaScript modernos.**
|
|
7
|
+
Universal TypeScript utility library for modern JavaScript environments.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
env vars y manipulación de objetos anidados.
|
|
9
|
+
## Features
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
- **Flat API**: Direct access to 150+ functions without nesting
|
|
12
|
+
- **Universal**: Works in Node.js, browsers, Web Workers, and all bundlers
|
|
13
|
+
- **Tree-shakeable**: Import only what you need for minimal bundles
|
|
14
|
+
- **TypeScript-first**: Full type inference and strict mode
|
|
15
|
+
- **Spanish validation**: NIF, NIE, CIF, IBAN, phone numbers, and more
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
compatible con **todos los entornos JavaScript modernos**:
|
|
17
|
-
|
|
18
|
-
### 🎯 Compatibilidad Total
|
|
19
|
-
|
|
20
|
-
- ✅ **Navegadores modernos** (Chrome, Firefox, Safari, Edge)
|
|
21
|
-
- ✅ **Node.js** (v18+) con funcionalidades completas
|
|
22
|
-
- ✅ **Web Workers** y **Service Workers**
|
|
23
|
-
- ✅ **Bundlers** (Webpack, Vite, Rollup, Parcel)
|
|
24
|
-
- ✅ **Frameworks** (React, Vue, Angular, Svelte)
|
|
25
|
-
|
|
26
|
-
### 🏗️ Builds Multi-Environment
|
|
27
|
-
|
|
28
|
-
- **Universal Build**: 65.5KB CJS, 6.7KB ESM (crypto-free, browser-safe)
|
|
29
|
-
- **Node.js Build**: 97.9KB CJS, 7.5KB ESM (crypto completo + operaciones de
|
|
30
|
-
archivo)
|
|
31
|
-
- **Browser Build**: 7.4KB ESM (Web Crypto API + fallbacks seguros)
|
|
32
|
-
|
|
33
|
-
### 🔒 Environment Guards
|
|
34
|
-
|
|
35
|
-
- Detección automática de entorno (Node.js/Browser/Worker)
|
|
36
|
-
- Fallbacks seguros para APIs no disponibles
|
|
37
|
-
- Exports condicionales automáticos según entorno
|
|
38
|
-
|
|
39
|
-
## ✨ Características v4.1.0
|
|
40
|
-
|
|
41
|
-
### 🆕 Novedades v4.1.0
|
|
42
|
-
|
|
43
|
-
- **⚙️ Configuración Avanzada**: Parsing de env vars, acceso a objetos anidados
|
|
44
|
-
con dot notation
|
|
45
|
-
- **🔍 Path Matching**: Wildcards para configuración, routing y permisos
|
|
46
|
-
(`features.*`)
|
|
47
|
-
- **🔄 Conversión Env Vars**: Transformación bidireccional env keys ↔ dot
|
|
48
|
-
notation paths
|
|
49
|
-
- **✅ Validación Paths**: Validación robusta de paths en dot notation
|
|
50
|
-
|
|
51
|
-
### v4.0.x Foundation
|
|
52
|
-
|
|
53
|
-
- **🎯 API Plana Revolucionaria**: Acceso directo (`g.validateNIF()` vs
|
|
54
|
-
`g.validation.validators.validateNIF()`)
|
|
55
|
-
- **⚡ Performance Extrema**: Build 70-90% más rápido (~40ms vs ~45s), bundle
|
|
56
|
-
69% menor (603KB→185KB)
|
|
57
|
-
- **🌲 Tree-shaking Optimizado**: Importaciones específicas por módulo
|
|
58
|
-
preservadas
|
|
59
|
-
- **📦 Arquitectura Consolidada**: 15 módulos exportados por dominio
|
|
60
|
-
- **🔧 Tooling Moderno**: pnpm + changeset + vitest + tsup
|
|
61
|
-
- **🌐 Environment Detection**: Detección avanzada Node.js/Browser con soporte
|
|
62
|
-
proxy
|
|
63
|
-
- **🇪🇸 Validación Española**: 150+ funciones - NIF, NIE, CIF, teléfonos, IBAN
|
|
64
|
-
- **📊 Manejo de Datos**: CSV, JSON, Tree con detección automática de formato
|
|
65
|
-
- **📁 Detección Universal**: 80+ formatos con categorización inteligente
|
|
66
|
-
- **✅ Testing Compatible**: Exports optimizados para Vitest y bundlers modernos
|
|
67
|
-
- **📚 Documentación JSDoc 100%**: 80+ funciones con ejemplos profesionales y
|
|
68
|
-
casos de uso reales
|
|
69
|
-
|
|
70
|
-
## Instalación
|
|
17
|
+
## Installation
|
|
71
18
|
|
|
72
19
|
```bash
|
|
73
|
-
# Con pnpm (recomendado)
|
|
74
20
|
pnpm add @gzl10/ts-helpers
|
|
75
|
-
|
|
76
|
-
# Con npm
|
|
21
|
+
# or
|
|
77
22
|
npm install @gzl10/ts-helpers
|
|
78
23
|
```
|
|
79
24
|
|
|
80
|
-
##
|
|
25
|
+
## Usage
|
|
81
26
|
|
|
82
|
-
### API
|
|
27
|
+
### Flat API (Recommended)
|
|
83
28
|
|
|
84
29
|
```typescript
|
|
85
30
|
import g from '@gzl10/ts-helpers'
|
|
86
31
|
|
|
87
|
-
//
|
|
88
|
-
g.validateNIF('12345678Z')
|
|
89
|
-
g.generateSpanishNIF()
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
g.
|
|
93
|
-
g.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
32
|
+
// Validation
|
|
33
|
+
g.validateNIF('12345678Z')
|
|
34
|
+
g.generateSpanishNIF()
|
|
35
|
+
|
|
36
|
+
// Strings
|
|
37
|
+
g.toCamelCase('hello-world')
|
|
38
|
+
g.sanitizeString('<script>alert("xss")</script>')
|
|
39
|
+
|
|
40
|
+
// Math & Finance
|
|
41
|
+
g.calculateNPV(0.1, [-1000, 300, 400, 500])
|
|
42
|
+
g.calculateIRR([-1000, 300, 400, 500])
|
|
43
|
+
|
|
44
|
+
// Async
|
|
45
|
+
g.sleep(1000)
|
|
46
|
+
g.runBatch(items, processFn, { concurrency: 5 })
|
|
47
|
+
|
|
48
|
+
// Data
|
|
49
|
+
g.exportData(data, 'file.csv')
|
|
50
|
+
g.detectUniversalFormat('report.xlsx')
|
|
51
|
+
|
|
52
|
+
// Objects
|
|
53
|
+
g.deepEqual(obj1, obj2)
|
|
100
54
|
g.setDeepValue(config, 'database.host', 'localhost')
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
g.
|
|
104
|
-
g.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
g.
|
|
109
|
-
g.
|
|
110
|
-
g.isProduction() // true en producción
|
|
111
|
-
g.isNonProduction() // true en dev, test, undefined
|
|
112
|
-
g.detectProtocol(req) // 'https' con soporte proxy
|
|
113
|
-
g.isLocalhost('localhost') // true
|
|
114
|
-
console.log(g.isNode) // true en Node.js
|
|
115
|
-
|
|
116
|
-
// Detección universal de formatos (80+ tipos)
|
|
117
|
-
g.detectFileExtension('report.xlsx') // 'xlsx'
|
|
118
|
-
g.detectUniversalFormat('presentation.pptx')
|
|
119
|
-
// { extension: 'pptx', category: 'presentation', mimeType: '...', isText: false }
|
|
55
|
+
|
|
56
|
+
// Dates
|
|
57
|
+
g.formatNow('DD/MM/YYYY')
|
|
58
|
+
g.addDays(new Date(), 7)
|
|
59
|
+
|
|
60
|
+
// Environment
|
|
61
|
+
g.isDevelopment()
|
|
62
|
+
g.isProduction()
|
|
63
|
+
g.detectProtocol(req)
|
|
120
64
|
```
|
|
121
65
|
|
|
122
|
-
###
|
|
66
|
+
### Tree-shaking Imports
|
|
123
67
|
|
|
124
68
|
```typescript
|
|
125
|
-
// 🌲 Para bundles mínimos - importa solo lo que necesitas
|
|
126
69
|
import { validateNIF, generateSpanishNIF } from '@gzl10/ts-helpers/validation'
|
|
127
70
|
import { exportData, importData } from '@gzl10/ts-helpers/data'
|
|
128
|
-
import { parseEnvValue } from '@gzl10/ts-helpers/environment'
|
|
129
|
-
import { setDeepValue, getDeepValue } from '@gzl10/ts-helpers/objects'
|
|
130
|
-
import {
|
|
131
|
-
matchPathPattern,
|
|
132
|
-
envKeyToPath,
|
|
133
|
-
pathToEnvKey,
|
|
134
|
-
} from '@gzl10/ts-helpers/strings'
|
|
135
|
-
import { isValidDotNotationPath } from '@gzl10/ts-helpers/validation'
|
|
136
71
|
import { toCamelCase, sanitizeString } from '@gzl10/ts-helpers/strings'
|
|
137
72
|
import { sleep, runBatch } from '@gzl10/ts-helpers/async'
|
|
138
73
|
import { calculateNPV, calculateIRR } from '@gzl10/ts-helpers/math'
|
|
139
74
|
import { formatNow, addDays } from '@gzl10/ts-helpers/dates'
|
|
140
|
-
import { deepEqual,
|
|
141
|
-
import {
|
|
142
|
-
isDevelopment,
|
|
143
|
-
isTest,
|
|
144
|
-
isProduction,
|
|
145
|
-
isNonProduction,
|
|
146
|
-
detectProtocol,
|
|
147
|
-
} from '@gzl10/ts-helpers/environment'
|
|
148
|
-
import {
|
|
149
|
-
detectFileExtension,
|
|
150
|
-
detectUniversalFormat,
|
|
151
|
-
} from '@gzl10/ts-helpers/data'
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## 🔄 Migración
|
|
155
|
-
|
|
156
|
-
### 🆕 v4.2.0 - Detección de entorno mejorada
|
|
157
|
-
|
|
158
|
-
**⚠️ BREAKING CHANGE**: `isDevelopment()` ahora retorna `false` en entorno
|
|
159
|
-
`test`
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
// ❌ Antes (v4.1.0)
|
|
163
|
-
if (isDevelopment()) {
|
|
164
|
-
// Se ejecutaba en dev Y test
|
|
165
|
-
enableDebugMode()
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// ✅ Ahora (v4.2.0) - Opciones según necesidad
|
|
169
|
-
if (isDevelopment()) {
|
|
170
|
-
// Solo en development (excluye test)
|
|
171
|
-
enableHotReload()
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (isTest()) {
|
|
175
|
-
// Solo en tests
|
|
176
|
-
mockExternalAPIs()
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (isNonProduction()) {
|
|
180
|
-
// En dev, test y undefined (comportamiento anterior de isDevelopment)
|
|
181
|
-
enableDebugMode()
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### 🔄 Migración desde v3.x
|
|
186
|
-
|
|
187
|
-
**BREAKING CHANGES v4.0.0**
|
|
188
|
-
|
|
189
|
-
```typescript
|
|
190
|
-
// ❌ v3.x - API anidada redundante
|
|
191
|
-
g.validation.validators.validateNIF('12345678Z')
|
|
192
|
-
g.primitives.string.toCamelCase('hello-world')
|
|
193
|
-
g.core.async.sleep(1000)
|
|
194
|
-
|
|
195
|
-
// ✅ v4.0.0 - API plana directa
|
|
196
|
-
g.validateNIF('12345678Z')
|
|
197
|
-
g.toCamelCase('hello-world')
|
|
198
|
-
g.sleep(1000)
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
**Dependencias Eliminadas**
|
|
202
|
-
|
|
203
|
-
Las re-exportaciones fueron eliminadas. Instala por separado si las necesitas:
|
|
204
|
-
|
|
205
|
-
```bash
|
|
206
|
-
npm install lodash axios dayjs numeral qs ms
|
|
75
|
+
import { deepEqual, setDeepValue } from '@gzl10/ts-helpers/objects'
|
|
76
|
+
import { isDevelopment, isProduction } from '@gzl10/ts-helpers/environment'
|
|
207
77
|
```
|
|
208
78
|
|
|
209
|
-
##
|
|
79
|
+
## Documentation
|
|
210
80
|
|
|
211
|
-
- **[USAGE-GUIDE.md](USAGE-GUIDE.md)** -
|
|
212
|
-
|
|
213
|
-
- **[CHANGELOG.md](CHANGELOG.md)** - 📝 Historial de cambios detallado
|
|
214
|
-
- **[GitLab Issues](https://gitlab.gzl10.com/oss/ts-helpers/-/issues)** - 🐛
|
|
215
|
-
Reportar bugs
|
|
81
|
+
- **[USAGE-GUIDE.md](USAGE-GUIDE.md)** - Complete API reference
|
|
82
|
+
- **[CHANGELOG.md](CHANGELOG.md)** - Version history
|
|
216
83
|
|
|
217
|
-
##
|
|
84
|
+
## Development
|
|
218
85
|
|
|
219
86
|
```bash
|
|
220
|
-
pnpm install
|
|
221
|
-
pnpm
|
|
222
|
-
pnpm test
|
|
223
|
-
pnpm
|
|
224
|
-
pnpm release:prepare # Changeset
|
|
87
|
+
pnpm install
|
|
88
|
+
pnpm build
|
|
89
|
+
pnpm test
|
|
90
|
+
pnpm lint
|
|
225
91
|
```
|
|
226
92
|
|
|
227
|
-
##
|
|
93
|
+
## Support
|
|
228
94
|
|
|
229
95
|
<a href="https://www.buymeacoffee.com/gzl10g" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
230
96
|
|
|
231
|
-
##
|
|
97
|
+
## License
|
|
232
98
|
|
|
233
99
|
MIT © [Gonzalo Díez](mailto:gonzalo@gzl10.com)
|
|
@@ -96,7 +96,7 @@ declare const getCryptoCapabilities: () => {
|
|
|
96
96
|
webCrypto: boolean;
|
|
97
97
|
nodeCrypto: boolean;
|
|
98
98
|
fallbackOnly: boolean;
|
|
99
|
-
environment: "
|
|
99
|
+
environment: "browser" | "node" | "unknown" | "worker";
|
|
100
100
|
};
|
|
101
101
|
|
|
102
102
|
export { getCryptoCapabilities, getEnvironmentType, isBrowserEnv, isNodeCryptoAvailable, isNodeEnv, isWebCryptoAvailable, isWorkerEnvironment };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ declare const g: {
|
|
|
26
26
|
webCrypto: boolean;
|
|
27
27
|
nodeCrypto: boolean;
|
|
28
28
|
fallbackOnly: boolean;
|
|
29
|
-
environment: "
|
|
29
|
+
environment: "browser" | "node" | "unknown" | "worker";
|
|
30
30
|
};
|
|
31
31
|
isNodeEnvironment(): boolean;
|
|
32
32
|
isBrowserEnvironment(): boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gzl10/ts-helpers",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "Librería de utilidades TypeScript con herramientas especializadas para desarrollo web, validación española, manejo de datos y operaciones asíncronas.",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -149,12 +149,15 @@
|
|
|
149
149
|
"./package.json": "./package.json",
|
|
150
150
|
"./dist/*": "./dist/*"
|
|
151
151
|
},
|
|
152
|
-
"author":
|
|
152
|
+
"author": {
|
|
153
|
+
"name": "Gonzalo Díez",
|
|
154
|
+
"email": "gonzalo@gzl10.com"
|
|
155
|
+
},
|
|
153
156
|
"repository": {
|
|
154
157
|
"type": "git",
|
|
155
158
|
"url": "https://gitlab.gzl10.com/oss/ts-helpers.git"
|
|
156
159
|
},
|
|
157
|
-
"homepage": "https://
|
|
160
|
+
"homepage": "https://www.gzl10.com",
|
|
158
161
|
"bugs": {
|
|
159
162
|
"url": "https://gitlab.gzl10.com/oss/ts-helpers/-/issues"
|
|
160
163
|
},
|