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

parse-unit

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-unit

parses number and unit, '20px' into [20, 'px']

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
181K
decreased by-18.01%
Maintainers
1
Weekly downloads
 
Created

What is parse-unit?

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.

What are parse-unit's main functionalities?

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); // ''

Other packages similar to parse-unit

Keywords

FAQs

Package last updated on 22 Sep 2014

Did you know?

Socket

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.

Install

Related posts

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