Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@stackmeister/json-ref

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stackmeister/json-ref

@stackmeister/json-ref ==========================

latest
Source
npmnpm
Version
0.1.5
Version published
Maintainers
1
Created
Source

@stackmeister/json-ref

Typing and utilities for working with JSON-Schema Refs ({ $ref: '' })

Install

// Yarn
yarn add @stackmeister/json-ref

// NPM
npm i @stackmeister/json-ref

TypeScript typings are included (No @types/ package needed)

Usage

Dereferencing a value

The most important key function of this library is dereferencing.

It takes any value and will recursively resolve any JSON-refs found in it.

It supports all common operations regarding $id and $anchor in the JSON-schema standard.

Notice the input value doesn't have to be a JSON-Schema! Dereferencing can be used on any JavaScript value freely.

import type { deref } from '@stackmeister/json-ref'

const user = {
  properties: {
    email: { $ref: '#/$defs/email' },
    password: { type: 'string', minLength: 5 },
  },
  $defs: {
    email: { type: 'string' }
  }
}

const resolvedUser = await deref(user)

Resolving external URLs, handling internal ID/Base-URLs via $id, internal anchors etc. are all fully supported.

It also comes with proper typing which allows you to cleanly remove refs from a type-definition once resolved.

FAQs

Package last updated on 09 Nov 2022

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