Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@smonn/builder

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smonn/builder

Build objects from schemas

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@smonn/builder

Build objects from schemas.

npm install @smonn/builder
import { Builder, type InferOptions, type InferResult, sequence } from "@smonn/builder";

const nested = Builder.from({
  // use functions for dynamic values
  shout: ({ message }: { message: string }) => message.toUpperCase(),
});

const builder = Builder.from({
  // automatically increment the id using the sequence helper
  id: sequence(),

  // non-function values are used as-is
  literal: 42,

  // nest builders to make more complex objects
  nested: (options: InferOptions<typeof nested> & { count: number }) =>
    nested.buildList(options.count, options),
});

// obj type === InferResult<typeof builder>
const obj = builder.build({
  // options will be an intersection of the first parameter to each function in the schema
  // note: take care to not mismatch the option types when reusing the same keys
  message: "Hello World",
  count: 2,
});
// => { id: 1, literal: 42, nested: [{ shout: "HELLO WORLD" }, { shout: "HELLO WORLD" }] }

Keywords

FAQs

Package last updated on 28 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc