Skip to content

Commit

Permalink
Add hasVocabulary function
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesrosiers committed Nov 12, 2024
1 parent 370cfa4 commit 09ef294
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ These are available from the `@hyperjump/json-schema/experimental` export.
Define a vocabulary that maps keyword name to keyword URIs defined using
`addKeyword`.
* **hasVocabulary**: (dialectId: string) => boolean;
Determine whether the vocabulary is supported.
* **getKeywordId**: (keywordName: string, dialectId: string) => string
Get the identifier for a keyword by its name.
Expand Down Expand Up @@ -568,14 +571,17 @@ These are available from the `@hyperjump/json-schema/experimental` export.
* **getDialectIds**
This function retrieves the identifiers of all loaded JSON Schema dialects.
* **getDialect**: (dialectId: string) => Record<string, string>;
* **getDialect**: (dialectId: string) => Record<string, string>;
This function retrieves all the keywords appropriate for a particular
dialect.
* **hasDialect**: (dialectId: string) => boolean;
This function retrieves all the keywords appropriate for a particular dialect.
Determine whether the dialect is supported.
* **Validation**: Keyword
A Keyword object that represents a "validate" operation. You would use this
for compiling and evaluating sub-schemas when defining a custom keyword.
* **getSchema**: (uri: string, browser?: Browser) => Promise\<Browser>
Get a schema by it's URI taking the local schema registry into account.
Expand Down
1 change: 1 addition & 0 deletions lib/experimental.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const getKeyword: <A>(id: string) => Keyword<A>;
export const getKeywordByName: <A>(keywordName: string, dialectId: string) => Keyword<A>;
export const getKeywordId: (keywordName: string, dialectId: string) => string;
export const defineVocabulary: (id: string, keywords: Record<string, string>) => void;
export const hasVocabulary: (vocabularyId: string) => boolean;
export const loadDialect: (dialectId: string, dialect: Record<string, boolean>, allowUnknownKeywords?: boolean) => void;
export const unloadDialect: (dialectId: string) => void;
export const hasDialect: (dialectId: string) => boolean;
Expand Down
2 changes: 1 addition & 1 deletion lib/experimental.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { compile, interpret, BASIC } from "./core.js";
export {
addKeyword, getKeyword, getKeywordByName, getKeywordName, getKeywordId,
defineVocabulary,
defineVocabulary, hasVocabulary,
loadDialect, unloadDialect, hasDialect, getDialectIds, getDialect
} from "./keywords.js";
export { getSchema, toSchema, canonicalUri, buildSchemaDocument } from "./schema.js";
Expand Down
2 changes: 2 additions & 0 deletions lib/keywords.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const defineVocabulary = (id, keywords) => {
_vocabularies[id] = keywords;
};

export const hasVocabulary = (vocabularyId) => vocabularyId in _vocabularies;

const _dialects = {};
const _allowUnknownKeywords = {};

Expand Down

0 comments on commit 09ef294

Please sign in to comment.