TyDy Save Abandoned

πŸš€ Runtime type dynamics, validation, reflection, code generation, and robust third-party library wrapping for enhanced type safety.

Project README

🌌 TyDy

NPM Package Publish CodeQL πŸ›  A TypeScript library for runtime type safety and dynamic type management.

πŸŽ‰ Introduction

TyDy (pronounced /ˈtaΙͺ daΙͺ/) is a TypeScript library that provides robust runtime type safety. It is an essential tool for working with dynamic data structures and APIs where data types can be unpredictable.

🌈 Features

  • πŸ’Ό Dynamic Type Management: Effortlessly define and manage dynamic types during runtime.
  • βœ… Runtime Type Validation: Automatically validates data against your dynamic type definitions.
  • πŸ” Type Observability: Programmatically respond to type changes.
  • πŸ“Š JSON Type Inference: Automatically infer types from complex JSON data structures.

🌟 Visualizing TyDy

flowchart TD
  subgraph "🌌 TyDy Library"
    subgraph "πŸ’Ό Dynamic Type Management"
      TypeRegistry[TypeRegistry]
    end
    subgraph "βœ… Runtime Type Validation"
      TypeValidator[TypeValidator]
    end
    subgraph "πŸ” Type Observability"
      TypeObserver[TypeObserver]
    end
    subgraph "πŸ“Š JSON Type Inference"
      JsonTypeInferencer[JsonTypeInferencer]
    end
  end
  TypeRegistry -->|Used by| TypeValidator
  TypeRegistry -->|Used by| TypeObserver
  TypeRegistry -->|Used by| JsonTypeInferencer
  TypeValidator -->|Validates| TypeRegistry
  TypeObserver -->|Observes| TypeRegistry
  JsonTypeInferencer -->|Infers| TypeRegistry

πŸ“¦ Installation

npm install tydy --save

πŸš€ Usage

πŸ” Type Observability with Observer Hooks

import { TypeObserver } from "tydy";

// Initialize a new observer instance
const observer = new TypeObserver();

// Register event handlers
observer.on("typeAdded", (typeName: string) => {
  console.log(`Type added: ${typeName}`);
});

observer.on("typeRemoved", (typeName: string) => {
  console.log(`Type removed: ${typeName}`);
});

// Operations to add and remove types, which trigger the event handlers
observer.addType("MyDynamicType");
observer.removeType("MyDynamicType");

πŸ“Š JSON Type Inference

import { JsonTypeInferencer, InferableType } from 'tydy';

// Initialize the inferencer
const inferencer = new JsonTypeInferencer();
const result = inferencer.inferNestedTypes({ name: 'Alice', age: 30, address: { street: '123 Elm St' } });

// Check if the result is an object and log its properties
if (result.type === InferableType.Object || result.type === InferableType.NestedObject) {
  console.log(result.properties);
}

πŸ’Ό Dynamic Type Management

import { TypeRegistry } from "tydy";
const typeSchema = { name: "string", age: "number" };

const MyDynamicType = TypeRegistry.registerType(typeSchema);

βœ… Runtime Type Validation

import { TypeValidator } from "tydy";

// Define a complex dynamic type
const MyDynamicType = {
  name: "string",
  age: "number",
  address: {
    street: "string",
    zipCode: "number"
  }
};

// Create an object to validate
const myObject = {
  name: "Alice",
  age: 30,
  address: {
    street: "123 Elm St",
    zipCode: 12345
  }
};

// Validate the object against the dynamic type
const isValid = TypeValidator.validate(myObject, MyDynamicType);
console.log(isValid);

πŸ™Œ Contributing

Contributions are welcomed! For more information on how to contribute, please see our contribution guidelines.

πŸ“ License

This project is licensed under the MIT License. For complete details, see the LICENSE file.

Open Source Agenda is not affiliated with "TyDy" Project. README Source: Mervsy/TyDy

Open Source Agenda Badge

Open Source Agenda Rating