Skip to content

Commit

Permalink
export LanguageName type and predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
inferrinizzard committed Apr 16, 2024
1 parent 719a028 commit a0e399a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/quicktype-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export { Ref, JSONSchemaType, JSONSchemaAttributes } from "./input/JSONSchemaInp
export { RenderContext } from "./Renderer";
export { Option, OptionDefinition, getOptionValues, OptionValues } from "./RendererOptions";
export { TargetLanguage, MultiFileRenderResult } from "./TargetLanguage";
export { all as defaultTargetLanguages, languageNamed } from "./language/All";
export { all as defaultTargetLanguages, languageNamed, isLanguageName } from "./language/All";
export {
MultiWord,
Sourcelike,
Expand Down Expand Up @@ -81,6 +81,7 @@ export { StringTypes } from "./attributes/StringTypes";
export { removeNullFromUnion, matchType, nullableFromUnion } from "./TypeUtils";
export { ConvenienceRenderer } from "./ConvenienceRenderer";
export { uriTypeAttributeKind } from "./attributes/URIAttributes";
export { type LanguageName, type LanguageDisplayName } from "./types";

export { CJSONTargetLanguage, CJSONRenderer, cJSONOptions } from "./language/CJSON";
export { CPlusPlusTargetLanguage, CPlusPlusRenderer, cPlusPlusOptions } from "./language/CPlusPlus";
Expand Down
15 changes: 14 additions & 1 deletion packages/quicktype-core/src/language/All.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { PhpTargetLanguage } from "./Php";
import { TypeScriptEffectSchemaTargetLanguage } from "./TypeScriptEffectSchema";
import { ElixirTargetLanguage } from "./Elixir";

import type { LanguageName, LanguageNameMap } from "../types";
import type { LanguageDisplayName, LanguageName, LanguageNameMap } from "../types";

export const all = [
new CJSONTargetLanguage(),
Expand Down Expand Up @@ -72,3 +72,16 @@ export function languageNamed<Name extends LanguageName>(

return foundLanguage as LanguageNameMap[Name];
}

export function isLanguageName(maybeName: string): maybeName is LanguageName {
if (all.some(lang => (lang.names as readonly string[]).includes(maybeName))) {
return true;
}
return false;
}
export function isLanguageDisplayName(maybeName: string): maybeName is LanguageDisplayName {
if (all.some(lang => lang.displayName === maybeName)) {
return true;
}
return false;
}

0 comments on commit a0e399a

Please sign in to comment.