Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ass-to-vtt

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ass-to-vtt - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

43

index.js

@@ -14,3 +14,5 @@ var split = require('split2')

var re_newline = /\\n/ig; // replace \N with newline
var re_newline = /\\N/g; // replace \N with newline
var re_softbreak = /\\n/g; // There's no equivalent function in WebVTT.
var re_hardspace = /\\h/g; // Replace with  
var re_style = /\{([^}]+)\}/; // replace style

@@ -25,2 +27,6 @@ var i = 1;

// Support for special characters in WebVTT.
// For obvious reasons, the ampersand one *must* be first.
text = text.replace( /&/g, "&amp;").replace( /</g, "&lt;").replace( />/g, "&gt;");
var style, pos_style = "", tagsToClose = []; // Places to stash style info.

@@ -34,6 +40,9 @@ // Subtitles may contain any number of override tags, so we'll loop through

for (var j = 1; j < style.length; j++) {
var firstLetter = style[j].substring(0,1);
// Extract the current tag name.
var tagCommand = style[j].match( /[a-zA-Z]+/ )[0];
// Give special reckognition to one-letter tags.
var oneLetter = ( tagCommand.length == 1 ) ? tagCommand : "";
// "New" position commands. It is assumed that bottom center position is the default.
if ( style[j].substring(0,2) === "an" ) {
if ( tagCommand === "an" ) {
var posNum = Number(style[j].substring(2,3));

@@ -51,3 +60,3 @@ if ( Math.floor((posNum-1)/3) == 1) {

// Legacy position commands.
} else if ( firstLetter === "a" && !Number.isNaN(Number(style[j].substring(1,2))) ) {
} else if ( oneLetter === "a" && !Number.isNaN(Number(style[j].substring(1,2))) ) {
var posNum = Number(style[j].substring(1,2));

@@ -66,6 +75,10 @@ if ( posNum > 8 ) {

// NOTE: Strikethrough (the 's' tag) is not supported in WebVTT.
} else if ( ['b', 'i', 'u', 's'].includes(firstLetter) ) {
if ( Number(style[j].substring(1,2)) === 0 ) {
} else if ( ['b', 'i', 'u', 's'].includes(oneLetter) ) {
if ( Number(style[j].substring(1,2)) === 0
// The more elaborate 'b-tag', which we will treat as an on-off selector.
|| ( style[j].match( /b\d{3}/ )
&& Number(style[j].match( /b(\d{3})/ )[1]) < 500 )
) {
// Closing a tag.
if ( tagsToClose.includes(firstLetter) ) {
if ( tagsToClose.includes(oneLetter) ) {
// Nothing needs to be done if this tag isn't already open.

@@ -78,3 +91,3 @@ // HTML tags must be nested, so we must ensure that any tag nested inside

replaceString += '</' + nowClosing + '>';
if ( nowClosing !== firstLetter ) {
if ( nowClosing !== oneLetter ) {
tagsToOpen.push(nowClosing);

@@ -90,8 +103,15 @@ } else {

// Opening a tag.
if ( !tagsToClose.includes( firstLetter ) ) {
if ( !tagsToClose.includes( oneLetter ) ) {
// Nothing needs to be done if the tag is already open.
// If no, place the tag on the bottom of the stack of tags being opened.
tagsToOpen.splice(0, 0, firstLetter);
tagsToOpen.splice(0, 0, oneLetter);
}
}
} else if (oneLetter === 'r') {
// Resetting override tags, by closing all open tags.
// TODO: The 'r' tag can also be used to switch to a different named style,
// however, named styles haven't been implemented.
while ( tagsToClose.length > 0) {
replaceString += '</' + tagsToClose.pop() + '>';
}
}

@@ -110,3 +130,4 @@

text = text.replace(re_newline, "\r\n");
text = text.replace(re_newline, "\r\n").replace(re_softbreak, " ").replace(
re_hardspace, "&nbsp;");
var content = i + "\r\n"

@@ -113,0 +134,0 @@ content += "0" + start + "0 --> 0" + end + "0" + pos_style + "\r\n"

{
"name": "ass-to-vtt",
"version": "1.1.1",
"version": "1.2.0",
"description": "Transform stream that converts ass files to vtt files (html5 video subtitles)",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc