@pithos/core 2.0.0 โ 2.0.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/README.md +384 -0
- package/dist/autocompletion.d.ts +1 -1
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/@pithos/core)
|
|
2
|
+
[](https://www.typescriptlang.org/)
|
|
3
|
+
[]()
|
|
4
|
+
|
|
5
|
+
# ๐บ Pithos โ Utilities Ecosystem
|
|
6
|
+
|
|
7
|
+
**Open the box to unleash the power**
|
|
8
|
+
|
|
9
|
+
All-in-one utilities ecosystem that provides solutions for most modern web development challenges.
|
|
10
|
+
**A synergistic utilities ecosystem where modules are designed to work together โ more than the sum of their parts.**
|
|
11
|
+
|
|
12
|
+
## โจ Key Features
|
|
13
|
+
|
|
14
|
+
- **๐ก๏ธ Zero Dependencies** - Complete supply chain security with no external vulnerabilities
|
|
15
|
+
- **๐ Interchangeable APIs** - 100% API compatible with Neverthrow and fp-ts
|
|
16
|
+
- **โก๏ธ Ultra-Performance** - High-speed execution with perfect tree-shaking and minimal bundle impact
|
|
17
|
+
- **๐ ๏ธ Production-Ready** - Battle-tested utilities with comprehensive error handling
|
|
18
|
+
- **๐๏ธ Type it once, infer it everywhere** - Full TypeScript inference, no manual generics, no `any` leaks
|
|
19
|
+
|
|
20
|
+
Tired of rewriting the same utilities across projects? Whether you're building web apps, libraries, or complex interfaces, Pithos provides the building blocks you need...
|
|
21
|
+
|
|
22
|
+
Something missing? Let's build it togetherโreach out or open a PR!
|
|
23
|
+
|
|
24
|
+
## ๐ค Why this project?
|
|
25
|
+
|
|
26
|
+
**Born from personal frustration:**
|
|
27
|
+
|
|
28
|
+
- ๐ "Where did I put that utility again?"
|
|
29
|
+
- ๐ Rewriting the same logic because it's faster than searching
|
|
30
|
+
- ๐งฉ Best code scattered across projects, never improving
|
|
31
|
+
- ๐ Great utilities stuck in old codebases
|
|
32
|
+
- ๐ช **Missing the compound effect:** Code that becomes more reliable through repeated use
|
|
33
|
+
|
|
34
|
+
**The solution:** Centralize, evolve, and battle-test in one place.
|
|
35
|
+
|
|
36
|
+
**Plus:** A single package that handles all major web development needs (validation, error handling, data parsing, etc.) in one cohesive bundle with zero dependencies, avoiding supply chain security issues.
|
|
37
|
+
|
|
38
|
+
If you've felt the same frustration, Pithos might be exactly what you need.
|
|
39
|
+
|
|
40
|
+
## ๐ The Pithos Story
|
|
41
|
+
|
|
42
|
+
Like Pandora's pithos that contained both problems and solutions, this utilities ecosystem tackles common development pain points while providing the tools you need.
|
|
43
|
+
By the way, Pandora's "box" was actually a large jar : "Pithos" in Greek ๐.
|
|
44
|
+
Each module draws from Greek mythology:
|
|
45
|
+
|
|
46
|
+
- Arkhe (แผฯฯฮฎ - "origin") โ Core utilities, the foundation
|
|
47
|
+
- Kanon (ฮบฮฑฮฝฯฮฝ - "rule/measure") โ Validation schemas
|
|
48
|
+
- Zygos (ฮถฯ
ฮณฯฯ - "balance/yoke") โ Functional programming patterns with Result and Either types
|
|
49
|
+
- Sphalma (ฯฯฮฌฮปฮผฮฑ - "error/fault") โ Error handling and error factories
|
|
50
|
+
- Taphos (ฯฮฌฯฮฟฯ - "tomb") โ Legacy utilities & deprecated functions
|
|
51
|
+
|
|
52
|
+
## ๐ Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pnpm install @pithos/core
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## ๐ฆ Usage
|
|
59
|
+
|
|
60
|
+
**Import, use, done!** No more time wasted on rewriting utilities or figuring out how to implement them:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { Arrayable, Nullable } from "pithos/arkhe/types/common";
|
|
64
|
+
import { validation } from "pithos/kanon/validation";
|
|
65
|
+
import { ok, err } from "pithos/zygos/result/result";
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**That's it!** Start building immediately instead of reinventing the wheel.
|
|
69
|
+
|
|
70
|
+
## ๐ก Some usecases
|
|
71
|
+
|
|
72
|
+
### ๐ท๏ธ **Utility Types** - Even the basics matter
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { Nullable, Arrayable } from "pithos/arkhe/types/common";
|
|
76
|
+
import { PartialKeys } from "pithos/arkhe/types/utilities";
|
|
77
|
+
|
|
78
|
+
type User = {
|
|
79
|
+
name: string;
|
|
80
|
+
emails: Arrayable<string>; // string | string[] - single or multiple emails
|
|
81
|
+
nickname: Nullable<string>; // null | string - clear intent: can be null
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Simplified user for forms (only name required)
|
|
85
|
+
type UserForm = PartialKeys<User, "emails" | "nickname">;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### ๐ก๏ธ **Result Pattern** - Error handling made simple
|
|
89
|
+
|
|
90
|
+
**Lightweight alternative to Neverthrow 8.2.0 (3x smaller, 100% compatible)**
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Standard try/catch - can crash your app
|
|
94
|
+
try {
|
|
95
|
+
const user = await fetch(`/api/users/123`);
|
|
96
|
+
if (!user.ok) throw new Error(`HTTP ${user.status}`);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
console.error("Failed:", error.message); // App might crash!
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Result to the rescue - always safe
|
|
102
|
+
const safeFetch = ResultAsync.fromThrowable(
|
|
103
|
+
fetch,
|
|
104
|
+
(error) => `Network error: ${error}`
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const result = await safeFetch("/api/users/123");
|
|
108
|
+
if (result.isOk()) {
|
|
109
|
+
console.log("User:", result.value); // Safe access
|
|
110
|
+
} else {
|
|
111
|
+
console.error("Error:", result.error); // Safe error handling
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### ๐ ๏ธ **Useful Utilities** - Data manipulation made easy
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { chunk } from "pithos/arkhe/array/chunk";
|
|
119
|
+
|
|
120
|
+
// Divide array into groups of 3
|
|
121
|
+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
|
|
122
|
+
const groups = chunk(numbers, 3);
|
|
123
|
+
console.log(groups); // [[1, 2, 3], [4, 5, 6], [7, 8]]
|
|
124
|
+
|
|
125
|
+
// Process data in batches
|
|
126
|
+
const users = ["user1", "user2", "user3", "user4", "user5"];
|
|
127
|
+
const batches = chunk(users, 2);
|
|
128
|
+
batches.forEach((batch) => processBatch(batch));
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### ๐ **Complete Workflow** - Validation + Parsing + Safe Fetch
|
|
132
|
+
|
|
133
|
+
Real-world example combining Kanon validation, safe parsing, and error handling with ResultAsync:
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { parseFloatDef } from "pithos/arkhe/number/parsers/parseFloatDef";
|
|
137
|
+
import {
|
|
138
|
+
ResultAsync,
|
|
139
|
+
errAsync,
|
|
140
|
+
okAsync,
|
|
141
|
+
} from "pithos/zygos/result/result-async";
|
|
142
|
+
import { validation } from "pithos/kanon/validation";
|
|
143
|
+
|
|
144
|
+
// Validation schema โ familiar Zod-like API
|
|
145
|
+
const ProductSchema = validation.object({
|
|
146
|
+
id: validation.string(),
|
|
147
|
+
name: validation.string(),
|
|
148
|
+
price: validation.string(),
|
|
149
|
+
stock: validation.string(),
|
|
150
|
+
category: validation.string().optional(),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
async function loadProduct(productId: string) {
|
|
154
|
+
const safeFetch = ResultAsync.fromThrowable(
|
|
155
|
+
fetch,
|
|
156
|
+
(error) => `Network error: ${error}`
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return safeFetch(`/api/products/${productId}`)
|
|
160
|
+
.andThen((response) => {
|
|
161
|
+
const safeJson = ResultAsync.fromThrowable(
|
|
162
|
+
() => response.json(),
|
|
163
|
+
(error) => `JSON parse error: ${error}`
|
|
164
|
+
);
|
|
165
|
+
return safeJson();
|
|
166
|
+
})
|
|
167
|
+
.andThen((data) => {
|
|
168
|
+
// Kanon validation
|
|
169
|
+
const validationResult = ProductSchema.safeParse(data);
|
|
170
|
+
|
|
171
|
+
if (!validationResult.success) {
|
|
172
|
+
return errAsync(`Validation failed: ${validationResult.error.message}`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return okAsync({
|
|
176
|
+
...validationResult.data,
|
|
177
|
+
price: parseFloatDef(validationResult.data.price, 0), // String โ Number
|
|
178
|
+
stock: parseFloatDef(validationResult.data.stock, 0), // String โ Number
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Usage
|
|
184
|
+
const result = await loadProduct("123");
|
|
185
|
+
if (result.isOk()) {
|
|
186
|
+
console.log("Product loaded:", result.value);
|
|
187
|
+
} else {
|
|
188
|
+
console.error("Error:", result.error);
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### ๐ **Smooth Migration** - Deprecated functions with clear guidance
|
|
193
|
+
|
|
194
|
+
Pithos provides deprecated functions with clear migration paths to native APIs:
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { fromPairs } from "pithos/taphos/array/fromPairs";
|
|
198
|
+
|
|
199
|
+
const pairs = [
|
|
200
|
+
["a", 1],
|
|
201
|
+
["b", 2],
|
|
202
|
+
["c", 3],
|
|
203
|
+
];
|
|
204
|
+
|
|
205
|
+
// โ Deprecated approach - still works but marked for removal
|
|
206
|
+
const obj = fromPairs(pairs);
|
|
207
|
+
console.log(obj); // { a: 1, b: 2, c: 3 }
|
|
208
|
+
|
|
209
|
+
// โ
Recommended approach - use native Object.fromEntries()
|
|
210
|
+
const objNative = Object.fromEntries(pairs);
|
|
211
|
+
console.log(objNative); // { a: 1, b: 2, c: 3 }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
**Benefits of this approach:**
|
|
215
|
+
|
|
216
|
+
- **Zero breaking changes** - deprecated functions still work
|
|
217
|
+
- **Clear migration path** - examples show exactly what to use instead
|
|
218
|
+
- **Future-proof** - migrate at your own pace without pressure
|
|
219
|
+
- **Bundle optimization** - native APIs are often more performant
|
|
220
|
+
|
|
221
|
+
## ๐ ๏ธ Available modules
|
|
222
|
+
|
|
223
|
+
### **๐บ Arkhe** - Core utilities & data manipulation
|
|
224
|
+
|
|
225
|
+
_The modern "lodash/underscore" - Data manipulation utilities with modern approaches documented but ES2020 compatibility prioritized_
|
|
226
|
+
|
|
227
|
+
- **data** : Array, collection, function, language, number, object, string utilities
|
|
228
|
+
- **types** : TypeScript types and guards
|
|
229
|
+
|
|
230
|
+
### **๐ฏ Kanon** - Schema validation
|
|
231
|
+
|
|
232
|
+
_Lightweight and interchangeable alternative to Zod with simplified API and optimized performance_
|
|
233
|
+
|
|
234
|
+
- **core** : Core validation primitives and composites
|
|
235
|
+
- **schemas** : Pre-built validation schemas
|
|
236
|
+
- **validation** : Validation engine and error handling
|
|
237
|
+
|
|
238
|
+
### **โก๏ธ Zygos** - Functional programming
|
|
239
|
+
|
|
240
|
+
_Lightweight and interchangeable alternative to Neverthrow/fp-ts with functional monads for robust error handling_
|
|
241
|
+
|
|
242
|
+
- **result** : Result pattern implementation (lightweight Neverthrow alternative)
|
|
243
|
+
- **option** : Option/Maybe monad
|
|
244
|
+
- **either** : Either monad
|
|
245
|
+
- **task-either** : Async Either monad
|
|
246
|
+
|
|
247
|
+
### **๐ง Sphalma** - Error handling & error factories
|
|
248
|
+
|
|
249
|
+
_Error handling utilities and error factory patterns for consistent error management_
|
|
250
|
+
|
|
251
|
+
- **error-factory** : Error factory for creating typed, coded errors with consistent structure
|
|
252
|
+
|
|
253
|
+
### **โฐ๏ธ Taphos** - Legacy utilities & deprecated functions
|
|
254
|
+
|
|
255
|
+
_The resting place of utilities - Deprecated functions with clear migration paths to native APIs_
|
|
256
|
+
|
|
257
|
+
- **array** : Deprecated array utilities (fromPairs, flattenDepth, nth, tail, head)
|
|
258
|
+
- **object** : Deprecated object utilities (keys, values, extend, toPairs)
|
|
259
|
+
- **string** : Deprecated string utilities (startsWith, endsWith, padStart, padEnd, repeat, toLower, toUpper, trim)
|
|
260
|
+
- **function** : Deprecated function utilities (partial)
|
|
261
|
+
|
|
262
|
+
## ๐ Documentation
|
|
263
|
+
|
|
264
|
+
Full documentation available at [pithos.dev](https://pithos.dev)
|
|
265
|
+
|
|
266
|
+
For now, explore the source code and TSDoc comments โ every function is fully documented.
|
|
267
|
+
|
|
268
|
+
## ๐ง Most useful scripts
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Development
|
|
272
|
+
pnpm run build # Build once
|
|
273
|
+
pnpm run dev # Build in watch mode
|
|
274
|
+
pnpm run test # Run all tests
|
|
275
|
+
pnpm run coverage # Run tests with coverage report
|
|
276
|
+
pnpm run lint # Lint code
|
|
277
|
+
pnpm run lint:fix # Lint and auto-fix issues
|
|
278
|
+
pnpm run check:types # Type-check without emitting files
|
|
279
|
+
pnpm run check:all # Run all checks (lint + types + tsdoc)
|
|
280
|
+
|
|
281
|
+
# Documentation
|
|
282
|
+
pnpm run doc:generate # Generate docs (runs snapshot tests at the end)
|
|
283
|
+
pnpm run doc:snapshots # Run doc snapshot tests only
|
|
284
|
+
pnpm run doc:snapshots:update # Update snapshots after intentional changes
|
|
285
|
+
|
|
286
|
+
# Analysis
|
|
287
|
+
pnpm run analyze:bundle # Analyze bundle size
|
|
288
|
+
pnpm run benchmark:kanon # Run benchmarks (supports filtering: pnpm run benchmark:kanon kanon,zod)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## โ ๏ธ Project Status
|
|
292
|
+
|
|
293
|
+
**Pithos is production-ready** for most modules, with **100% test coverage**.
|
|
294
|
+
|
|
295
|
+
| Module | Status | Notes |
|
|
296
|
+
| -------- | --------------- | ---------------------------------------------- |
|
|
297
|
+
| Arkhe | โ
Stable | Core utilities, fully tested |
|
|
298
|
+
| Kanon | โ
Stable | Schema validation |
|
|
299
|
+
| Zygos | โ
Stable | Result/Either/Option patterns |
|
|
300
|
+
| Sphalma | โ
Stable | Error handling |
|
|
301
|
+
| Taphos | โ
Stable | Deprecated utilities with migration paths |
|
|
302
|
+
|
|
303
|
+
**Philosophy**: Quality over quantity. Each utility is carefully crafted and optimized before being added.
|
|
304
|
+
|
|
305
|
+
## ๐ณ Tree Shaking
|
|
306
|
+
|
|
307
|
+
Pithos is optimized for tree shaking. Use direct imports for optimal bundle size:
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// โ
Good - only specific utilities included
|
|
311
|
+
import { chunk } from "pithos/arkhe/array/chunk";
|
|
312
|
+
import { debounce } from "pithos/arkhe/function/debounce";
|
|
313
|
+
|
|
314
|
+
// โ Less optimal - entire module included
|
|
315
|
+
import * as Arkhe from "pithos/arkhe";
|
|
316
|
+
import { chunk } from "pithos";
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## ๐ Complementary Libraries
|
|
320
|
+
|
|
321
|
+
Pithos is designed to provide the most useful and reusable utilities possible, but it is **not intended to replace popular and specialized libraries** that already excel at their specific domains.
|
|
322
|
+
|
|
323
|
+
**In some cases**, certain implementations have been developed for simplicity and to achieve lighter bundles, but for more robust requirements, specialized libraries remain the recommended approach.
|
|
324
|
+
|
|
325
|
+
**Practical example**: Pithos offers lightweight validation with Kanon, but for complex form handling with UI frameworks, you might complement it with specialized form libraries like React Hook Form or Formik.
|
|
326
|
+
|
|
327
|
+
### ๐ Recommended Libraries
|
|
328
|
+
|
|
329
|
+
#### **๐งฎ Functional Programming**
|
|
330
|
+
|
|
331
|
+
- **Pithos Zygos** for Either and Task monads (interchangeable with fp-ts)
|
|
332
|
+
- **[fp-ts](https://github.com/gcanti/fp-ts)** for advanced features (functors, composition tools, and more)
|
|
333
|
+
|
|
334
|
+
#### **โ
Result Pattern**
|
|
335
|
+
|
|
336
|
+
- **Pithos Result** for lightweight error handling (~6KB, 100% API compatible with neverthrow)
|
|
337
|
+
- **[neverthrow](https://github.com/supermacro/neverthrow)** for advanced Result features
|
|
338
|
+
|
|
339
|
+
#### **๐ Data Validation & Parsing**
|
|
340
|
+
|
|
341
|
+
- **Pithos Kanon** for schema validation (lightweight, zero dependencies)
|
|
342
|
+
- **[Zod](https://zod.dev/)** for complex data transformations
|
|
343
|
+
|
|
344
|
+
#### **๐
Date Management**
|
|
345
|
+
|
|
346
|
+
- **Temporal** - Modern and standardized JavaScript API for date and time manipulation, built into the language with excellent TypeScript support
|
|
347
|
+
|
|
348
|
+
#### **๐ฌ Advanced Animations**
|
|
349
|
+
|
|
350
|
+
- **[GSAP](https://greensock.com/gsap/)** - Professional and ultra-performant animation library for complex requirements, featuring timeline management, morphing capabilities, and comprehensive browser support
|
|
351
|
+
|
|
352
|
+
## ๐ค Contributing
|
|
353
|
+
|
|
354
|
+
We welcome contributions! Whether it's bug fixes, new features, or documentation improvements, every contribution helps make Pithos better.
|
|
355
|
+
|
|
356
|
+
### How to contribute:
|
|
357
|
+
|
|
358
|
+
1. **Fork** the repository
|
|
359
|
+
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
|
|
360
|
+
3. **Commit** your changes (`git commit -m 'Add amazing feature'`)
|
|
361
|
+
4. **Push** to the branch (`git push origin feature/amazing-feature`)
|
|
362
|
+
5. **Open** a Pull Request
|
|
363
|
+
|
|
364
|
+
### Development setup:
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
git clone https://github.com/mopi1402/pithos.git
|
|
368
|
+
cd pithos
|
|
369
|
+
pnpm install
|
|
370
|
+
pnpm run dev
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Code style:
|
|
374
|
+
|
|
375
|
+
- Follow the existing TypeScript/ESLint configuration
|
|
376
|
+
- Write clear, documented code
|
|
377
|
+
- Add tests for new features
|
|
378
|
+
- Update documentation as needed
|
|
379
|
+
|
|
380
|
+
**Questions?** Open an issue or start a discussion!
|
|
381
|
+
|
|
382
|
+
## ๐ License
|
|
383
|
+
|
|
384
|
+
[MIT](LICENSE)
|
package/dist/autocompletion.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithos/core",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Advanced JavaScript/TypeScript superset providing utilities, validation, and functional patterns",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"bugs": {
|
|
82
82
|
"url": "https://github.com/mopi1402/pithos/issues"
|
|
83
83
|
},
|
|
84
|
-
"homepage": "https://
|
|
84
|
+
"homepage": "https://pithos.dev",
|
|
85
85
|
"engines": {
|
|
86
86
|
"node": ">=20.0.0"
|
|
87
87
|
},
|