Skip to content

Commit c6975ba

Browse files
committed
Initial commit
0 parents  commit c6975ba

25 files changed

Lines changed: 1422 additions & 0 deletions

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
end_of_line = lf
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.yml]
11+
indent_style = space
12+
indent_size = 2

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: LitoMore

.github/workflows/main.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: CI
2+
on:
3+
- push
4+
- pull_request
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-node@v4
11+
with:
12+
node-version: 22
13+
- run: npm install
14+
- run: npm run build
15+
- run: npm test

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_moduels
2+
distribution
3+
coverage

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.xo-config.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"prettier": true,
3+
"plugins": ["import"],
4+
"rules": {
5+
"sort-imports": [
6+
"error",
7+
{
8+
"ignoreCase": false,
9+
"ignoreDeclarationSort": true,
10+
"ignoreMemberSort": false,
11+
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
12+
"allowSeparatedGroups": false
13+
}
14+
],
15+
"import/no-named-as-default": "off",
16+
"import/extensions": "off",
17+
"import/order": [
18+
"error",
19+
{
20+
"groups": ["builtin", "external", "parent", "sibling", "index"],
21+
"alphabetize": {
22+
"order": "asc",
23+
"caseInsensitive": true
24+
},
25+
"warnOnUnassignedImports": true,
26+
"newlines-between": "never"
27+
}
28+
],
29+
"@typescript-eslint/consistent-type-imports": [
30+
"error",
31+
{
32+
"prefer": "no-type-imports"
33+
}
34+
]
35+
},
36+
"overrides": [
37+
{
38+
"files": ["*.js"],
39+
"rules": {
40+
"@typescript-eslint/consistent-type-imports": "off"
41+
}
42+
}
43+
]
44+
}

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) LitoMore
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

ava.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const ava = {
2+
typescript: {
3+
compile: false,
4+
rewritePaths: {
5+
'source/': 'distribution/',
6+
'test/': 'distribution/test/',
7+
},
8+
},
9+
};
10+
11+
export default ava;

docs/types.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Types
2+
3+
## Separator
4+
5+
```ts
6+
type Separator = "." | ",";
7+
```
8+
9+
## SubLike
10+
11+
```ts
12+
type SubLike = SubSrt | SubVtt | SubFcpxml;
13+
```
14+
15+
## SubSrt
16+
17+
```ts
18+
type SubSrt = {
19+
items: Array<{
20+
from: number;
21+
to: number;
22+
duration: number;
23+
text: string;
24+
}>;
25+
};
26+
```
27+
28+
## SubVtt
29+
30+
```ts
31+
type SubVtt = {
32+
items: Array<{
33+
from: number;
34+
to: number;
35+
duration: number;
36+
text: string;
37+
}>;
38+
};
39+
```
40+
41+
## SubFcpxml
42+
43+
```ts
44+
type SubFcpxml = {
45+
name: string;
46+
fps: number;
47+
gapDuration: string;
48+
sequenceDuration: string;
49+
items: Array<{
50+
text: string;
51+
from: number;
52+
to: number;
53+
duration: number;
54+
font: string;
55+
fontSize: string;
56+
fontFace: string;
57+
fontColor: string;
58+
bold: string;
59+
shadowColor: string;
60+
shadowOffset: string;
61+
alignment: string;
62+
titleOffset: string;
63+
titleDuration: string;
64+
}>;
65+
};
66+
```
67+
68+
## DataToFcpxmlOptions
69+
70+
```ts
71+
export type DataToFcpxmlOptions = {
72+
name?: string;
73+
font?: string;
74+
fontSize?: string;
75+
fontFace?: string;
76+
fontColor?: string;
77+
bold?: string;
78+
shadowColor?: string;
79+
shadowOffset?: string;
80+
alignment?: string;
81+
};
82+
```

0 commit comments

Comments
 (0)