postcss-convert-values
Advanced tools
Comparing version 5.0.4 to 5.1.0
{ | ||
"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 : ''); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
13107
7
280
0