@userscripters/stackexchange-api-types
Advanced tools
Comparing version 3.1.1 to 3.2.0
import type { | ||
EnumMember, | ||
Expression, | ||
Identifier, | ||
@@ -93,1 +95,70 @@ KeywordTypeSyntaxKind, | ||
}; | ||
export type EnumOptions = { | ||
exported?: boolean; | ||
constant?: boolean; | ||
}; | ||
/** | ||
* @summary creates a enum declaration | ||
* @param f compiler factory to use | ||
* @param name identifier of the enum | ||
* @param expressions members of the enum | ||
* @param options configuration | ||
*/ | ||
export const createEnum = ( | ||
f: NodeFactory, | ||
name: string | Identifier, | ||
expressions: Map<string | Identifier, Expression>, | ||
{ exported = false, constant = false }: EnumOptions = {} | ||
) => { | ||
const modifiers: Modifier[] = []; | ||
if (exported) modifiers.push(f.createModifier(ts.SyntaxKind.ExportKeyword)); | ||
if (constant) modifiers.push(f.createModifier(ts.SyntaxKind.ConstKeyword)); | ||
const members: EnumMember[] = []; | ||
expressions.forEach((expression, name) => { | ||
members.push(f.createEnumMember(name, expression)); | ||
}); | ||
return f.createEnumDeclaration( | ||
undefined, | ||
modifiers, | ||
typeof name === "string" ? f.createIdentifier(name) : name, | ||
members | ||
); | ||
}; | ||
export type StringUnionOptions = { | ||
exported?: boolean; | ||
}; | ||
/** | ||
* @summary creates a string union node | ||
* @param f compiler factory to use | ||
* @param name identifier of the enum | ||
* @param members list of union members | ||
*/ | ||
export const createStringUnion = ( | ||
f: NodeFactory, | ||
name: string | Identifier, | ||
members: string[], | ||
{ exported = false }: StringUnionOptions = {} | ||
) => { | ||
const modifiers: Modifier[] = []; | ||
if (exported) modifiers.push(f.createModifier(ts.SyntaxKind.ExportKeyword)); | ||
const union = f.createUnionTypeNode( | ||
members.map((type) => | ||
f.createLiteralTypeNode(f.createStringLiteral(type)) | ||
) | ||
); | ||
return f.createTypeAliasDeclaration( | ||
undefined, | ||
modifiers, | ||
typeof name === "string" ? f.createIdentifier(name) : name, | ||
undefined, | ||
union | ||
); | ||
}; |
@@ -5,2 +5,3 @@ import got from "got"; | ||
import { URL } from "url"; | ||
import { generateBuiltInFilters } from "./filters.js"; | ||
import { InterfaceOptions, parseInterface } from "./parsers.js"; | ||
@@ -136,2 +137,10 @@ import { printNodesToFile } from "./printer.js"; | ||
); | ||
await generateBuiltInFilters( | ||
factory, | ||
DOCS_BASE, | ||
"/docs/filters", | ||
`${TYPES_PATH}/filters.d.ts`, | ||
"Filters" | ||
); | ||
} |
@@ -36,2 +36,13 @@ import got from "got"; | ||
/** | ||
* @summary capitalizes the filter name, as well as trims, and removes leading and trailing dots | ||
* @param name non-normalized type name (i.e. just parsed from docs) | ||
*/ | ||
export const normalizeFilterName = (name: string) => { | ||
return name | ||
.trim() | ||
.replace(/^[.]|[.]$/g, "") | ||
.toLowerCase(); | ||
}; | ||
/** | ||
* @summary fetches a JSDOM document from a URL | ||
@@ -38,0 +49,0 @@ */ |
@@ -9,4 +9,5 @@ import {Wrappers} from "./lib/wrapper"; | ||
export * from "./lib/filters"; | ||
export * from "./lib/types"; | ||
export * from "./lib/wrapper"; | ||
export as namespace StackExchangeAPI; |
{ | ||
"name": "@userscripters/stackexchange-api-types", | ||
"description": "Stack Exchange API types generator", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Oleg Valter", |
@@ -9,3 +9,3 @@ | ||
| License | [GPL-3.0-or-later](https://spdx.org/licenses/GPL-3.0-or-later) | | ||
| Version | 3.1.1 | | ||
| Version | 3.2.0 | | ||
@@ -12,0 +12,0 @@ # Support |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45777
23
1216