Skip to content

Commit 759e4e4

Browse files
committed
Add hasVocabulary function
1 parent 90fdcac commit 759e4e4

4 files changed

Lines changed: 13 additions & 4 deletions

File tree

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,9 @@ These are available from the `@hyperjump/json-schema/experimental` export.
697697
698698
Define a vocabulary that maps keyword name to keyword URIs defined using
699699
`addKeyword`.
700+
* **hasVocabulary**: (dialectId: string) => boolean;
701+
702+
Determine whether the vocabulary is supported.
700703
* **getKeywordId**: (keywordName: string, dialectId: string) => string
701704
702705
Get the identifier for a keyword by its name.
@@ -726,14 +729,17 @@ These are available from the `@hyperjump/json-schema/experimental` export.
726729
* **getDialectIds**
727730
728731
This function retrieves the identifiers of all loaded JSON Schema dialects.
729-
* **getDialect**: (dialectId: string) => Record<string, string>;
732+
* **getDialect**: (dialectId: string) => Record<string, string>;
733+
734+
This function retrieves all the keywords appropriate for a particular
735+
dialect.
736+
* **hasDialect**: (dialectId: string) => boolean;
730737
731-
This function retrieves all the keywords appropriate for a particular dialect.
738+
Determine whether the dialect is supported.
732739
* **Validation**: Keyword
733740
734741
A Keyword object that represents a "validate" operation. You would use this
735742
for compiling and evaluating sub-schemas when defining a custom keyword.
736-
737743
* **getSchema**: (uri: string, browser?: Browser) => Promise\<Browser>
738744
739745
Get a schema by it's URI taking the local schema registry into account.

lib/experimental.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const addFormat: (format: Format) => void;
6565
export const setFormatHandler: (keywordUri: string, formatName: string, formatUri: string) => void;
6666
export const removeFormatHandler: (keywordUri: string, formatName: string) => void;
6767
export const defineVocabulary: (id: string, keywords: Record<string, string>) => void;
68+
export const hasVocabulary: (vocabularyId: string) => boolean;
6869
export const loadDialect: (dialectId: string, dialect: Record<string, boolean>, allowUnknownKeywords?: boolean) => void;
6970
export const unloadDialect: (dialectId: string) => void;
7071
export const hasDialect: (dialectId: string) => boolean;

lib/experimental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export { compile, interpret, BASIC, DETAILED } from "./core.js";
22
export {
33
addKeyword, getKeyword, getKeywordByName, getKeywordName, getKeywordId,
44
addFormat, setFormatHandler, removeFormatHandler,
5-
defineVocabulary,
5+
defineVocabulary, hasVocabulary,
66
loadDialect, unloadDialect, hasDialect, getDialectIds, getDialect
77
} from "./keywords.js";
88
export { getSchema, toSchema, canonicalUri, buildSchemaDocument } from "./schema.js";

lib/keywords.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export const removeFormatHandler = (keywordUri, formatName) => {
5151
delete _keywords[keywordUri].formats[formatName];
5252
};
5353

54+
export const hasVocabulary = (vocabularyId) => vocabularyId in _vocabularies;
55+
5456
const _dialects = {};
5557

5658
export const getKeywordId = (keyword, dialectId) => {

0 commit comments

Comments
 (0)