changed string concatation process

This commit is contained in:
Shariar Shaikot
2018-01-19 20:11:20 +06:00
parent 5edba40781
commit 91683540bc
4 changed files with 21 additions and 6041 deletions

View File

@@ -11,6 +11,9 @@
]
}
],
"prefer-promise-reject-errors":[
"off"
],
"symbol-description": [
"off"
],

View File

@@ -6,25 +6,26 @@ class WebVTTConverter {
blobToBuffer() {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener('loadend', event => {
reader.addEventListener('loadend', (event) => {
const buf = event.target.result;
resolve(new Uint8Array(buf));
});
reader.addEventListener('error', () => reject('Error while reading the Blob object'));
reader.readAsArrayBuffer(this.resource)
reader.readAsArrayBuffer(this.resource);
});
}
toVTT(utf8str) {
static toVTT(utf8str) {
return utf8str
.replace(/\{\\([ibu])\}/g, '</$1>')
.replace(/\{\\([ibu])1\}/g, '<$1>')
.replace(/\{([ibu])\}/g, '<$1>')
.replace(/\{\/([ibu])\}/g, '</$1>')
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2') + '\r\n\r\n';
.replace(/\{\\([ibu])\}/g, '</$1>')
.replace(/\{\\([ibu])1\}/g, '<$1>')
.replace(/\{([ibu])\}/g, '<$1>')
.replace(/\{\/([ibu])\}/g, '</$1>')
.replace(/(\d\d:\d\d:\d\d),(\d\d\d)/g, '$1.$2')
.concat('\r\n\r\n');
}
toTypedArray(str) {
static toTypedArray(str) {
const result = [];
str.split().forEach((each, index) => {
result.push(parseInt(str.substring(index, index + 2), 16));
@@ -37,12 +38,12 @@ class WebVTTConverter {
if (!(this.resource instanceof Blob)) return reject('Expecting resource to be a Blob but something else found.');
if (!(FileReader)) return reject('No FileReader constructor found');
if (!TextDecoder) return reject('No TextDecoder constructor found');
this.blobToBuffer()
.then(buffer => {
const utf8str = new TextDecoder('utf-8').decode(buffer);
const vttString = 'WEBVTT FILE\r\n\r\n';
console.log(this.toTypedArray(vttString.concat(utf8str)));
});
WebVTTConverter.blobToBuffer()
.then((buffer) => {
const utf8str = new TextDecoder('utf-8').decode(buffer);
const vttString = 'WEBVTT FILE\r\n\r\n';
console.log(WebVTTConverter.toTypedArray(vttString.concat(utf8str)));
});
});
}
}

6025
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,8 @@
"description": "Convert SRT format subtitle to WebVTT on the fly over HTML5 environmentø",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server"
},
"repository": {
"type": "git",