Skip to content

Commit

Permalink
Move hash function into utils (#6503)
Browse files Browse the repository at this point in the history
  • Loading branch information
robwalch authored Jun 14, 2024
1 parent aed1b4b commit ccfea95
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
6 changes: 0 additions & 6 deletions src/types/general.ts

This file was deleted.

10 changes: 10 additions & 0 deletions src/utils/hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// From https://github.com/darkskyapp/string-hash
export function hash(text: string) {
let hash = 5381;
let i = text.length;
while (i) {
hash = (hash * 33) ^ text.charCodeAt(--i);
}

return (hash >>> 0).toString();
}
12 changes: 1 addition & 11 deletions src/utils/webvtt-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VTTParser } from './vttparser';
import { utf8ArrayToStr } from '@svta/common-media-library/utils/utf8ArrayToStr';
import { hash } from './hash';
import {
RationalTimestamp,
toMpegTsClockFromTimescale,
Expand Down Expand Up @@ -45,17 +46,6 @@ const cueString2millis = function (timeString: string) {
return ts;
};

// From https://github.com/darkskyapp/string-hash
const hash = function (text: string) {
let hash = 5381;
let i = text.length;
while (i) {
hash = (hash * 33) ^ text.charCodeAt(--i);
}

return (hash >>> 0).toString();
};

// Create a unique hash id for a cue based on start/end times and text.
// This helps timeline-controller to avoid showing repeated captions.
export function generateCueId(
Expand Down

0 comments on commit ccfea95

Please sign in to comment.