|
| 1 | +# subkit |
| 2 | + |
| 3 | +## Install |
| 4 | + |
| 5 | +```shell |
| 6 | +npm i subkit |
| 7 | +``` |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +```ts |
| 12 | +import fs from "node:fs/promises"; |
| 13 | +import { dataToVtt, dataToFcpxml, srtToData, srtToFcpxml } from "subkit"; |
| 14 | + |
| 15 | +const srt = await fs.readFile("path/to/file.srt", "utf8"); |
| 16 | + |
| 17 | +// Convert SRT to data object |
| 18 | +const data = srtToData(srt); |
| 19 | + |
| 20 | +// Convert SRT data oject to any format |
| 21 | +const vtt = dataToVtt(data); |
| 22 | +const fcpxml = dataToFcpxml(data); |
| 23 | + |
| 24 | +// Convert SRT to FCPXML with convertion aliases |
| 25 | +const fcpxml_ = srtToFcpxml(srt); |
| 26 | +console.log(fcpxml === fcpxml_); |
| 27 | +// Output => true |
| 28 | +``` |
| 29 | + |
| 30 | +## API |
| 31 | + |
| 32 | +### SRT |
| 33 | + |
| 34 | +#### srtToData(text: string): SubSrt |
| 35 | + |
| 36 | +This converts SRT text content to a [`SubSrt`](./docs/types.md#subsrt) data object. |
| 37 | + |
| 38 | +#### dataToSrt(data: SubLike, separator?: Separator): string |
| 39 | + |
| 40 | +This accepts a [`SubLike`](./docs/types.md#sublike) data as input. The [`separator`](./docs/types.md#separator) is used for timestamp strings and it defaults to `,`. |
| 41 | + |
| 42 | +### WebVTT |
| 43 | + |
| 44 | +#### vttToData(text: string): SubVtt |
| 45 | + |
| 46 | +This converts WebVTT text content to a [`SubVtt`](./docs/types.md#subvtt) data object. |
| 47 | + |
| 48 | +#### dataToVtt(data: SubLike, separator?: Separator): string; |
| 49 | + |
| 50 | +This accepts a [`SubLike`](./docs/types.md#sublike) data as input. The [`separator`](./docs/types.md#separator) is used for timestamp strings and it defaults to `.`. |
| 51 | + |
| 52 | +### FCPXML |
| 53 | + |
| 54 | +#### fcpxmlToData(text: string): SubFcpxmlv |
| 55 | + |
| 56 | +This converts FCPXML text context to a [`SubFcpxml`](./docs/types.md#subfcpxml) data object. |
| 57 | + |
| 58 | +#### dataToFcpxml(data: SubLike, fps: number, options?: DataToFcpxmlOptions): string |
| 59 | + |
| 60 | +This accepts a [`SubLike`](./docs/types.md#sublike) and `fps` as input. And some fields can be configured by using [`DataToFcpxmlOptions`](./docs/types.md#datatofcpxmloptions). |
| 61 | + |
| 62 | +### Convertions |
| 63 | + |
| 64 | +We've defined some convertion aliases for converting between two subs. Available convertion aliaes are: |
| 65 | + |
| 66 | +- `srtToVtt(text: string, separator?: Separator)` |
| 67 | +- `vttToSrt(text: string, separator?: Separator)` |
| 68 | +- `fcpxmlToSrt(text: string, separator?: Separator)` |
| 69 | +- `fcpxmlToVtt(text: string, separator?: Separator)` |
| 70 | +- `srtToFcpxml(text: string, fps: number, options?: DataToFcpxmlOptions)` |
| 71 | +- `vttToFcpxml(text: string, fps: number, optiosn?: DataToFcpxmlOptions)` |
| 72 | + |
| 73 | +### Utilities |
| 74 | + |
| 75 | +#### msToTime(ms: string, separator?: Separator): string |
| 76 | + |
| 77 | +This converts the milliseconds to time string for SRT or VTT. |
| 78 | + |
| 79 | +#### timeToMs(time: string): number |
| 80 | + |
| 81 | +This converts the SRT or VTT time string to milliseconds. |
| 82 | + |
| 83 | +## License |
| 84 | + |
| 85 | +MIT |
0 commit comments