util.d.ts 1.8 KB

12345678910111213141516171819202122232425262728293031
  1. import type { AnySchema, EvaluatedProperties, EvaluatedItems } from "../types";
  2. import type { SchemaCxt, SchemaObjCxt } from ".";
  3. import { Code, Name, CodeGen } from "./codegen";
  4. import type { Rule, ValidationRules } from "./rules";
  5. export declare function toHash<T extends string = string>(arr: T[]): {
  6. [K in T]?: true;
  7. };
  8. export declare function alwaysValidSchema(it: SchemaCxt, schema: AnySchema): boolean | void;
  9. export declare function checkUnknownRules(it: SchemaCxt, schema?: AnySchema): void;
  10. export declare function schemaHasRules(schema: AnySchema, rules: {
  11. [Key in string]?: boolean | Rule;
  12. }): boolean;
  13. export declare function schemaHasRulesButRef(schema: AnySchema, RULES: ValidationRules): boolean;
  14. export declare function schemaRefOrVal({ topSchemaRef, schemaPath }: SchemaObjCxt, schema: unknown, keyword: string, $data?: string | false): Code | number | boolean;
  15. export declare function unescapeFragment(str: string): string;
  16. export declare function escapeFragment(str: string | number): string;
  17. export declare function escapeJsonPointer(str: string | number): string;
  18. export declare function unescapeJsonPointer(str: string): string;
  19. export declare function eachItem<T>(xs: T | T[], f: (x: T) => void): void;
  20. declare type SomeEvaluated = EvaluatedProperties | EvaluatedItems;
  21. declare type MergeEvaluatedFunc<T extends SomeEvaluated> = (gen: CodeGen, from: Name | T, to: Name | Exclude<T, true> | undefined, toName?: typeof Name) => Name | T;
  22. interface MergeEvaluated {
  23. props: MergeEvaluatedFunc<EvaluatedProperties>;
  24. items: MergeEvaluatedFunc<EvaluatedItems>;
  25. }
  26. export declare const mergeEvaluated: MergeEvaluated;
  27. export declare function evaluatedPropsToName(gen: CodeGen, ps?: EvaluatedProperties): Name;
  28. export declare function setEvaluated(gen: CodeGen, props: Name, ps: {
  29. [K in string]?: true;
  30. }): void;
  31. export {};