npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@huncyrus/simple-validated-dto

v1.0.2

Published

Simple Validated DTO class for JavaScript projects, using Zod for schema validation and deep-freezing data to ensure immutability.

Downloads

19

Readme

Simple Validated DTO

A self-closing (immutable via freeze), self-building (pass the input, no need to design the class), self-validating (via zod) Data Transfer Object implementation for JavaScript projects.

GitHub Release CI

Reasons

  • There are (older) projects where TypeScript can not be used, where validation schemas already exists, the project evolving rapidly (large team) or there are shared schemas across services/modules/functions already.
  • The nature of JavaScript itself (the lack of private and protected functions)
  • Validation requirements (data immutability, guarantee of data structure, etc...)

Features

  • Minimal dependency (zod, vitest)
  • Easy to use
  • JavaScript support without overhead
  • Support both require and import (ESM/CommonJs)

Requirements

  • Node.js v20+
  • Basic Zod schema knowledge

Usage

Import the dependencies:

  npm install @huncyrus/simple-validated-dto

See the example file.

Import the SimpleValidatedDto:

  import { z } from 'zod';
  import { SimpleValidatedDto } from '../src/SimpleValidatedDto.js';
  // Alias can be used also
  // import { SimpleValidatedDto as dto } from '../src/SimpleValidatedDto.js';

Create a schema, based on an input or data structure, example:

  const myDataInput = {
    id: 42,
    title: 'Ministry of Silly Walks',
    other: '',
  };
  // schema example
  const exampleSchema = z.object({
      id: z.number(),
      title: z.string().min(1),
      other: z.union([z.string(), z.number()]),
  });

Then pass the data and schema:

  const dto = new SimpleValidatedDto(exampleInput, exampleSchema);

Retrieve data from DTO

 console.log('Data from DTO: ', dto.data);

Note: alternatively, use the input fields as dto.<field-name> to retrieve its value

Mutate via build

The DTO provides a method to mutate the data, which shall create a new object instead of mutation:

  const newDto = SimplevalidatedDto.build(newInput, schema);

Tests

The DTO uses vitest for unit tests:

  npm run test

Test Coverage

Test coverate via Vitest:

  npm run test:coverage

Tests via docker

Build the container:

  docker build -t simple-validated-dto-tests .
  # or rebuild
  # docker build --no-cache -t simple-validated-dto-tests .

Then run the container:

  docker run --rm simple-validated-dto-tests

Author

Author: Györk Bakonyi

Contribution

Contributing rules

References