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

amperize

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amperize - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

42

lib/amperize.js

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

, async = require('async')
, url = require('url')
, http = require('http')
, sizeOf = require('image-size')
, helpers = require('./helpers');

@@ -98,2 +101,17 @@

function enter(error) {
if (error) {
return done(error);
}
children = element.children;
html += helpers[element.type](element);
if (!children || !children.length) return close(null, html);
setImmediate(function delay() {
traverse.call(amperize, children, html, close);
});
}
if (element.name === 'img' && amperize.config.img) {

@@ -105,12 +123,22 @@ element.name = 'amp-img';

}
}
children = element.children;
html += helpers[element.type](element);
if ((!element.attribs.width || !element.attribs.height) && element.attribs.src.indexOf('http') === 0) {
var options = url.parse(element.attribs.src);
if (!children || !children.length) return close(null, html);
return http.get(options, function (response) {
var chunks = [];
setImmediate(function delay() {
traverse.call(amperize, children, html, close);
});
response.on('data', function (chunk) {
chunks.push(chunk);
}).on('end', function () {
var dimensions = sizeOf(Buffer.concat(chunks));
element.attribs.width = dimensions.width;
element.attribs.height = dimensions.height;
return enter();
});
});
}
}
return enter();
}, done);

@@ -117,0 +145,0 @@ };

3

package.json
{
"name": "amperize",
"version": "0.1.5",
"version": "0.2.0",
"description": "AMP up your plain HTML",

@@ -30,2 +30,3 @@ "main": "./lib/amperize",

"htmlparser2": "3.8.3",
"image-size": "0.3.5",
"lodash.merge": "3.3.2",

@@ -32,0 +33,0 @@ "node-uuid": "1.4.3"

@@ -68,4 +68,4 @@ 'use strict';

it('transforms <img> into <amp-img></amp-img>', function () {
amperize.parse('<img src="foo">', function (error, result) {
expect(result).to.be.equal('<amp-img src="foo" layout="responsive"></amp-img>');
amperize.parse('<img src="http://lorempixel.com/output/abstract-q-c-640-480-3.jpg">', function (error, result) {
expect(result).to.be.equal('<amp-img src="http://lorempixel.com/output/abstract-q-c-640-480-3.jpg" layout="responsive" width="640" height="480"></amp-img>');
});

@@ -72,0 +72,0 @@ });

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