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

[Suggestion] TypeScript Conversion / Support #126

Open
samuel-greenberg opened this issue Jun 23, 2022 · 8 comments
Open

[Suggestion] TypeScript Conversion / Support #126

samuel-greenberg opened this issue Jun 23, 2022 · 8 comments
Milestone

Comments

@samuel-greenberg
Copy link

I like this parser and as a TypeScript user am interested in a typed version of this package. Wanted to start a discussion about that process if you are interested, and how I can help in the event it moves forward.

@osk
Copy link
Owner

osk commented Jun 24, 2022

Thanks!

Yes, that's a good addition. Feel free to open a PR, otherwise it's something I could get to in the next few weeks.

@osk osk added this to the version-1.10 milestone Jun 24, 2022
@samuel-greenberg
Copy link
Author

samuel-greenberg commented Jun 24, 2022

Awesome! I'll likely have a PR up to make those updates in the next week or so :)

Update - 7/7/22: Finished converting lib to typescipt, focusing on tests now and making sure I'm not breaking anything 😁

@samuel-greenberg
Copy link
Author

Draft PR is up, it's definitely a bit of a beast.

It all functions as expected, but there are some eslint issues left to solve.

Thanks for the patience, I've had some stuff come up and was busier than expected.

@meoyawn
Copy link

meoyawn commented Jun 23, 2023

rough sketch of the types

declare module "node-webvtt" {
  interface Opts {
    meta?: boolean
    strict?: boolean
  }

  export interface Cue {
    identifier: string
    start: number
    end: number
    text: string
    styles: string
  }

  export interface VTT {
    valid: boolean
    strict: boolean
    cues: Cue[]
    errors: unknown[]
    meta?: Partial<Record<string, string>>
  }

  export interface Segment {
    duration: number
    cues: ReadonlyArray<Cue>
  }

  export function parse(input: string, options?: Opts): VTT

  export function compile(input: VTT): string

  export namespace hls {
    export function hlsSegment(
      input: string,
      segmentLength?: number,
      startOffset?: number,
    ): ReadonlyArray<Segment>

    export function hlsSegmentPlaylist(
      input: string,
      segmentLength?: number,
    ): ReadonlyArray<Segment>
  }
}

@goatandsheep
Copy link
Collaborator

@meoyawn @samuel-greenberg what if we just added a typedef? would that be easier? I noticed the PR was closed

@cellulosa
Copy link

any update on this?

@goatandsheep
Copy link
Collaborator

@cellulosa let me know if we can just add a typedef instead

@cellulosa
Copy link

I mean that'd be an easy fix for the time being

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

5 participants