Skip to content

Latest commit

Β 

History

History
75 lines (57 loc) Β· 1.4 KB

File metadata and controls

75 lines (57 loc) Β· 1.4 KB

Typha 🌾

Typha is a lightweight TypeScript/JavaScript library for parsing JSON strings into typed objects using schemas.
It ensures that your data respects the type definitions you specify, handling numbers, booleans, strings, dates, arrays, and nested objects automatically.


Features

  • βœ… Parse JSON strings safely into typed objects
  • βœ… Supports primitives: string, number, boolean, Date
  • βœ… Handles arrays and nested objects
  • βœ… TypeScript ready with full type definitions
  • βœ… Lightweight and zero dependencies

Installation

npm install typha

Usage

import { parseWithSchema } from "typha";

// Define your schema
const schema = {
  name: String,
  age: Number,
  active: Boolean,
  createdAt: Date,
  tags: [String],
  profile: {
    bio: String,
    score: Number
  }
};

// Example JSON string
const raw = JSON.stringify({
  name: "raulmaciasdev",
  age: "40",
  active: "true",
  createdAt: "2025-08-21T10:30:00.000Z",
  tags: ["js", "ts"],
  profile: { bio: "Dev", score: "99" }
});

// Parse using Typha
const obj = parseWithSchema(raw, schema);

console.log(obj);
/*
{
  name: "raulmaciasdev",
  age: 40,
  active: true,
  createdAt: 2025-08-21T10:30:00.000Z,
  tags: ["js","ts"],
  profile: { bio: "Dev", score: 99 }
}
*/

Contributing

Typha is open source! Feel free to fork, open issues, or submit pull requests.

License

MIT