Skip to content

Commit 4fa7aa5

Browse files
committed
Add hasSchema function
1 parent e45b79c commit 4fa7aa5

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ Schema, such as `@hyperjump/json-schema/draft-2020-12`.
201201
* **unregisterSchema**: (uri: string) => void
202202
203203
Remove a schema from the local schema registry.
204+
* **hasSchema**: (uri: string) => boolean
205+
206+
Check if a schema with the given URI is already registered.
204207
* _(deprecated)_ **addSchema**: (schema: object, retrievalUri?: string, defaultDialectId?: string) => void
205208
206209
Load a schema manually rather than fetching it from the filesystem or over

lib/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export type SchemaObject = { // eslint-disable-line @typescript-eslint/consisten
88

99
export const registerSchema: (schema: SchemaObject | boolean, retrievalUri?: string, contextDialectId?: string) => void;
1010
export const unregisterSchema: (retrievalUri: string) => void;
11+
export const hasSchema: (uri: string) => boolean;
1112

1213
/**
1314
* @deprecated since 1.7.0. Use registerSchema instead.

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ addKeyword(vocabulary);
130130
addKeyword(writeOnly);
131131

132132
export { addSchema, unregisterSchema, validate, FLAG } from "./core.js";
133-
export { registerSchema } from "./schema.js";
133+
export { registerSchema, hasSchema } from "./schema.js";
134134
export {
135135
getMetaSchemaOutputFormat,
136136
setMetaSchemaOutputFormat,

lib/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export const unregisterSchema = (uri) => {
5959
delete schemaRegistry[normalizedUri];
6060
};
6161

62+
export const hasSchema = (uri) => uri in schemaRegistry;
63+
6264
export const buildSchemaDocument = (schema, id, dialectId, embedded = {}) => {
6365
// Dialect / JSON Schema Version
6466
if (typeof schema.$schema === "string") {

0 commit comments

Comments
 (0)