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

postcss-convert-values

Package Overview
Dependencies
Maintainers
8
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-convert-values - npm Package Compare versions

Comparing version 5.0.4 to 5.1.0

types/index.d.ts

6

package.json
{
"name": "postcss-convert-values",
"version": "5.0.4",
"version": "5.1.0",
"description": "Convert values with PostCSS (e.g. ms -> s)",
"main": "src/index.js",
"types": "types/index.d.ts",
"files": [
"LICENSE-MIT",
"src"
"src",
"types"
],

@@ -10,0 +12,0 @@ "keywords": [

'use strict';
const valueParser = require('postcss-value-parser');
const convert = require('./lib/convert');
const convert = require('./lib/convert.js');

@@ -39,6 +39,9 @@ const LENGTH_UNITS = new Set([

/*
/**
* Numbers without digits after the dot are technically invalid,
* but in that case css-value-parser returns the dot as part of the unit,
* so we use this to remove the dot.
*
* @param {string} item
* @return {string}
*/

@@ -53,2 +56,8 @@ function stripLeadingDot(item) {

/**
* @param {valueParser.Node} node
* @param {Options} opts
* @param {boolean} keepZeroUnit
* @return {void}
*/
function parseWord(node, opts, keepZeroUnit) {

@@ -81,2 +90,6 @@ const pair = valueParser.unit(node.value);

/**
* @param {valueParser.WordNode} node
* @return {void}
*/
function clampOpacity(node) {

@@ -95,2 +108,6 @@ const pair = valueParser.unit(node.value);

/**
* @param {import('postcss').Declaration} decl
* @return {boolean}
*/
function shouldKeepZeroUnit(decl) {

@@ -102,5 +119,8 @@ const { parent } = decl;

(lowerCasedProp === 'max-height' || lowerCasedProp === 'height')) ||
(parent.parent &&
parent.parent.name &&
parent.parent.name.toLowerCase() === 'keyframes' &&
(parent &&
parent.parent &&
parent.parent.type === 'atrule' &&
/** @type {import('postcss').AtRule} */ (
parent.parent
).name.toLowerCase() === 'keyframes' &&
lowerCasedProp === 'stroke-dasharray') ||

@@ -110,3 +130,7 @@ keepWhenZero.has(lowerCasedProp)

}
/**
* @param {Options} opts
* @param {import('postcss').Declaration} decl
* @return {void}
*/
function transform(opts, decl) {

@@ -159,3 +183,9 @@ const lowerCasedProp = decl.prop.toLowerCase();

const plugin = 'postcss-convert-values';
/**
* @typedef {{precision: boolean | number, angle?: boolean, time?: boolean, length?: boolean}} Options */
/**
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} opts
* @return {import('postcss').Plugin}
*/
function pluginCreator(opts = { precision: false }) {

@@ -162,0 +192,0 @@ return {

@@ -18,3 +18,6 @@ 'use strict';

]);
/**
* @param {number} number
* @return {string}
*/
function dropLeadingZero(number) {

@@ -35,3 +38,8 @@ const value = String(number);

}
/**
* @param {number} number
* @param {string} originalUnit
* @param {Map<string, number>} conversions
* @return {string}
*/
function transform(number, originalUnit, conversions) {

@@ -42,9 +50,18 @@ let conversionUnits = [...conversions.keys()].filter((u) => {

const base = number * conversions.get(originalUnit);
const base = number * /** @type {number} */ (conversions.get(originalUnit));
return conversionUnits
.map((u) => dropLeadingZero(base / conversions.get(u)) + u)
.map(
(u) =>
dropLeadingZero(base / /** @type {number} */ (conversions.get(u))) + u
)
.reduce((a, b) => (a.length < b.length ? a : b));
}
/**
* @param {number} number
* @param {string} unit
* @param {{time?: boolean, length?: boolean, angle?: boolean}} options
* @return {string}
*/
module.exports = function (number, unit, { time, length, angle }) {

@@ -51,0 +68,0 @@ let value = dropLeadingZero(number) + (unit ? unit : '');

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