New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

calculate-size

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculate-size - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

87

lib/index.js

@@ -1,51 +0,42 @@

(function (dependencies, factory) {
if (typeof module === 'object' && typeof module.exports === 'object') {
var v = factory(require, exports); if (v !== undefined) module.exports = v;
"use strict";
function createDummyElement(text, options) {
var element = document.createElement('div');
var textNode = document.createTextNode(text);
element.appendChild(textNode);
element.style.fontFamily = options.font;
element.style.fontSize = options.fontSize;
element.style.fontWeight = options.fontWeight;
element.style.position = 'absolute';
element.style.visibility = 'hidden';
element.style.left = '-999px';
element.style.top = '-999px';
element.style.width = options.width;
element.style.height = 'auto';
document.body.appendChild(element);
return element;
}
function destroyElement(element) {
element.parentNode.removeChild(element);
}
var cache = {};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = function (text, options) {
if (options === void 0) { options = {}; }
var cacheKey = JSON.stringify({ text: text, options: options });
if (cache[cacheKey]) {
return cache[cacheKey];
}
else if (typeof define === 'function' && define.amd) {
define(dependencies, factory);
}
})(["require", "exports"], function (require, exports) {
"use strict";
function createDummyElement(text, options) {
var element = document.createElement('div');
var textNode = document.createTextNode(text);
element.appendChild(textNode);
element.style.fontFamily = options.font;
element.style.fontSize = options.fontSize;
element.style.fontWeight = options.fontWeight;
element.style.position = 'absolute';
element.style.visibility = 'hidden';
element.style.left = '-999px';
element.style.top = '-999px';
element.style.width = options.width;
element.style.height = 'auto';
document.body.appendChild(element);
return element;
}
function destroyElement(element) {
element.parentNode.removeChild(element);
}
var cache = {};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = function (text, options) {
if (options === void 0) { options = {}; }
var cacheKey = JSON.stringify({ text: text, options: options });
if (cache[cacheKey]) {
return cache[cacheKey];
}
options.font = options.font || 'Times';
options.fontSize = options.fontSize || '16px';
options.fontWeight = options.fontWeight || 'normal';
options.width = options.width || 'auto';
var element = createDummyElement(text, options);
var size = {
width: element.offsetWidth,
height: element.offsetHeight,
};
destroyElement(element);
cache[cacheKey] = size;
return size;
options.font = options.font || 'Times';
options.fontSize = options.fontSize || '16px';
options.fontWeight = options.fontWeight || 'normal';
options.width = options.width || 'auto';
var element = createDummyElement(text, options);
var size = {
width: element.offsetWidth,
height: element.offsetHeight,
};
});
destroyElement(element);
cache[cacheKey] = size;
return size;
};
//# sourceMappingURL=index.js.map
{
"name": "calculate-size",
"version": "1.1.0",
"version": "1.1.1",
"description": "Calculate the pixel size of a string",

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

@@ -22,4 +22,11 @@ calculate-size [![Build Status](https://travis-ci.org/schickling/calculate-size.svg?branch=master)](https://travis-ci.org/schickling/calculate-size) [![npm version](https://badge.fury.io/js/calculate-size.svg)](https://badge.fury.io/js/calculate-size)

### Options
* `font: string`
* `fontSize: string`
* `fontWeight: string`
* `width: string` (Constraint width by a fixed value to calc height)
console.log(size.width) // 140
console.log(size.height) // 20
```

Sorry, the diff of this file is not supported yet

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