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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@umbraco/json-models-builders

v2.0.19

Published

Builders and models for Umbraco Sites

Downloads

680

Readme

Umbraco.JsonModels.Builder

Umbraco.JsonModels.Builder is a package made for use with Umbraco. This package is meant to contain all the Umbraco backoffice models, and their corresponding builders. If you see any model/builder missing, please create an issue / open a PR for it yourself, we would love your contribution!

What even is a builder?

Before we even get started, lets talk about what a builder is. We are using the Builder pattern here. The builder is a class that creates a model, but you yourself can then use that builder to tweak the different properties. If you take a look at the DocumentTypeBuilder you will see all these properties:

compositeContentTypes;
isContainer;
allowAsRoot;
allowedTemplates;
allowedContentTypes;
alias;
description;
thumbnail;
name;
id;
icon;
trashed;
key;
parentId;
path;
allowCultureVariant;
isElement;
defaultTemplate;
lockedCompositeContentTypes: any[];
historyCleanupPreventCleanup;
historyCleanupKeepAllVersionsNewerThanDays;
historyCleanupKeepLatestVersionPerDayForDays;
documentTypeGroupBuilders;
documentTypeHistoryCleanupBuilder;

This looks very daunting, what types are these properties, what values do you fill out? You could imagine this being a big process, every time you needed to create a document type. Well the builder handles setting all of this for you! So all you would need to do, when using a builder to create a document type is:

const documentType = new DocumentTypeBuilder()
      .build();

The builder will then fill out all the properties with default values!

Prerequisites

This project was made with Node V16, so the minimum requirement is node 16.17.1

Getting started

You can import a builder in the top of your file like so:

import {  DocumentTypeBuilder} from "@umbraco/json-models-builders";

You can then use the imported builder to build a model:

const documentType = new DocumentTypeBuilder()
      .build();

If you want to configure a property, like giving the document type a specific name, there are different methods for that, for changing the name, you can call the withName() method like so:

const documentType = new DocumentTypeBuilder()
      .withName("My document type")
      .build();

Contributing to Umbraco.JsonModels.Builders

There are a few things to consider when contributing

Adding new models/builders

When adding new models/builders, it is important to register the exports in the correct index.ts files! Lets say you've added a new builder, remember to export it in the lib/builders/index.ts file.

Testing your code

  • Run npm run build & npm link in the root of this directory.
  • Now the package is ready to be linked where-ever you are using it, without it having to be on npm!
  • Run npm link @umbraco/json-models-builders in your directory where you are using this package.