@oxog/utils 1.0.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.
- package/CHANGELOG.md +44 -0
- package/LICENSE +21 -0
- package/README.md +297 -0
- package/dist/index.cjs +645 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +780 -0
- package/dist/index.d.ts +780 -0
- package/dist/index.js +611 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/async.cjs +188 -0
- package/dist/plugins/async.cjs.map +1 -0
- package/dist/plugins/async.d.cts +169 -0
- package/dist/plugins/async.d.ts +169 -0
- package/dist/plugins/async.js +182 -0
- package/dist/plugins/async.js.map +1 -0
- package/dist/plugins/deep.cjs +157 -0
- package/dist/plugins/deep.cjs.map +1 -0
- package/dist/plugins/deep.d.cts +157 -0
- package/dist/plugins/deep.d.ts +157 -0
- package/dist/plugins/deep.js +152 -0
- package/dist/plugins/deep.js.map +1 -0
- package/dist/plugins/guard.cjs +47 -0
- package/dist/plugins/guard.cjs.map +1 -0
- package/dist/plugins/guard.d.cts +213 -0
- package/dist/plugins/guard.d.ts +213 -0
- package/dist/plugins/guard.js +38 -0
- package/dist/plugins/guard.js.map +1 -0
- package/dist/plugins/transform.cjs +49 -0
- package/dist/plugins/transform.cjs.map +1 -0
- package/dist/plugins/transform.d.cts +231 -0
- package/dist/plugins/transform.d.ts +231 -0
- package/dist/plugins/transform.js +42 -0
- package/dist/plugins/transform.js.map +1 -0
- package/dist/types-XmRC5wYO.d.cts +97 -0
- package/dist/types-XmRC5wYO.d.ts +97 -0
- package/package.json +115 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to @oxog/utils will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-01-15
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- Initial release of @oxog/utils
|
|
9
|
+
- Object utilities: get, set, setMut, has, pick, omit, merge, keys, values, entries, fromEntries
|
|
10
|
+
- Array utilities: groupBy, keyBy, chunk, uniq, uniqBy, flatten, compact, first, last, sample
|
|
11
|
+
- String utilities: camelCase, kebabCase, snakeCase, pascalCase, capitalize, truncate, slugify, template
|
|
12
|
+
- Deep utilities: cloneDeep, mergeDeep, isEqual, diff
|
|
13
|
+
- Async utilities: debounce, throttle, sleep, retry, timeout
|
|
14
|
+
- Type guards: isEmpty, isNil, isPlainObject, isArray, isString, isNumber, isFunction, isDate
|
|
15
|
+
- Transform utilities: mapKeys, mapValues, invert, flip, compose, pipe
|
|
16
|
+
- Full TypeScript support with strict mode
|
|
17
|
+
- Zero runtime dependencies
|
|
18
|
+
- 100% test coverage
|
|
19
|
+
- Micro-kernel plugin architecture
|
|
20
|
+
- Prototype pollution protection
|
|
21
|
+
- LLM-native design with llms.txt
|
|
22
|
+
|
|
23
|
+
### Features
|
|
24
|
+
- Type-safe path inference for object access
|
|
25
|
+
- Circular reference handling in deep operations
|
|
26
|
+
- Turkish character support in slugify
|
|
27
|
+
- Configurable debounce and throttle
|
|
28
|
+
- Exponential backoff for retry
|
|
29
|
+
- Immutable by default (with mutable alternatives)
|
|
30
|
+
- Tree-shakeable bundles
|
|
31
|
+
- ESM + CJS dual output
|
|
32
|
+
|
|
33
|
+
### Documentation
|
|
34
|
+
- Full API documentation
|
|
35
|
+
- Usage examples for all functions
|
|
36
|
+
- TypeScript examples
|
|
37
|
+
- Integration examples for Express, Fastify, NestJS, tRPC, Prisma
|
|
38
|
+
- LLM-optimized README
|
|
39
|
+
|
|
40
|
+
### Testing
|
|
41
|
+
- Vitest test suite with 100% coverage
|
|
42
|
+
- Unit tests for all functions
|
|
43
|
+
- Integration tests
|
|
44
|
+
- Mock timers for async utilities
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ersin Koรง
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# @oxog/utils
|
|
2
|
+
|
|
3
|
+
> Zero-dependency, type-safe utility functions for Node.js backends.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@oxog/utils)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
[](https://nodejs.org/)
|
|
9
|
+
[](https://github.com/ersinkoc/utils)
|
|
10
|
+
|
|
11
|
+
Modern, tree-shakeable utility library for Node.js backend development with zero dependencies. Full TypeScript support with automatic type inference.
|
|
12
|
+
|
|
13
|
+
## โจ Features
|
|
14
|
+
|
|
15
|
+
- ๐ฆ **Zero dependencies** - No runtime dependencies
|
|
16
|
+
- ๐ **Type-safe** - Written in TypeScript with full type inference
|
|
17
|
+
- ๐ณ **Tree-shakeable** - Import only what you need
|
|
18
|
+
- ๐ก๏ธ **Secure** - Prototype pollution protection built-in
|
|
19
|
+
- โก **Performant** - Immutable by default, optimized for Node.js backends
|
|
20
|
+
- ๐งช **Well-tested** - 216 tests with 100% success rate
|
|
21
|
+
- ๐ **LLM-native** - Designed for AI/LLM code generation
|
|
22
|
+
|
|
23
|
+
## ๐ฆ Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @oxog/utils
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## ๐ Quick Start
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { get, set, groupBy, camelCase } from '@oxog/utils';
|
|
33
|
+
|
|
34
|
+
// Object utilities
|
|
35
|
+
const user = { name: 'Ersin', address: { city: 'Istanbul' } };
|
|
36
|
+
const city = get(user, 'address.city'); // 'Istanbul'
|
|
37
|
+
const updated = set(user, 'name', 'Ali'); // new object, immutable
|
|
38
|
+
|
|
39
|
+
// Array utilities
|
|
40
|
+
const users = [
|
|
41
|
+
{ id: 1, name: 'Alice', role: 'admin' },
|
|
42
|
+
{ id: 2, name: 'Bob', role: 'user' }
|
|
43
|
+
];
|
|
44
|
+
const grouped = groupBy(users, 'role');
|
|
45
|
+
// { admin: [{ id: 1, ... }], user: [{ id: 2, ... }] }
|
|
46
|
+
|
|
47
|
+
// String utilities
|
|
48
|
+
const slug = camelCase('hello-world'); // 'helloWorld'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## ๐ Import Patterns
|
|
52
|
+
|
|
53
|
+
### Main Package
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
// Direct imports (recommended for tree-shaking)
|
|
57
|
+
import { get, set, merge, pick, omit } from '@oxog/utils';
|
|
58
|
+
|
|
59
|
+
// Namespace imports
|
|
60
|
+
import * as utils from '@oxog/utils';
|
|
61
|
+
utils.get(obj, 'path');
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Optional Plugins
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
// Deep operations (clone, merge, diff, equality)
|
|
68
|
+
import { cloneDeep, isEqual, mergeDeep } from '@oxog/utils/deep';
|
|
69
|
+
|
|
70
|
+
// Async utilities (debounce, throttle, retry, timeout)
|
|
71
|
+
import { debounce, throttle, retry, sleep } from '@oxog/utils/async';
|
|
72
|
+
|
|
73
|
+
// Type guards (isEmpty, isNil, isPlainObject, etc.)
|
|
74
|
+
import { isEmpty, isNil, isPlainObject } from '@oxog/utils/guard';
|
|
75
|
+
|
|
76
|
+
// Function utilities (compose, pipe, mapKeys, etc.)
|
|
77
|
+
import { compose, pipe, flip } from '@oxog/utils/transform';
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## ๐ API Reference
|
|
81
|
+
|
|
82
|
+
### Object Utilities
|
|
83
|
+
|
|
84
|
+
| Function | Description |
|
|
85
|
+
|----------|-------------|
|
|
86
|
+
| `get(obj, path, defaultValue?)` | Safe nested property access with type inference |
|
|
87
|
+
| `set(obj, path, value)` | Immutable property setter |
|
|
88
|
+
| `setMut(obj, path, value)` | Mutable property setter |
|
|
89
|
+
| `has(obj, path)` | Check if path exists in object |
|
|
90
|
+
| `pick(obj, keys)` | Create object with specified keys |
|
|
91
|
+
| `omit(obj, keys)` | Create object excluding specified keys |
|
|
92
|
+
| `merge(target, ...sources)` | Safe shallow merge with prototype pollution protection |
|
|
93
|
+
| `keys(obj)` | Type-safe Object.keys() |
|
|
94
|
+
| `values(obj)` | Type-safe Object.values() |
|
|
95
|
+
| `entries(obj)` | Type-safe Object.entries() |
|
|
96
|
+
| `fromEntries(entries)` | Type-safe Object.fromEntries() |
|
|
97
|
+
|
|
98
|
+
### Array Utilities
|
|
99
|
+
|
|
100
|
+
| Function | Description |
|
|
101
|
+
|----------|-------------|
|
|
102
|
+
| `groupBy(arr, key)` | Group array items by property or function |
|
|
103
|
+
| `keyBy(arr, key)` | Index array by property value |
|
|
104
|
+
| `chunk(arr, size)` | Split array into chunks |
|
|
105
|
+
| `uniq(arr)` | Remove duplicate values |
|
|
106
|
+
| `uniqBy(arr, key)` | Remove duplicates by key |
|
|
107
|
+
| `flatten(arr, depth?)` | Flatten nested arrays |
|
|
108
|
+
| `compact(arr)` | Remove falsy values |
|
|
109
|
+
| `first(arr, n?)` | Get first n elements |
|
|
110
|
+
| `last(arr, n?)` | Get last n elements |
|
|
111
|
+
| `sample(arr, n?)` | Get random sample(s) |
|
|
112
|
+
|
|
113
|
+
### String Utilities
|
|
114
|
+
|
|
115
|
+
| Function | Description |
|
|
116
|
+
|----------|-------------|
|
|
117
|
+
| `camelCase(str)` | Convert to camelCase |
|
|
118
|
+
| `kebabCase(str)` | Convert to kebab-case |
|
|
119
|
+
| `snakeCase(str)` | Convert to snake_case |
|
|
120
|
+
| `pascalCase(str)` | Convert to PascalCase |
|
|
121
|
+
| `capitalize(str)` | Capitalize first letter |
|
|
122
|
+
| `truncate(str, length, suffix?)` | Truncate string to length |
|
|
123
|
+
| `slugify(str)` | URL-safe slug with Turkish/Unicode support |
|
|
124
|
+
| `template(str, data)` | String interpolation with `{{variable}}` |
|
|
125
|
+
|
|
126
|
+
### Deep Utilities (`@oxog/utils/deep`)
|
|
127
|
+
|
|
128
|
+
| Function | Description |
|
|
129
|
+
|----------|-------------|
|
|
130
|
+
| `cloneDeep(obj)` | Deep clone with circular reference support |
|
|
131
|
+
| `mergeDeep(target, ...sources)` | Deep merge with prototype pollution protection |
|
|
132
|
+
| `isEqual(a, b)` | Deep equality comparison |
|
|
133
|
+
| `diff(a, b)` | Get differences between two objects |
|
|
134
|
+
|
|
135
|
+
### Async Utilities (`@oxog/utils/async`)
|
|
136
|
+
|
|
137
|
+
| Function | Description |
|
|
138
|
+
|----------|-------------|
|
|
139
|
+
| `debounce(fn, wait, options?)` | Debounce function execution |
|
|
140
|
+
| `throttle(fn, wait, options?)` | Throttle function execution |
|
|
141
|
+
| `sleep(ms)` | Sleep for specified milliseconds |
|
|
142
|
+
| `retry(options)` | Retry function with backoff |
|
|
143
|
+
| `timeout(promise, ms)` | Add timeout to promise |
|
|
144
|
+
|
|
145
|
+
### Type Guards (`@oxog/utils/guard`)
|
|
146
|
+
|
|
147
|
+
| Function | Description |
|
|
148
|
+
|----------|-------------|
|
|
149
|
+
| `isEmpty(value)` | Check if collection is empty |
|
|
150
|
+
| `isNil(value)` | Check if null or undefined |
|
|
151
|
+
| `isPlainObject(value)` | Check if plain object |
|
|
152
|
+
| `isArray(value)` | Type guard for arrays |
|
|
153
|
+
| `isString(value)` | Type guard for strings |
|
|
154
|
+
| `isNumber(value)` | Type guard for numbers (excludes NaN) |
|
|
155
|
+
| `isFunction(value)` | Type guard for functions |
|
|
156
|
+
| `isDate(value)` | Type guard for valid dates |
|
|
157
|
+
|
|
158
|
+
### Transform Utilities (`@oxog/utils/transform`)
|
|
159
|
+
|
|
160
|
+
| Function | Description |
|
|
161
|
+
|----------|-------------|
|
|
162
|
+
| `mapKeys(obj, fn)` | Transform object keys |
|
|
163
|
+
| `mapValues(obj, fn)` | Transform object values |
|
|
164
|
+
| `invert(obj)` | Swap keys and values |
|
|
165
|
+
| `flip(fn)` | Flip function argument order |
|
|
166
|
+
| `compose(...fns)` | Compose functions right-to-left |
|
|
167
|
+
| `pipe(...fns)` | Compose functions left-to-right |
|
|
168
|
+
|
|
169
|
+
## ๐ก Usage Examples
|
|
170
|
+
|
|
171
|
+
### Type-Safe Property Access
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { get, set } from '@oxog/utils';
|
|
175
|
+
|
|
176
|
+
interface User {
|
|
177
|
+
profile?: {
|
|
178
|
+
name: string;
|
|
179
|
+
settings?: {
|
|
180
|
+
theme: 'light' | 'dark';
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const user: User = { profile: { name: 'Ersin' } };
|
|
186
|
+
|
|
187
|
+
// TypeScript infers return type automatically
|
|
188
|
+
const theme: 'light' | 'dark' | undefined = get(user, 'profile.settings.theme');
|
|
189
|
+
const updated = set(user, 'profile.settings.theme', 'dark' as const);
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Safe Deep Merging
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
import { mergeDeep } from '@oxog/utils/deep';
|
|
196
|
+
|
|
197
|
+
const config = mergeDeep(
|
|
198
|
+
{ database: { host: 'localhost', port: 5432 } },
|
|
199
|
+
{ database: { credentials: { user: 'admin' } } }
|
|
200
|
+
);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Retry with Exponential Backoff
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { retry } from '@oxog/utils/async';
|
|
207
|
+
|
|
208
|
+
const data = await retry({
|
|
209
|
+
fn: () => fetch('https://api.example.com'),
|
|
210
|
+
attempts: 3,
|
|
211
|
+
delay: 1000,
|
|
212
|
+
backoff: 'exponential'
|
|
213
|
+
});
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Function Composition
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import { pipe } from '@oxog/utils/transform';
|
|
220
|
+
|
|
221
|
+
const processUser = pipe(
|
|
222
|
+
(data: any) => validateUser(data),
|
|
223
|
+
(user: User) => transformUser(user),
|
|
224
|
+
(user: ProcessedUser) => saveUser(user)
|
|
225
|
+
);
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## ๐งช Testing
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
# Run all tests
|
|
232
|
+
npm test
|
|
233
|
+
|
|
234
|
+
# Run tests in watch mode
|
|
235
|
+
npm run test:watch
|
|
236
|
+
|
|
237
|
+
# Run coverage report
|
|
238
|
+
npm run test:coverage
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
- **216 tests** with 100% success rate
|
|
242
|
+
- **99.41% statement coverage**
|
|
243
|
+
- **100% function coverage**
|
|
244
|
+
- **95.36% branch coverage**
|
|
245
|
+
|
|
246
|
+
## ๐ง Scripts
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
npm run build # Build the project
|
|
250
|
+
npm test # Run tests
|
|
251
|
+
npm run test:watch # Watch mode
|
|
252
|
+
npm run test:coverage # Coverage report
|
|
253
|
+
npm run lint # Lint source code
|
|
254
|
+
npm run format # Format code with Prettier
|
|
255
|
+
npm run typecheck # TypeScript type checking
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## ๐๏ธ Build Output
|
|
259
|
+
|
|
260
|
+
```text
|
|
261
|
+
dist/
|
|
262
|
+
โโโ index.js # ESM entry
|
|
263
|
+
โโโ index.cjs # CommonJS entry
|
|
264
|
+
โโโ index.d.ts # TypeScript definitions
|
|
265
|
+
โโโ index.d.cts # CommonJS definitions
|
|
266
|
+
โโโ plugins/
|
|
267
|
+
โ โโโ deep.js # Deep operations
|
|
268
|
+
โ โโโ async.js # Async utilities
|
|
269
|
+
โ โโโ guard.js # Type guards
|
|
270
|
+
โ โโโ transform.js # Transform utilities
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## ๐ก๏ธ Security
|
|
274
|
+
|
|
275
|
+
This library includes built-in protection against prototype pollution attacks:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import { merge } from '@oxog/utils';
|
|
279
|
+
|
|
280
|
+
// Dangerous keys are filtered automatically
|
|
281
|
+
const result = merge({}, { __proto__: { evil: true } });
|
|
282
|
+
console.log(result.evil); // undefined
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## ๐ License
|
|
286
|
+
|
|
287
|
+
MIT ยฉ [Ersin Koรง](https://github.com/ersinkoc/utils)
|
|
288
|
+
|
|
289
|
+
## ๐ Links
|
|
290
|
+
|
|
291
|
+
- **Documentation**: [https://utils.oxog.dev](https://utils.oxog.dev)
|
|
292
|
+
- **GitHub**: [https://github.com/ersinkoc/utils](https://github.com/ersinkoc/utils)
|
|
293
|
+
- **Issues**: [https://github.com/ersinkoc/utils/issues](https://github.com/ersinkoc/utils/issues)
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
Made with โค๏ธ by [Ersin Koรง](https://github.com/ersinkoc)
|