Skip to content

Commit 6dcae06

Browse files
committed
Add hasVocabulary function
1 parent f98669f commit 6dcae06

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
@@ -539,6 +539,9 @@ These are available from the `@hyperjump/json-schema/experimental` export.
539539
540540
Define a vocabulary that maps keyword name to keyword URIs defined using
541541
`addKeyword`.
542+
* **hasVocabulary**: (dialectId: string) => boolean;
543+
544+
Determine whether the vocabulary is supported.
542545
* **getKeywordId**: (keywordName: string, dialectId: string) => string
543546
544547
Get the identifier for a keyword by its name.
@@ -568,14 +571,17 @@ These are available from the `@hyperjump/json-schema/experimental` export.
568571
* **getDialectIds**
569572
570573
This function retrieves the identifiers of all loaded JSON Schema dialects.
571-
* **getDialect**: (dialectId: string) => Record<string, string>;
574+
* **getDialect**: (dialectId: string) => Record<string, string>;
575+
576+
This function retrieves all the keywords appropriate for a particular
577+
dialect.
578+
* **hasDialect**: (dialectId: string) => boolean;
572579
573-
This function retrieves all the keywords appropriate for a particular dialect.
580+
Determine whether the dialect is supported.
574581
* **Validation**: Keyword
575582
576583
A Keyword object that represents a "validate" operation. You would use this
577584
for compiling and evaluating sub-schemas when defining a custom keyword.
578-
579585
* **getSchema**: (uri: string, browser?: Browser) => Promise\<Browser>
580586
581587
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
@@ -60,6 +60,7 @@ export const getKeyword: <A>(id: string) => Keyword<A>;
6060
export const getKeywordByName: <A>(keywordName: string, dialectId: string) => Keyword<A>;
6161
export const getKeywordId: (keywordName: string, dialectId: string) => string;
6262
export const defineVocabulary: (id: string, keywords: { [keyword: string]: string }) => void;
63+
export const hasVocabulary: (vocabularyId: string) => boolean;
6364
export const loadDialect: (dialectId: string, dialect: { [vocabularyId: string]: boolean }, allowUnknownKeywords?: boolean) => void;
6465
export const unloadDialect: (dialectId: string) => void;
6566
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 } 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
const _allowUnknownKeywords = {};
3941

0 commit comments

Comments
 (0)