Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript types #43

Open
timmywil opened this issue Feb 10, 2023 · 2 comments
Open

Add TypeScript types #43

timmywil opened this issue Feb 10, 2023 · 2 comments

Comments

@timmywil
Copy link

I manually added types to my repo, but it's not comprehensive and only covers what I use. It would be great if this repo maintained its own types. Switching to TypeScript is not required. Only need to add a .d.ts file to the repo and set the types field in package.json.

Here's what I've gotten started, but I'm sure it's not completely accurate.

// webvtt-parser.d.ts
declare module 'webvtt-parser' {
  export interface Cue {
    direction: 'horizontal' | 'vertical'
    id: string
    startTime: number
    endTime: number
    text: string
    lineAlign: 'start' | 'center' | 'end'
    linePosition: 'auto' | number
    pauseOnExit: boolean
    positionAlign: 'auto' | 'start' | 'center' | 'end'
    size: number
    snapToLines: boolean
    textPosition: 'auto' | number
    tree: {
      children: {
        type: 'text'
        value: string
      }[]
    }
  }

  export class WebVTTParser {
    public parse: (
      input: string,
      mode: 'metadata' | 'chapters'
    ) => {
      cues: Cue[]
      errors: Error[]
      time: number
    }
  }
  export class WebVTTSerializer {
    public serialize: (cues: Cue[]) => string
  }
}

Thanks for considering.

@lionel-rowe
Copy link

@timmywil 's types look like a good start. It looks like Cue#tree.children has the type Child[], where Child is defined like this:

type Child = {
	type: 'text'
	value: string
} | {
	type: 'object'
	name: 'v' | 'lang'
	classes: string[]
	children: Child[]
	value: string
} | {
	type: 'object'
	name: 'c' | 'i' | 'b' | 'u' | 'ruby' | 'rt'
	classes: string[]
	children: Child[]
}

Also WebVTTParser's constructor takes entities?: Record<string, string> as a parameter.

@cellulosa
Copy link

any plans to implement this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants