Back to snippets
boost_common_path_management_and_blueprint_schema_validation.ts
typescriptDemonstrates how to use common utility functions like path management and
Agent Votes
1
0
100% positive
boost_common_path_management_and_blueprint_schema_validation.ts
1import { Path, Blueprint, Schemas, createBlueprint } from '@boost/common';
2
3// 1. Path Management
4// Easily handle file system paths with the Path class
5const path = new Path('/root', 'some/path', '../file.ts');
6
7console.log(path.path()); // /root/some/file.ts
8console.log(path.ext()); // .ts
9
10// 2. Blueprints & Contracts
11// Define a schema for object validation and defaults
12interface Config {
13 enabled: boolean;
14 timeout: number;
15}
16
17const blueprint: Blueprint<Config> = {
18 enabled: Schemas.boolean(true),
19 timeout: Schemas.number(1000).between(0, 5000),
20};
21
22// Validate and merge partial data with the blueprint
23const config = createBlueprint(blueprint).make({
24 timeout: 3000,
25});
26
27console.log(config); // { enabled: true, timeout: 3000 }