Skip to content

Commit 7bede94

Browse files
committed
Add hasVocabulary function
1 parent 0f54f33 commit 7bede94

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
@@ -542,6 +542,9 @@ These are available from the `@hyperjump/json-schema/experimental` export.
542542
543543
Define a vocabulary that maps keyword name to keyword URIs defined using
544544
`addKeyword`.
545+
* **hasVocabulary**: (dialectId: string) => boolean;
546+
547+
Determine whether the vocabulary is supported.
545548
* **getKeywordId**: (keywordName: string, dialectId: string) => string
546549
547550
Get the identifier for a keyword by its name.
@@ -571,14 +574,17 @@ These are available from the `@hyperjump/json-schema/experimental` export.
571574
* **getDialectIds**
572575
573576
This function retrieves the identifiers of all loaded JSON Schema dialects.
574-
* **getDialect**: (dialectId: string) => Record<string, string>;
577+
* **getDialect**: (dialectId: string) => Record<string, string>;
578+
579+
This function retrieves all the keywords appropriate for a particular
580+
dialect.
581+
* **hasDialect**: (dialectId: string) => boolean;
575582
576-
This function retrieves all the keywords appropriate for a particular dialect.
583+
Determine whether the dialect is supported.
577584
* **Validation**: Keyword
578585
579586
A Keyword object that represents a "validate" operation. You would use this
580587
for compiling and evaluating sub-schemas when defining a custom keyword.
581-
582588
* **getSchema**: (uri: string, browser?: Browser) => Promise\<Browser>
583589
584590
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: Record<string, string>) => void;
63+
export const hasVocabulary: (vocabularyId: string) => boolean;
6364
export const loadDialect: (dialectId: string, dialect: Record<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
const _persistentDialects = {};

0 commit comments

Comments
 (0)