Skip to content

Commit ccfea95

Browse files
authored
Move hash function into utils (#6503)
1 parent aed1b4b commit ccfea95

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

src/types/general.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/utils/hash.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// From https://github.com/darkskyapp/string-hash
2+
export function hash(text: string) {
3+
let hash = 5381;
4+
let i = text.length;
5+
while (i) {
6+
hash = (hash * 33) ^ text.charCodeAt(--i);
7+
}
8+
9+
return (hash >>> 0).toString();
10+
}

src/utils/webvtt-parser.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { VTTParser } from './vttparser';
22
import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr';
3+
import { hash } from './hash';
34
import {
45
RationalTimestamp,
56
toMpegTsClockFromTimescale,
@@ -45,17 +46,6 @@ const cueString2millis = function (timeString: string) {
4546
return ts;
4647
};
4748

48-
// From https://github.com/darkskyapp/string-hash
49-
const hash = function (text: string) {
50-
let hash = 5381;
51-
let i = text.length;
52-
while (i) {
53-
hash = (hash * 33) ^ text.charCodeAt(--i);
54-
}
55-
56-
return (hash >>> 0).toString();
57-
};
58-
5949
// Create a unique hash id for a cue based on start/end times and text.
6050
// This helps timeline-controller to avoid showing repeated captions.
6151
export function generateCueId(

0 commit comments

Comments
 (0)