Skip to content

Commit 85315e3

Browse files
committed
Add hasVocabulary function
1 parent 1cfe63d commit 85315e3

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ These are available from the `@hyperjump/json-schema/experimental` export.
556556
557557
Define a vocabulary that maps keyword name to keyword URIs defined using
558558
`addKeyword`.
559+
* **hasVocabulary**: (dialectId: string) => boolean;
560+
561+
Determine whether the vocabulary is supported.
559562
* **getKeywordId**: (keywordName: string, dialectId: string) => string
560563
561564
Get the identifier for a keyword by its name.
@@ -585,14 +588,17 @@ These are available from the `@hyperjump/json-schema/experimental` export.
585588
* **getDialectIds**
586589
587590
This function retrieves the identifiers of all loaded JSON Schema dialects.
588-
* **getDialect**: (dialectId: string) => Record<string, string>;
591+
* **getDialect**: (dialectId: string) => Record<string, string>;
592+
593+
This function retrieves all the keywords appropriate for a particular
594+
dialect.
595+
* **hasDialect**: (dialectId: string) => boolean;
589596
590-
This function retrieves all the keywords appropriate for a particular dialect.
597+
Determine whether the dialect is supported.
591598
* **Validation**: Keyword
592599
593600
A Keyword object that represents a "validate" operation. You would use this
594601
for compiling and evaluating sub-schemas when defining a custom keyword.
595-
596602
* **getSchema**: (uri: string, browser?: Browser) => Promise\<Browser>
597603
598604
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
@@ -62,6 +62,7 @@ export const getKeyword: <A>(id: string) => Keyword<A>;
6262
export const getKeywordByName: <A>(keywordName: string, dialectId: string) => Keyword<A>;
6363
export const getKeywordId: (keywordName: string, dialectId: string) => string;
6464
export const defineVocabulary: (id: string, keywords: Record<string, string>) => void;
65+
export const hasVocabulary: (vocabularyId: string) => boolean;
6566
export const loadDialect: (dialectId: string, dialect: Record<string, boolean>, allowUnknownKeywords?: boolean) => void;
6667
export const unloadDialect: (dialectId: string) => void;
6768
export const hasDialect: (dialectId: string) => boolean;

lib/experimental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export { compile, interpret, BASIC, DETAILED } from "./core.js";
22
export {
33
addKeyword, getKeyword, getKeywordByName, getKeywordName, getKeywordId,
4-
defineVocabulary,
4+
defineVocabulary, hasVocabulary,
55
loadDialect, unloadDialect, hasDialect, getDialectIds, getDialect
66
} from "./keywords.js";
77
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
@@ -34,6 +34,8 @@ export const defineVocabulary = (id, keywords) => {
3434
_vocabularies[id] = keywords;
3535
};
3636

37+
export const hasVocabulary = (vocabularyId) => vocabularyId in _vocabularies;
38+
3739
const _dialects = {};
3840

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

0 commit comments

Comments
 (0)