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

minimize

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minimize - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

45

lib/helpers.js
'use strict';
function tag (element) {
return '<' + element.data + '>';
var flow = /<\/[^>]+>$|\w+$/
, inline = [
'b', 'big', 'i', 'small', 'tt', 'abbr', 'acronym', 'cite', 'code', 'dfn'
, 'em', 'kbd', 'strong', 'samp', 'var', 'a', 'bdo', 'br', 'img', 'map'
, 'object', 'q', 'script', 'span', 'sub', 'sup', 'button', 'input', 'label'
, 'select', 'textarea'
];
function isInline (element) {
return !!~inline.indexOf(element.name);
}
function tag (element, ancestor, data) {
return (isInline(element) && data.match(flow) ? ' <' : '<') + element.data + '>';
}
function close (element) {

@@ -18,3 +30,3 @@ return element.type === 'tag' || element.type === 'script'

function requiresFlow(element) {
function structure(element) {
return element.type !== 'text'

@@ -25,8 +37,10 @@ ? element.name.match(/pre|textarea/) || isJS(element)

function text (element, parent) {
element = element.data;
function text (element, ancestor, data) {
element = element.data.trim();
if (!requiresFlow(parent)) element = element.replace(/\n/, '').replace(/\s+/g, ' ');
if (!structure(ancestor)) element = element.replace(/\n/, '').replace(/\s+/g, ' ');
return element.trim();
if (data.match(flow)) element = ' ' + element;
return element;
}

@@ -36,8 +50,6 @@

close: close
, map: {
directive: tag
, tag: tag
, text: text
, script: tag
}
, directive: tag
, tag: tag
, text: text
, script: tag
};

@@ -50,5 +62,6 @@

module.exports.tag = tag;
module.exports.text = text;
module.exports.text = isJS;
module.exports.text = requiresFlow;
module.exports.isJS = isJS;
module.exports.structure = structure;
module.exports.isInline = isInline;
module.exports.flow = flow;
}

@@ -8,3 +8,3 @@ 'use strict';

, htmlparser
, previous;
, ancestor;

@@ -30,5 +30,7 @@ /**

function walk (data, element) {
data += helpers.map[element.type](element, previous);
previous = element;
data += helpers[element.type](element, ancestor, data);
// Store reference to ancestor.
if (element.children) ancestor = element;
return (element.children

@@ -35,0 +37,0 @@ ? traverse(element.children, data)

{
"name": "minimize",
"version": "0.0.5",
"version": "0.0.6",
"description": "Minimize HTML",

@@ -5,0 +5,0 @@ "main": "./lib/minimize",

@@ -27,2 +27,10 @@ 'use strict';

});
describe('prepends a space if the element', function () {
it('is inline and prepended by text', function () {
});
it('is inlnie and prepended by closing tag', function () {
});
});
});

@@ -55,3 +63,3 @@

describe('function requiresFlow', function () {
describe('function structure', function () {
it('returns false if element is text', function () {

@@ -66,2 +74,35 @@ });

});
describe('function text', function () {
it('trims whitespace', function () {
});
it('replaces whitelines and spaces in non structural elements', function () {
});
it('retains structure if element requires structure', function () {
});
it('prepends space if the text is prepended with closing tag', function () {
});
});
describe('inline element list', function () {
it('is an array', function () {
});
it('has all required elements', function () {
});
});
describe('regular expression flow', function () {
it('is a valid regular expression', function () {
});
it('can detect if last part of string is closing tag', function () {
});
it('can detect if last part of string is text', function () {
});
});
});
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