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

@duplojs/data-parser-tools

v0.3.0

Published

<a name="top"></a>

Readme

@duplojs/data-parser-tools is a library that convert dataParser schema to choice format (typescript, jsonSchema)

Installation

To consume @duplojs/data-parser-tools, you need to install the npm package and zod.

npm install @duplojs/data-parser-tools@0 @duplojs/utils@1 @duplojs/server-utils@0

Usage

The library exposes two converters:

  • @duplojs/data-parser-tools/toTypescript
  • @duplojs/data-parser-tools/toJsonSchema

1) Generate a TypeScript type with render

import { DPE } from "@duplojs/utils";
import { render, defaultTransformers } from "@duplojs/data-parser-tools/toTypescript";

const userSchema = DPE.object({
	id: DPE.number(),
	name: DPE.string(),
}).addIdentifier("User");

const tsType = render(userSchema, {
	identifier: "User",
	mode: "out",
	transformers: defaultTransformers,
});

console.log(tsType);
// export type User = { id: number; name: string; };

identifier is the final exported name.
mode can be:

  • "out": output format (strict)
  • "in": input format (includes accepted input variants, for example date/time)

2) Generate a JSON Schema

import { DPE } from "@duplojs/utils";
import { render, defaultTransformers } from "@duplojs/data-parser-tools/toJsonSchema";

const userSchema = DPE.object({
	id: DPE.number(),
	name: DPE.string(),
}).addIdentifier("User");

const jsonSchema = render(userSchema, {
	identifier: "User",
	mode: "out",
	transformers: defaultTransformers,
	version: "jsonSchema7", // jsonSchema4 | jsonSchema7 | jsonSchema202012 | openApi3 | openApi31
});

console.log(jsonSchema.$ref); // "#/definitions/User"

3) Add an identifier to a schema (addIdentifier)

addIdentifier clones the schema and attaches an internal reusable name during rendering.

const base = DPE.object({ value: DPE.string() });
const named = base.addIdentifier("MyNamedSchema");

If the name passed to render({ identifier }) differs from the schema identifier, an alias is generated (for example: export type PublicName = MyNamedSchema;).

4) Use hooks

Hooks let you intercept/replace a schema before transformation.

  • output("next", schema): continue the hook chain
  • output("stop", schema): stop the chain and transform this schema
import { DPE } from "@duplojs/utils";
import { render, defaultTransformers, type TransformerHook } from "@duplojs/data-parser-tools/toTypescript";

const forceStringHook: TransformerHook = ({ output }) => output("stop", DPE.string());

const result = render(DPE.number(), {
	identifier: "HookExample",
	mode: "out",
	transformers: defaultTransformers,
	hooks: [forceStringHook],
});

console.log(result);
// export type HookExample = string;

5) Recursive schemas

Recursive references are supported through DPE.lazy(...).

import { DPE } from "@duplojs/utils";
import { render, defaultTransformers } from "@duplojs/data-parser-tools/toTypescript";

type Node = { children: Node[] };

const nodeSchema: DPE.Contract<Node> = DPE.object({
	children: DPE.array(DPE.lazy(() => nodeSchema)),
}).addIdentifier("Node");

const result = render(nodeSchema, {
	identifier: "Node",
	mode: "out",
	transformers: defaultTransformers,
});

6) Custom types: date, time, file

import { DPE } from "@duplojs/utils";
import { SDP } from "@duplojs/server-utils";
import { render, defaultTransformers } from "@duplojs/data-parser-tools/toTypescript";

const schema = DPE.object({
	createdAt: DPE.date(),
	startAt: DPE.time(),
	avatar: SDP.file(),
});

const outType = render(schema, {
	identifier: "PayloadOut",
	mode: "out",
	transformers: defaultTransformers,
});

const inType = render(schema, {
	identifier: "PayloadIn",
	mode: "in",
	transformers: defaultTransformers,
});

In practice:

  • date / time in "out" produce template-literals (date..., time...)
  • date / time in "in" also accept additional input variants
  • file maps to FileInterface (imported from @duplojs/server-utils/file)