@happyvertical/utils 0.74.8
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/AGENT.md +33 -0
- package/LICENSE +7 -0
- package/README.md +143 -0
- package/dist/browser.d.ts +20 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +59 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunks/universal-BeseWxvS.js +934 -0
- package/dist/chunks/universal-BeseWxvS.js.map +1 -0
- package/dist/cli/claude-context.d.ts +3 -0
- package/dist/cli/claude-context.d.ts.map +1 -0
- package/dist/cli/claude-context.js +21 -0
- package/dist/cli/claude-context.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/parse-args.d.ts +61 -0
- package/dist/cli/parse-args.d.ts.map +1 -0
- package/dist/cli/parse-flags.d.ts +22 -0
- package/dist/cli/parse-flags.d.ts.map +1 -0
- package/dist/config/env-config.d.ts +119 -0
- package/dist/config/env-config.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +394 -0
- package/dist/index.js.map +1 -0
- package/dist/shared/code/extraction.d.ts +90 -0
- package/dist/shared/code/extraction.d.ts.map +1 -0
- package/dist/shared/code/index.d.ts +14 -0
- package/dist/shared/code/index.d.ts.map +1 -0
- package/dist/shared/code/sandbox.d.ts +165 -0
- package/dist/shared/code/sandbox.d.ts.map +1 -0
- package/dist/shared/code/validation.d.ts +113 -0
- package/dist/shared/code/validation.d.ts.map +1 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/logger.d.ts +43 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/types.d.ts +195 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/universal.d.ts +400 -0
- package/dist/shared/universal.d.ts.map +1 -0
- package/dist/web.d.ts +35 -0
- package/dist/web.d.ts.map +1 -0
- package/metadata.json +54 -0
- package/package.json +70 -0
package/AGENT.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# @happyvertical/utils
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN AGENT:GENERATED -->
|
|
4
|
+
## Purpose
|
|
5
|
+
Foundation utilities for ID generation, date parsing, URL handling, string conversion, error handling, and logging
|
|
6
|
+
|
|
7
|
+
## Package Map
|
|
8
|
+
- Package: `@happyvertical/utils`
|
|
9
|
+
- Hierarchy path: `@happyvertical/sdk > packages > utils`
|
|
10
|
+
- Workspace position: `28 of 30` local packages
|
|
11
|
+
- Internal dependencies: none
|
|
12
|
+
- Internal dependents: `@happyvertical/accounting`, `@happyvertical/ai`, `@happyvertical/analytics`, `@happyvertical/auth`, `@happyvertical/cache`, `@happyvertical/comfyui`, `@happyvertical/directory`, `@happyvertical/documents`, `@happyvertical/email`, `@happyvertical/encryption`, `@happyvertical/files`, `@happyvertical/geo`, `@happyvertical/jobs`, `@happyvertical/logger`, `@happyvertical/messages`, `@happyvertical/sdk-mcp`, `@happyvertical/secrets`, `@happyvertical/social`, `@happyvertical/sql`, `@happyvertical/translator`, `@happyvertical/video`, `@happyvertical/weather`
|
|
13
|
+
- Knowledge graph files: `AGENT.md`, `metadata.json`, `ecosystem-manifest.json`
|
|
14
|
+
|
|
15
|
+
## Build & Test
|
|
16
|
+
```bash
|
|
17
|
+
pnpm --filter @happyvertical/utils build
|
|
18
|
+
pnpm --filter @happyvertical/utils test
|
|
19
|
+
pnpm --filter @happyvertical/utils clean
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Agent Correction Loops
|
|
23
|
+
- If Vite or TypeScript reports missing packages, run `pnpm install` at the repo root and rerun `pnpm --filter @happyvertical/utils build`.
|
|
24
|
+
- If tests or exports fail after API, type, or bundle changes, run `pnpm --filter @happyvertical/utils clean` followed by `pnpm --filter @happyvertical/utils build` and `pnpm --filter @happyvertical/utils test`.
|
|
25
|
+
- If failures span multiple packages or Turborepo ordering looks wrong, run `pnpm build` and `pnpm typecheck` from the repo root before retrying package-scoped commands.
|
|
26
|
+
|
|
27
|
+
## Ecosystem Relationships
|
|
28
|
+
- Provides: Foundation utilities for ID generation, date parsing, URL handling, string conversion, error handling, and logging
|
|
29
|
+
- Implements: none
|
|
30
|
+
- Requires: @paralleldrive/cuid2, date-fns, pluralize, uuid
|
|
31
|
+
- Stability: stable (Primary package surface is described as implemented and production-oriented.)
|
|
32
|
+
<!-- END AGENT:GENERATED -->
|
|
33
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright <2025> <Happy Vertical Corporation>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @happyvertical/utils
|
|
2
|
+
|
|
3
|
+
Foundation utilities for the HAVE SDK: ID generation, date parsing, URL handling, string conversion, error classes, logging, code extraction/validation/sandboxing, CLI argument parsing, and environment config loading.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @happyvertical/utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
A browser-safe entry point is available at `@happyvertical/utils/browser` (excludes Node.js-specific code like `node:vm` sandbox and `node:crypto` hashing).
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### ID Generation
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { makeId, createId, isCuid } from '@happyvertical/utils';
|
|
19
|
+
|
|
20
|
+
const id = makeId(); // CUID2 (default)
|
|
21
|
+
const uuid = makeId('uuid'); // UUID via crypto.randomUUID()
|
|
22
|
+
const cuid = createId(); // CUID2 directly
|
|
23
|
+
isCuid(id); // true
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### String & URL Utilities
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { camelCase, snakeCase, keysToCamel, keysToSnake, makeSlug, urlFilename, isUrl } from '@happyvertical/utils';
|
|
30
|
+
|
|
31
|
+
camelCase('hello-world'); // "helloWorld"
|
|
32
|
+
snakeCase('helloWorld'); // "hello_world"
|
|
33
|
+
keysToCamel({ user_name: 'j' }); // { userName: 'j' } (recursive)
|
|
34
|
+
makeSlug('My Title & Co.'); // "my-title-38-co"
|
|
35
|
+
urlFilename('https://example.com/path/file.pdf'); // "file.pdf"
|
|
36
|
+
isUrl('https://example.com'); // true
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Date Utilities
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { dateInString, formatDate, parseDate, parseAmazonDateString, addInterval } from '@happyvertical/utils';
|
|
43
|
+
|
|
44
|
+
dateInString('Report_January_15_2023.pdf'); // Date(2023, 0, 15)
|
|
45
|
+
formatDate(new Date(), 'yyyy-MM-dd'); // "2023-01-15"
|
|
46
|
+
parseDate('2023-01-15'); // Date object (ISO)
|
|
47
|
+
parseDate('01/15/2023', 'MM/dd/yyyy'); // Date object (custom format)
|
|
48
|
+
parseAmazonDateString('20220223T215409Z'); // Date object
|
|
49
|
+
addInterval(new Date(), { days: 7 }); // Date 7 days from now
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Error Classes
|
|
53
|
+
|
|
54
|
+
All extend `BaseError` with `code`, `context`, and `timestamp` fields, plus `toJSON()`:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { ValidationError, ApiError, NetworkError, TimeoutError, ParsingError, FileError, DatabaseError } from '@happyvertical/utils';
|
|
58
|
+
|
|
59
|
+
throw new ValidationError('Invalid email', { field: 'email', value: input });
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Code Extraction & Sandbox
|
|
63
|
+
|
|
64
|
+
Extract code blocks from markdown/AI responses, validate, and execute in isolated `node:vm` contexts:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { extractCodeBlock, extractJSON, validateCode, executeInSandbox } from '@happyvertical/utils';
|
|
68
|
+
|
|
69
|
+
const code = extractCodeBlock(markdownText, 'javascript');
|
|
70
|
+
const data = extractJSON<{ name: string }>(aiResponse);
|
|
71
|
+
|
|
72
|
+
const result = validateCode(code, { maxLength: 10000 });
|
|
73
|
+
if (result.valid) {
|
|
74
|
+
const output = executeInSandbox(code, { globals: { data }, timeout: 5000 });
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### CLI Argument Parsing
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { parseCliArgs } from '@happyvertical/utils';
|
|
82
|
+
|
|
83
|
+
const parsed = parseCliArgs(process.argv, [
|
|
84
|
+
{ name: 'build', description: 'Build project', options: { output: { type: 'string', description: 'Output dir' } } }
|
|
85
|
+
]);
|
|
86
|
+
// { command: 'build', args: [], options: { output: './dist' } }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Environment Config
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { loadEnvConfig } from '@happyvertical/utils';
|
|
93
|
+
|
|
94
|
+
// Loads HAVE_AI_* env vars, merged with user options (user options take precedence)
|
|
95
|
+
const config = loadEnvConfig({ provider: 'openai' }, {
|
|
96
|
+
packageName: 'ai',
|
|
97
|
+
schema: { provider: 'string', model: 'string', timeout: 'number' }
|
|
98
|
+
});
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Logging
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
import { getLogger, setLogger, disableLogging } from '@happyvertical/utils';
|
|
105
|
+
|
|
106
|
+
const logger = getLogger();
|
|
107
|
+
logger.info('Started', { userId: 123 });
|
|
108
|
+
disableLogging(); // Switch to no-op logger
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## API Reference
|
|
112
|
+
|
|
113
|
+
**IDs** — `makeId(type?)`, `createId()`, `isCuid(id)`
|
|
114
|
+
|
|
115
|
+
**Strings** — `camelCase(str)`, `snakeCase(str)`, `keysToCamel(obj)`, `keysToSnake(obj)`, `domainToCamel(str)`, `makeSlug(str)`
|
|
116
|
+
|
|
117
|
+
**URLs** — `urlFilename(url)`, `urlPath(url)`, `isUrl(str)`, `normalizeUrl(url)`, `generateScopeFromUrl(url)`, `hashPageContent(html)`
|
|
118
|
+
|
|
119
|
+
**Dates** — `dateInString(str)`, `prettyDate(str)`, `parseAmazonDateString(str)`, `formatDate(date, format?)`, `parseDate(str, format?)`, `isValidDate(date)`, `addInterval(date, duration)`
|
|
120
|
+
|
|
121
|
+
**Pluralization** — `pluralizeWord(word)`, `singularize(word)`, `isPlural(word)`, `isSingular(word)`
|
|
122
|
+
|
|
123
|
+
**Type Guards** — `isArray(obj)`, `isPlainObject(obj)`
|
|
124
|
+
|
|
125
|
+
**Async** — `waitFor(fn, options?)`, `sleep(ms)`
|
|
126
|
+
|
|
127
|
+
**Code** — `extractCodeBlock(text, lang?)`, `extractAllCodeBlocks(text, lang?)`, `extractJSON<T>(text)`, `extractFunctionDefinition(code, name)`, `validateCode(code, options?)`, `isSafeCode(code)`, `createSandbox(options?)`, `executeCode(code, sandbox, options?)`, `executeCodeAsync(code, sandbox, options?)`, `executeInSandbox(code, options?)`, `executeInSandboxAsync(code, options?)`
|
|
128
|
+
|
|
129
|
+
**CLI** — `parseCliArgs(argv, commands, builtInCommands?)`
|
|
130
|
+
|
|
131
|
+
**Config** — `loadEnvConfig<T>(userOptions?, options?)`, `toCamelCase(str)`, `toScreamingSnakeCase(str)`, `convertType(value, type)`
|
|
132
|
+
|
|
133
|
+
**Logging** — `getLogger()`, `setLogger(logger)`, `disableLogging()`, `enableLogging()`
|
|
134
|
+
|
|
135
|
+
**Misc** — `logTicker(tick, options?)`, `getTempDirectory(subfolder?)`
|
|
136
|
+
|
|
137
|
+
**Error Classes** — `BaseError`, `ValidationError`, `ApiError`, `FileError`, `NetworkError`, `DatabaseError`, `ParsingError`, `TimeoutError`
|
|
138
|
+
|
|
139
|
+
**Types** — `Logger`, `ErrorCode`, `Command`, `OptionConfig`, `ParsedArgs`, `ConfigOptions<T>`, `ValidationOptions`, `ValidationResult`, `SandboxOptions`, `ExecuteOptions`
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
MIT
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-safe utilities
|
|
3
|
+
*
|
|
4
|
+
* This entry point only exports utilities that work in browser environments.
|
|
5
|
+
* It excludes Node.js-specific code like:
|
|
6
|
+
* - cli/parse-args (uses node:path, node:util)
|
|
7
|
+
* - shared/code/sandbox (uses node:vm)
|
|
8
|
+
* - web.ts hash functions (uses node:crypto)
|
|
9
|
+
*
|
|
10
|
+
* For Node.js environments, use the main entry point instead.
|
|
11
|
+
*/
|
|
12
|
+
export * from './config/env-config';
|
|
13
|
+
export { extractAllCodeBlocks, extractCodeBlock, extractFunctionDefinition, extractJSON, } from './shared/code/extraction';
|
|
14
|
+
export { isSafeCode, type ValidationOptions, type ValidationResult, validateCode, } from './shared/code/validation';
|
|
15
|
+
export * from './shared/logger';
|
|
16
|
+
export * from './shared/types';
|
|
17
|
+
export * from './shared/universal';
|
|
18
|
+
/** @internal */
|
|
19
|
+
export declare const PACKAGE_VERSION_INITIALIZED = true;
|
|
20
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,cAAc,qBAAqB,CAAC;AAEpC,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,yBAAyB,EACzB,WAAW,GACZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,YAAY,GACb,MAAM,0BAA0B,CAAC;AAElC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,gBAAgB,CAAC;AAE/B,cAAc,oBAAoB,CAAC;AAEnC,gBAAgB;AAChB,eAAO,MAAM,2BAA2B,OAAO,CAAC"}
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { A, B, D, E, F, N, P, T, V, a, c, b, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, C, G, H, I, J, K, L, M, O, Q, R, S, U, W, X, Y } from "./chunks/universal-BeseWxvS.js";
|
|
2
|
+
import { isCuid } from "@paralleldrive/cuid2";
|
|
3
|
+
const PACKAGE_VERSION_INITIALIZED = true;
|
|
4
|
+
export {
|
|
5
|
+
A as ApiError,
|
|
6
|
+
B as BaseError,
|
|
7
|
+
D as DatabaseError,
|
|
8
|
+
E as ErrorCode,
|
|
9
|
+
F as FileError,
|
|
10
|
+
N as NetworkError,
|
|
11
|
+
PACKAGE_VERSION_INITIALIZED,
|
|
12
|
+
P as ParsingError,
|
|
13
|
+
T as TimeoutError,
|
|
14
|
+
V as ValidationError,
|
|
15
|
+
a as addInterval,
|
|
16
|
+
c as camelCase,
|
|
17
|
+
b as convertType,
|
|
18
|
+
d as createId,
|
|
19
|
+
e as dateInString,
|
|
20
|
+
f as disableLogging,
|
|
21
|
+
g as domainToCamel,
|
|
22
|
+
h as enableLogging,
|
|
23
|
+
i as extractAllCodeBlocks,
|
|
24
|
+
j as extractCodeBlock,
|
|
25
|
+
k as extractFunctionDefinition,
|
|
26
|
+
l as extractJSON,
|
|
27
|
+
m as formatDate,
|
|
28
|
+
n as getLogger,
|
|
29
|
+
o as getTempDirectory,
|
|
30
|
+
p as isArray,
|
|
31
|
+
isCuid,
|
|
32
|
+
q as isPlainObject,
|
|
33
|
+
r as isPlural,
|
|
34
|
+
s as isSafeCode,
|
|
35
|
+
t as isSingular,
|
|
36
|
+
u as isUrl,
|
|
37
|
+
v as isValidDate,
|
|
38
|
+
w as keysToCamel,
|
|
39
|
+
x as keysToSnake,
|
|
40
|
+
y as loadEnvConfig,
|
|
41
|
+
z as logTicker,
|
|
42
|
+
C as makeId,
|
|
43
|
+
G as makeSlug,
|
|
44
|
+
H as parseAmazonDateString,
|
|
45
|
+
I as parseDate,
|
|
46
|
+
J as pluralizeWord,
|
|
47
|
+
K as prettyDate,
|
|
48
|
+
L as setLogger,
|
|
49
|
+
M as singularize,
|
|
50
|
+
O as sleep,
|
|
51
|
+
Q as snakeCase,
|
|
52
|
+
R as toCamelCase,
|
|
53
|
+
S as toScreamingSnakeCase,
|
|
54
|
+
U as urlFilename,
|
|
55
|
+
W as urlPath,
|
|
56
|
+
X as validateCode,
|
|
57
|
+
Y as waitFor
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sources":["../src/browser.ts"],"sourcesContent":["/**\n * Browser-safe utilities\n *\n * This entry point only exports utilities that work in browser environments.\n * It excludes Node.js-specific code like:\n * - cli/parse-args (uses node:path, node:util)\n * - shared/code/sandbox (uses node:vm)\n * - web.ts hash functions (uses node:crypto)\n *\n * For Node.js environments, use the main entry point instead.\n */\n\n// Export config utilities (browser-safe)\nexport * from './config/env-config';\n// Export code utilities that don't require Node.js\nexport {\n extractAllCodeBlocks,\n extractCodeBlock,\n extractFunctionDefinition,\n extractJSON,\n} from './shared/code/extraction';\nexport {\n isSafeCode,\n type ValidationOptions,\n type ValidationResult,\n validateCode,\n} from './shared/code/validation';\n// Export logger utilities (browser-safe)\nexport * from './shared/logger';\n// Export types (browser-safe)\nexport * from './shared/types';\n// Export all universal utilities (browser-safe)\nexport * from './shared/universal';\n\n/** @internal */\nexport const PACKAGE_VERSION_INITIALIZED = true;\n"],"names":[],"mappings":";;AAmCO,MAAM,8BAA8B;"}
|