publicsuffixlist.js icon indicating copy to clipboard operation
publicsuffixlist.js copied to clipboard

Typescript type definitions

Open SebastienGllmt opened this issue 3 years ago • 0 comments

This isn't on npm so maybe not worth submitting to the @types package, but here is the type definition for the API of this library in case somebody else finds it useful

declare module "publicsuffixlist.js" {
  type Selfie =
    | string
    | {
        magic: number;
        buf32: number[];
      };
  type Decoder = {
    decode: (bufferStr: string, buffer: ArrayBuffer) => void;
    decodeSize: (bufferStr: string) => number;
  };
  type Encoder = {
    encode: (buffer: ArrayBuffer, length: number) => string;
  };
  class PublicSuffixList {
    version: string;

    parse(text: string, toAscii: (input: string) => string): void;

    getPublicSuffix(hostname: string): string;
    getDomain(hostname: string): string;

    suffixInPSL(hostname: string): boolean;

    toSelfie(encoder?: null | Encoder): Selfie;
    fromSelfie(selfie: Selfie, decoder?: null | Decoder): boolean;

    enableWASM(options?: {
      customFetch?: null | ((url: URL) => Promise<Blob>);
    }): Promise<boolean>;
    disableWASM(): Promise<boolean>;
  }

  const psl: PublicSuffixList;
  export default psl;
}

SebastienGllmt avatar Dec 02 '21 13:12 SebastienGllmt