Skip to content

Commit

Permalink
Corepack test
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencrader committed Dec 4, 2023
1 parent e802cbe commit 5002442
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 71 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@typescript-eslint/return-await": ["error", "in-try-catch"],
"jsdoc/require-param-type": 0,
"jsdoc/require-returns-type": 0,
"jsdoc/no-undefined-types": 0,
"jsdoc/require-jsdoc": [
"error",
{
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Enable Corepack
run: corepack enable

- name: Set Node.js 16.x
uses: actions/setup-node@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Enable Corepack
run: corepack enable

- name: Set Node.js 16.x
uses: actions/setup-node@v3
with:
Expand Down
5 changes: 0 additions & 5 deletions src/formats/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type HTMLSegmentPart = {

/**
* Determines if the value of data is a valid HTML transcript format
*
* @param data The transcript data
* @returns True: data is valid HTML transcript format
*/
Expand All @@ -42,7 +41,6 @@ export const isHTML = (data: string): boolean => {

/**
* Updates HTML Segment parts if expected HTML segment
*
* @param element HTML segment to check
* @param segmentPart Current segment parts
* @returns Updated HTML Segment part and segment data for next segment (if fields encountered)
Expand Down Expand Up @@ -85,7 +83,6 @@ const updateSegmentPartFromElement = (

/**
* Create Segment from HTML segment parts
*
* @param segmentPart HTML segment data
* @param lastSpeaker Name of last speaker. Will be used if no speaker found in `segmentLines`
* @returns Created segment
Expand All @@ -106,7 +103,6 @@ const createSegmentFromSegmentPart = (segmentPart: HTMLSegmentPart, lastSpeaker:

/**
* Parse HTML data and create {@link Segment} for each segment data found in data
*
* @param elements HTML elements containing transcript data
* @returns Segments created from HTML data
*/
Expand Down Expand Up @@ -168,7 +164,6 @@ const getSegmentsFromHTMLElements = (elements: Array<HTMLElement>): Array<Segmen

/**
* Parse HTML data to an Array of {@link Segment}
*
* @param data The transcript data
* @returns An array of Segments from the parsed data
* @throws {TypeError} When `data` is not valid HTML format
Expand Down
7 changes: 0 additions & 7 deletions src/formats/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export type SubtitleSegment = {

/**
* Determines if the value of data is a valid JSON transcript format
*
* @param data The transcript data
* @returns True: data is valid JSON transcript format
*/
Expand All @@ -69,7 +68,6 @@ export const isJSON = (data: string): boolean => {

/**
* Parse JSON data where segments are in the `segments` Array and in the {@link JSONSegment} format
*
* @param data Parsed JSON data
* @returns An array of Segments from the parsed data
*/
Expand All @@ -95,7 +93,6 @@ const parseDictSegmentsJSON = (data: JSONTranscript): Array<Segment> => {

/**
* Parse JSON data where top level item is a dict/object
*
* @param data The transcript data
* @returns An array of Segments from the parsed data
* @throws {TypeError} When JSON data does not match one of the valid formats
Expand All @@ -118,7 +115,6 @@ const parseDictJSON = (data: object): Array<Segment> => {

/**
* Convert {@link SubtitleSegment} to the {@link Segment} format used here
*
* @param data Segment parsed from JSON data
* @returns Segment representing `data`.
* Returns {@link undefined} when data does not match {@link SubtitleSegment} format.
Expand Down Expand Up @@ -151,7 +147,6 @@ const getSegmentFromSubtitle = (data: SubtitleSegment): Segment => {

/**
* Parse JSON data where items in data are in the {@link SubtitleSegment} format
*
* @param data Parsed JSON data
* @returns An array of Segments from the parsed data
* @throws {TypeError} When item in `data` does not match the {@link SubtitleSegment} format
Expand All @@ -178,7 +173,6 @@ const parseListJSONSubtitle = (data: Array<SubtitleSegment>): Array<Segment> =>

/**
* Parse JSON data where top level item is an Array
*
* @param data The transcript data
* @returns An array of Segments from the parsed data
* @throws {TypeError} When JSON data does not match one of the valid formats
Expand All @@ -202,7 +196,6 @@ const parseListJSON = (data: Array<unknown>): Array<Segment> => {

/**
* Parse JSON data to an Array of {@link Segment}
*
* @param data The transcript data
* @returns An array of Segments from the parsed data
* @throws {TypeError} When `data` is not valid JSON format
Expand Down
4 changes: 0 additions & 4 deletions src/formats/srt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type SRTSegment = {

/**
* Parse lines looking for data to be SRT format
*
* @param lines Lines containing SRT data
* @param indexOptional if true and index line does not exist, don't raise error. Return value will be -1.
* @returns Parsed segment
Expand Down Expand Up @@ -99,7 +98,6 @@ export const parseSRTSegment = (lines: Array<string>, indexOptional = false): SR

/**
* Create Segment from lines containing an SRT segment/cue
*
* @param segmentLines Lines containing SRT data
* @param lastSpeaker Name of last speaker. Will be used if no speaker found in `segmentLines`
* @param dataIsVTT the data is VTT formatted. Enables handling of minor differences between SRT and VTT
Expand All @@ -120,7 +118,6 @@ const createSegmentFromSRTLines = (segmentLines: Array<string>, lastSpeaker: str

/**
* Determines if the value of data is a valid SRT transcript format
*
* @param data The transcript data
* @param dataIsVTT the data is VTT formatted. Enables handling of minor differences between SRT and VTT
* @returns True: data is valid SRT transcript format
Expand All @@ -136,7 +133,6 @@ export const isSRT = (data: string, dataIsVTT = false): boolean => {

/**
* Parse SRT data to an Array of {@link Segment}
*
* @param data The transcript data
* @param dataIsVTT the data is VTT formatted. Enables handling of minor differences between SRT and VTT
* @returns An array of Segments from the parsed data
Expand Down
2 changes: 0 additions & 2 deletions src/formats/vtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const WEBVTT_HEADER = "WEBVTT"

/**
* Determines if the value of data is a valid VTT transcript format
*
* @param data The transcript data
* @returns True: data is valid VTT transcript format
*/
Expand All @@ -19,7 +18,6 @@ export const isVTT = (data: string): boolean => {

/**
* Parse VTT data to an Array of {@link Segment}
*
* @param data The transcript data
* @returns An array of Segments from the parsed data
* @throws {TypeError} When `data` is not valid VTT format
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export { Options, IOptions } from "./options"

/**
* Determines the format of transcript by inspecting the data
*
* @param data The transcript data
* @returns The determined transcript format
* @throws {TypeError} Cannot determine format of data or error parsing data
Expand Down Expand Up @@ -39,7 +38,6 @@ export const determineFormat = (data: string): TranscriptFormat => {

/**
* Convert the data to an Array of {@link Segment}
*
* @param data The transcript data
* @param transcriptFormat The format of the data.
* @returns An Array of Segment objects from the parsed data
Expand Down
5 changes: 0 additions & 5 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DEFAULT_COMBINE_SEGMENTS_LENGTH } from "./types"

/**
* Verifies the type of the value matches the expected type
*
* @param name name of option to check value for
* @param expectedType expected type off the value for the option
* @param value value to check
Expand Down Expand Up @@ -140,7 +139,6 @@ export class OptionsManager implements IOptions {

/**
* Get option value from it's name
*
* @param name name of option to get
* @returns value of option. If unknown, returns undefined
*/
Expand Down Expand Up @@ -173,7 +171,6 @@ export class OptionsManager implements IOptions {

/**
* Set option value using it's name
*
* @param name name of option to set
* @param value value to set option to
*/
Expand Down Expand Up @@ -227,7 +224,6 @@ export class OptionsManager implements IOptions {

/**
* Set one or more options
*
* @param options the options to set
* @param setDefault true: set all values to the default before setting values specified by `options`
*/
Expand All @@ -245,7 +241,6 @@ export class OptionsManager implements IOptions {

/**
* Helper to determine if at least one option should be applied
*
* @returns true: at least one option set
*/
public optionsSet = (): boolean => {
Expand Down
61 changes: 24 additions & 37 deletions src/segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const PATTERN_TRAILING_SPACE = /^ *$/

/**
* Remove any trailing space characters from data
*
* @param data text to trim
* @returns text with any trailing space character removed
*/
Expand All @@ -25,7 +24,6 @@ const trimEndSpace = (data: string): string => {
* Append `addition` to `body` with the character(s) specified.
*
* If `addition` matches the {@link PATTERN_PUNCTUATIONS} pattern, no character is added before the additional data.
*
* @param body Current body text
* @param addition Additional text to add to `body`
* @param separator Character(s) to use to separate data. If undefined, uses `\n`.
Expand All @@ -44,7 +42,6 @@ const joinBody = (body: string, addition: string, separator: string = undefined)

/**
* Combine one or more {@link Segment}
*
* @param segments Array of Segment objects to combine
* @param bodySeparator Character(s) to use to separate body data. If undefined, uses `\n`.
* @returns Combined segment where:
Expand Down Expand Up @@ -89,13 +86,12 @@ type CombineResult = {
* Checks if the new and prior segments have the same speaker.
*
* If so, combines segments where:
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from priorSegment
* - `body`: body of priorSegment with body of newSegment separated with space
*
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from priorSegment
* - `body`: body of priorSegment with body of newSegment separated with space
* @param newSegment segment being created
* @param priorSegment prior parsed segment
* @param lastSpeaker last speaker name.
Expand Down Expand Up @@ -123,13 +119,12 @@ const doCombineSpeaker = (newSegment: Segment, priorSegment: Segment, lastSpeake
* max length
*
* If so, combines segments where:
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from priorSegment
* - `body`: body of priorSegment with body of newSegment separated with space
*
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from priorSegment
* - `body`: body of priorSegment with body of newSegment separated with space
* @param newSegment segment being created
* @param priorSegment prior parsed segment
* @param maxLength maximum allowed length of combined body. If undefined, uses {@link DEFAULT_COMBINE_SEGMENTS_LENGTH}
Expand Down Expand Up @@ -175,13 +170,12 @@ const doCombineSegments = (
* Checks if the new and prior segments have the same speaker, startTime and endTime.
*
* If so, combines segments where:
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from priorSegment
* - `body`: body of priorSegment with body of newSegment separated with value of separator argument
*
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from priorSegment
* - `body`: body of priorSegment with body of newSegment separated with value of separator argument
* @param newSegment segment being created
* @param priorSegment prior parsed segment
* @param separator string to use to combine body values. If undefined, uses "\n"
Expand Down Expand Up @@ -220,13 +214,12 @@ const doCombineEqualTimes = (
* Checks if the new and prior segments have the same speaker. If so, sets the speaker value to undefined
*
* If so, combines segments where:
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from newSegment if different from priorSegment else undefined
* - `body`: body of priorSegment with body of newSegment separated with space
*
* - `startTime`: from priorSegment
* - `startTimeFormatted`: from priorSegment
* - `endTime`: from newSegment
* - `endTimeFormatted`: from newSegment
* - `speaker`: from newSegment if different from priorSegment else undefined
* - `body`: body of priorSegment with body of newSegment separated with space
* @param newSegment segment being created
* @param priorSegment prior parsed segment. For the first segment, this shall be undefined.
* @param lastSpeaker last speaker name.
Expand Down Expand Up @@ -279,7 +272,6 @@ const doSpeakerChange = (newSegment: Segment, priorSegment: Segment, lastSpeaker

/**
* Determine how {@link Options.speakerChange is applied based an past options being applied}
*
* @param currentResult current result object from any prior options
* @param priorSegment prior parsed segment
* @param lastSpeaker last speaker name.
Expand Down Expand Up @@ -317,7 +309,6 @@ const applyOptionsAndDoSpeakerChange = (
* Apply convert rules when no prior segment exits.
*
* NOTE: not all rules applicable when no prior segment
*
* @param newSegment segment before any rules options to it
* @param lastSpeaker last speaker name.
* Used when speaker in segment has been removed via {@link Options.speakerChange} rule
Expand All @@ -339,7 +330,6 @@ const doCombineNoPrior = (newSegment: Segment, lastSpeaker: string): CombineResu

/**
* Apply convert rules when prior segment exits.
*
* @param newSegment segment before any rules options to it
* @param priorSegment prior parsed segment
* @param lastSpeaker last speaker name.
Expand Down Expand Up @@ -397,7 +387,6 @@ const doCombineWithPrior = (newSegment: Segment, priorSegment: Segment, lastSpea

/**
* Apply any options to the current segment
*
* @param newSegment segment before any rules options to it
* @param priorSegment prior parsed segment. For the first segment, this shall be undefined.
* @param lastSpeaker last speaker name.
Expand Down Expand Up @@ -426,7 +415,6 @@ const applyOptions = (newSegment: Segment, priorSegment: Segment, lastSpeaker: s

/**
* Get the last speaker name from the previously parsed segments
*
* @param priorSegment prior parsed segment
* @param priorSegments array of all previous segments
* @returns the name of the last speaker
Expand All @@ -450,7 +438,6 @@ const getLastSpeaker = (priorSegment: Segment, priorSegments: Array<Segment>): s

/**
* Helper for adding segment to or updating last segment in array of segments
*
* @param newSegment segment to add or replace
* @param priorSegments array of all previous segments
* @returns updated array of segments with new segment added or last segment updated (per options)
Expand Down
1 change: 0 additions & 1 deletion src/speaker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const PATTERN_SPEAKER = /^(?<speaker>[a-z].+?): (?<body>.*)/i
* Attempt to extract the speaker's name from the data.
*
* Looks for the strings in the format matching {@link PATTERN_SPEAKER}
*
* @param data Data to get speaker from
* @returns The speaker (if found) and the remaining string
*/
Expand Down
Loading

0 comments on commit 5002442

Please sign in to comment.