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

@datadayrepos/json-schema-common

v0.0.1-beta.11

Published

Utils for json schema renders and editors. No framework dependency

Downloads

3

Readme

Json-Schema-Common

This holds a set of utility functions used across both render and editor tooling for json-schemas.

This is the access point for three main functionalities that are used frequently:

  • getDefaultFormState
  • retrieveSchema
  • validator And a number of form-utility functions.

No dependency on vue or uix frameworks.

🛠 Install

pnpm add @datadayrepos/json-schema-common

💻 Code

RetrieveSchema

Retrieves schema to resolve and normalize a JSON schema. Inspired by react json form, but quite simpler logic, optimized. Also, we dont go recursivelythrough the schema, so it is mostly used for sending in subschemas and resolve their dependencies.

/*
Retrieves schema to resolve and normalize a JSON schema. This means taking a given schema (and possibly a root or parent schema) and processing it to a standard, usable format. This could involve resolving $ref references, handling schema dependencies, or flattening nested schemas.
*/
import { retrieveSchema } from '@datadayrepos/json-schema-common'

GetDefaultFormState

/*
getDefaultFormState is a utility function that calculates default values for a form, based on its JSON Schema. It returns a new object that contains default values for all fields in the form. The resulting object can be used as the formData prop for a JSON Schema form.
*/
import { getDefaultFormState } from '@datadayrepos/json-schema-common'

Validator

This initiates, and imports the validator. It returns a very large object, and by initializing it only once, we save some processing time.

This is really a proxy for importing the full @datadayrepos/json-schema-validator - but deigned to persist the main imported class as a constant.

There are many methods and utilities exposed, but at the outset we really only need these two:

/*
useful when dealing with conditional schemas
like 'oneOf' or 'anyOf'. It identifies which schema from a list of options best matches the current state of formData.
*/
import { validator } from '@datadayrepos/json-schema-common'

// two main methods are exposed here

// simple boolean return
const val = validator.isValidFormData(data, schema, rootschema)

// returns validation errors
const val = validator.validateFormData(data, schema, rootschema)

This validates to schema version 7. Other drafts and utilities are available. See the docs for '@datadayrepos/json-schema-validator'

Utilities

Various form processng utilities used throughout the application.

// form utils exports
import {
  allowAdditionalItems,
  fallbackLabel,
  getSchemaType,
  getUiField,
  getUiOptions,
  getUserErrOptions,
  getWidgetConfig,
  isFixedItems,
  isMultiSelect,
  isSelect,
  optionsList,
  orderProperties,
  replaceArrayIndex,
  shouldShowItem,
} from '@datadayrepos/json-schema-common'

Constants

Various form constants used throughout the application.

// todo? move to application level?
import {
  ADDITIONAL_PROPERTIES_KEY,
  ADDITIONAL_PROPERTY_FLAG,
  ALL_OF_KEY,
  ANY_OF_KEY,
  CONST_KEY,
  DEFAULT_KEY,
  DEFINITIONS_KEY,
  DEPENDENCIES_KEY,
  ENUM_KEY,
  ERRORS_KEY,
  ID_KEY,
  ITEMS_KEY,
  NAME_KEY,
  ONE_OF_KEY,
  PROPERTIES_KEY,
  REF_KEY,
  REQUIRED_KEY,
  SUBMIT_BTN_OPTIONS_KEY,
  UI_FIELD_KEY,
  UI_OPTIONS_KEY,
  UI_WIDGET_KEY,
} from '@datadayrepos/json-schema-common'

📄 License

Prop License © 2023 Ivar Strand