@thi.ng/wasm-api-bindgen
Version:
Polyglot bindings code generators (TS/JS, Zig, C11) for hybrid WebAssembly projects
120 lines • 4.36 kB
TypeScript
import type { BigType, Keys, Nullable } from "@thi.ng/api";
import type { CodeGenOpts, Field, InjectedBody, Struct, TopLevelType, TypeColl, Union, WasmPrim, WasmPrim32 } from "../api.js";
/**
* Returns true iff `x` is a {@link WasmPrim32}.
*
* @param x
*/
export declare const isNumeric: (x: string) => x is WasmPrim32;
/**
* Returns true iff `x` is a `i64` or `u64`.
*
* @param x
*/
export declare const isBigNumeric: (x: string) => x is BigType;
export declare const isSizeT: (x: string) => x is "isize" | "usize";
/**
* Returns true iff `x` is a {@link WasmPrim}.
*
* @param x
*/
export declare const isWasmPrim: (x: string) => x is WasmPrim;
export declare const isWasmString: (x: string) => x is "string";
export declare const isPadding: (f: Pick<Field, "pad">) => boolean;
export declare const isPointer: (x: Field["tag"]) => x is "ptr";
export declare const isFuncPointer: (type: string, coll: TypeColl) => boolean;
export declare const isEnum: (type: string, coll: TypeColl) => boolean;
export declare const isExternal: (type: string, coll: TypeColl) => boolean;
export declare const isSlice: (x: Field["tag"]) => x is "slice";
export declare const isOpaque: (x: string) => x is "opaque";
/**
* Returns true iff the struct field is a pointer, slice or "string" type
*
* @param f
*/
export declare const isPointerLike: (f: Field, coll: TypeColl) => boolean;
/**
* Returns true if `type` is "slice".
*
* @param type
*/
export declare const isStringSlice: (type: CodeGenOpts["stringType"]) => type is "slice";
export declare const isStruct: (x: TopLevelType) => x is Struct;
export declare const isUnion: (x: TopLevelType) => x is Union;
/**
* Returns true if `x` is a struct or union and contains string fields.
*
* @param x
*/
export declare const hasStringFields: (x: TopLevelType) => boolean;
/**
* Returns true if the given type collection contains structs or unions with
* string fields.
*
* @param coll
*/
export declare const usesStrings: (coll: TypeColl) => boolean;
/**
* Returns filtered array of struct fields of with "ptr" tag or function
* pointers.
*
* @param fields
*
* @internal
*/
export declare const pointerFields: (fields: Field[]) => Field[];
/**
* Returns filtered array of struct fields of only "string" fields.
*
* @param fields
*
* @internal
*/
export declare const stringFields: (fields: Field[]) => Field[];
export declare const sliceTypes: (coll: TypeColl) => Set<string | null>;
/**
* Returns enum identifier formatted according to given opts.
*
* @param opts
* @param name
*
* @internal
*/
export declare const enumName: (opts: CodeGenOpts, name: string) => string;
/**
* Returns given field's default value (or undefined). The `lang` ID is required
* to obtain the language specific value if the default is given as object.
*
* @param f
* @param lang
*/
export declare const defaultValue: (f: Field, lang: string) => import("@thi.ng/api").NumOrString | undefined;
/**
* Takes an array of strings or splits given string into lines, word wraps and
* then prefixes each line with given `width` and `prefix`. Returns array of new
* lines.
*
* @param prefix
* @param str
* @param width
*/
export declare const prefixLines: (prefix: string, str: string | string[], width: number) => string[];
export declare const ensureLines: (src: string | string[] | InjectedBody, key?: keyof InjectedBody) => Iterable<string>;
export declare const ensureStringArray: (src: string | string[]) => string[];
/**
* Yields iterator of given lines, each with applied indentation based on given
* scope regexp's which are applied to each line to increase or decrease
* indentation level (the initial indentation level can be specified via
* optional `level` arg, default 0). If `scopeStart` succeeds, the indent is
* increased for the _next_ line. If `scopeEnd` succeeds the level is decreased
* for the _current_ line. ...
*
* @param lines
* @param indent
* @param scopeStart
* @param scopeEnd
* @param level
*/
export declare function withIndentation(lines: string[], indent: string, scopeStart: RegExp, scopeEnd: RegExp, level?: number): Generator<string, void, unknown>;
export declare const injectBody: (acc: string[], body: Nullable<string | string[] | InjectedBody>, key?: Keys<InjectedBody>) => number | "" | null | undefined;
//# sourceMappingURL=utils.d.ts.map