TypeScript fundamentals
@cratis/fundamentals provides typed domain values, GUIDs, dates, and JSON conversion for TypeScript applications. Use it in browser or Node.js code without a Cratis backend.
Installation
Section titled “Installation”Install the npm package:
npm install @cratis/fundamentalsDisplay an empty identifier
Section titled “Display an empty identifier”Add this to your TypeScript application’s entry point:
import { Guid } from '@cratis/fundamentals';
const emptyGuid = Guid.empty;console.log(emptyGuid.toString());Run the application with its usual development command. The console prints 00000000-0000-0000-0000-000000000000, the empty GUID formatted as a string. This checks that the package import and identifier conversion work in your application.
Overview
Section titled “Overview”Choose a utility for the value or conversion your application needs:
Topics
Section titled “Topics”| Topic | Description |
|---|---|
| ConceptAs | Domain-Driven Design pattern for creating strongly-typed domain identifiers and value objects that wrap primitive types. |
| GUID | GUID creation, manipulation, and utility functions for unique identifiers. |
| Constructor | Runtime constructor type alias for class-based APIs and metadata-driven tooling. |
| PropertyAccessor | Property accessor function type for typed property selection and path utilities. |
| TimeSpan | .NET-compatible time interval parsing, formatting, and JSON serialization. |
| ValueMap | A value-based map for complex object keys with stable lookup semantics. |
| Serialization | Type-safe JSON serialization and deserialization system with polymorphic support and runtime type preservation. |
Module imports
Section titled “Module imports”Use the package root for shared types, or import from @cratis/fundamentals/geospatial,
@cratis/fundamentals/json, and @cratis/fundamentals/reflection. These entry points
work in Node.js ESM, CommonJS, and TypeScript projects using NodeNext or Bundler
module resolution.
import { Guid } from '@cratis/fundamentals';import { Point } from '@cratis/fundamentals/geospatial';
const origin = new Point(0, 0);const id = Guid.empty;Next steps
Section titled “Next steps”- Create and compare GUIDs — validate incoming identifiers and compare their values.
- Define a typed concept — give a primitive value a domain-specific type.
- Configure serialization — preserve domain types when converting JSON.