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

parseunit

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parseunit

Parse strings with a number and unit

  • 0.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

parseunit

Travis npm David David

Parse strings with a number and unit.

API

ES5

var parse = require('parseunit');
var parsed = parse('12px');
console.log(parsed[0], parsed[1]); // 12 'px'

// or parse into an object for better readability
var parseObj = parse.parseObj;
var parsed = parseObj('12px');
console.log(parsed.val, parsed.unit); // 12 'px'

ES6

import parseUnit, {parseUnitObj} from 'parseunit';

const [val, unit] = parseUnit('12px');
// or
const {val, unit} = parseUnitObj('12px');

console.log(val, unit); // 12 'px'

parseUnit

Default export

Params

  • str string

Returns

  • [val, unit] [number, string]

parseUnitObj

Params

  • str string

Returns

  • {val, unit} {number, string}

Alternatives

parse-unit

Keywords

FAQs

Package last updated on 01 Nov 2015

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