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

@hashicorp/hashi-image

Package Overview
Dependencies
Maintainers
13
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hashicorp/hashi-image - npm Package Compare versions

Comparing version 1.0.6 to 2.0.0-alpha.0

57

dist/index.js

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

var preact = require('preact');
var React = _interopDefault(require('react'));
var queryString = _interopDefault(require('query-string'));

@@ -15,13 +15,12 @@ var assign = _interopDefault(require('object-assign'));

_ref$steps = _ref.steps,
steps = _ref$steps === undefined ? [250, 500, 750, 1000, 1500, 2000, 2500] : _ref$steps,
steps = _ref$steps === void 0 ? [250, 500, 750, 1000, 1500, 2000, 2500] : _ref$steps,
_ref$sizes = _ref.sizes,
sizes = _ref$sizes === undefined ? '100vw' : _ref$sizes,
sizes = _ref$sizes === void 0 ? '100vw' : _ref$sizes,
_ref$svg = _ref.svg,
svg = _ref$svg === undefined ? false : _ref$svg,
svg = _ref$svg === void 0 ? false : _ref$svg,
classes = _ref.classes,
aspect_ratio = _ref.aspect_ratio,
_ref$params = _ref.params,
params = _ref$params === undefined ? {} : _ref$params,
params = _ref$params === void 0 ? {} : _ref$params,
alt = _ref.alt;
// set default params, merge user preferences with priority

@@ -32,7 +31,5 @@ var opts = assign({

q: 80
}, params);
}, params); // handle aspect ratios & steps passed as a string
// handle aspect ratios & steps passed as a string
aspect_ratio = typeof aspect_ratio === 'string' ? aspect_ratio.split(',').map(Number) : aspect_ratio;
steps = typeof steps === 'string' ? steps.split(',').map(Number) : steps;

@@ -42,3 +39,7 @@

// if it's an SVG, we don't need the picture element, so return
return preact.h('img', { 'class': classes, src: src, alt: alt });
return React.createElement("img", {
className: classes,
src: src,
alt: alt
});
} else {

@@ -48,25 +49,23 @@ // otherwise, we return a picture element with multiple sizes and a webp

var srcDefault = formatSteps(steps, opts, aspect_ratio, src);
var srcWebp = formatSteps(steps, assign({}, opts, { fm: 'webp' }), aspect_ratio, src);
return preact.h(
'picture',
null,
preact.h('source', { type: 'image/webp', srcSet: srcWebp, sizes: sizes }),
preact.h('img', {
'class': classes,
src: format(src, opts, aspect_ratio && aspect_ratio[2], aspect_ratio),
srcSet: srcDefault,
sizes: sizes,
alt: alt
})
);
var srcWebp = formatSteps(steps, assign({}, opts, {
fm: 'webp'
}), aspect_ratio, src);
return React.createElement("picture", null, React.createElement("source", {
type: "image/webp",
srcSet: srcWebp,
sizes: sizes
}), React.createElement("img", {
className: classes,
src: format(src, opts, aspect_ratio && aspect_ratio[2], aspect_ratio),
srcSet: srcDefault,
sizes: sizes,
alt: alt
}));
}
}
function formatSteps(steps, opts, aspect_ratio, src) {
return steps.map(function (s) {
return format(src, opts, s, aspect_ratio) + ' ' + s + 'w';
return "".concat(format(src, opts, s, aspect_ratio), " ").concat(s, "w");
});
}
function format(src, opts, width, aspect_ratio) {

@@ -76,7 +75,7 @@ var opt = assign({}, opts);

if (width && aspect_ratio) opt.h = aspect_ratio[1] / aspect_ratio[0] * width;
return src + '?' + queryString.stringify(opt);
return "".concat(src, "?").concat(queryString.stringify(opt));
}
exports.default = Image;
exports.format = format;
exports.formatSteps = formatSteps;
exports.format = format;
{
"name": "@hashicorp/hashi-image",
"description": "super optimized image element, pulls from dato and formats for 7 screen sizes in two formats. Skips optimization for SVGs.",
"version": "1.0.6",
"version": "2.0.0-alpha.0",
"author": "Hashicorp - Jeff Escalante",
"main": "dist",
"peerDependencies": {
"dependencies": {
"object-assign": "^4.1.1",
"preact": "^8.2.7",
"query-string": "^5.1.1"
"query-string": "^6.4.2",
"react": "^16.8.6"
},
"main": "dist",
"publishConfig": {

@@ -18,3 +18,3 @@ "access": "public"

},
"gitHead": "78236aa1b7f3adda5e4e3dd1d1ba8f084e1c24dc"
"gitHead": "5f9b5a0487251e5846a3eabd9ff839d3fe7e1e31"
}
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