Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The parse-unit npm package is used to parse CSS units from strings. It extracts the numeric value and the unit from a given string, making it useful for handling and manipulating CSS values programmatically.
Parse CSS Units
This feature allows you to parse a CSS unit string into its numeric value and unit. For example, '10px' would be parsed into 10 and 'px'.
const parseUnit = require('parse-unit');
const [value, unit] = parseUnit('10px');
console.log(value); // 10
console.log(unit); // 'px'
Handle Different Units
This feature demonstrates the ability to handle different types of units such as percentages. For example, '50%' would be parsed into 50 and '%'.
const parseUnit = require('parse-unit');
const [value, unit] = parseUnit('50%');
console.log(value); // 50
console.log(unit); // '%'
Default Unit Handling
This feature shows how the package handles strings without explicit units. For example, '100' would be parsed into 100 and an empty string.
const parseUnit = require('parse-unit');
const [value, unit] = parseUnit('100');
console.log(value); // 100
console.log(unit); // ''
The css-unit-converter package provides similar functionality by converting between different CSS units. It offers more advanced features like unit conversion, which parse-unit does not support.
The postcss-value-parser package is a more comprehensive tool for parsing CSS values. It can parse not only units but also functions, keywords, and more, making it more versatile than parse-unit.
The style-value-types package is part of the Popmotion library and provides utilities for parsing and manipulating CSS values. It offers a broader range of features, including color parsing and value interpolation, which are not available in parse-unit.
Parses a number and unit string, eg "20px"
into [20, "px"]
.
var unit = require('parse-unit')
//prints [50, "gold"]
console.log( unit("50 gold") )
parse(str[, out])
Parses the string and its unit, returning an array containing the number and unit, separated.
"-20 foo" => [-20, "foo"]
"5.5%" => [5.5, "%"]
5 => [5, ""]
"5" => [5, ""]
This will create a new array unless you specify an array to out
, which allows you to re-use arrays.
MIT, see LICENSE.md for details.
FAQs
parses number and unit, '20px' into [20, 'px']
The npm package parse-unit receives a total of 138,085 weekly downloads. As such, parse-unit popularity was classified as popular.
We found that parse-unit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.