Skip to content

Add typings #34

@matthieusieben

Description

@matthieusieben

I am currently using the following to type @hapi/nigel. It would be nice if this module exported its own types. I d'ont have the time or resources to make a PR. Sorry about that.

// types.d.ts

declare module '@hapi/nigel' {
  import { Writable } from 'node:stream'

  export interface Haystack {
    readonly length: number
    readUInt8: (pos: number) => number | undefined
    startsWith?: (value: Buffer, pos?: number, length?: number) => boolean
  }

  export interface Needle {
    readonly value: Buffer
    readonly lastPos: number
    readonly last: number
    readonly length: number
    readonly badCharShift: Buffer
  }

  export function compile(needle: Buffer): Needle
  export function horspool(haystack: Haystack, needle: Needle | Buffer, start?: number): number
  export function all(haystack: Haystack, needle: Needle | Buffer, start?: number): number[]

  export class Stream extends Writable {
    constructor(needle: Buffer)
    needle(needle: Buffer): void
    flush(): void
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionality or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions