dimension-parser

v0.0.21
parse dimensions out of strings

dimension-parser Build Status

parse dimensions out of strings

install

npm install dimension-parser

or

bower install dimension-parser

examples

var dimensionParser = require('dimension-parser');

dimensionParser('171.5 x 141.5 cm (67.5 x 55.75 in.)', 'in'); // returns {width: "67.50", height: "55.75"}

// or

dimensionParser('171.5 x 141.5 x 141.5 cm (67.5 x 55¾ x 55 3/4 in.)', 'in'); // returns {width: "67.50", height: "55.75", length: "55.75"}

// or you can test if a string contains dimensions

dimensionParser.hasDimensions('foobar'); // returns false

// you can also provide a format (the default is WxHxL)
dimensionParser('171.5 x 141.5 x 141.5 cm (67.5 x 55¾ x 55 3/4 in.)', 'in', 'HxWxL'); // returns {height: "67.50", width: "55.75", length: "55.75"}

// and you can also tell the parser to be more strict
dimensionParser('171.5 x 141.5 x 141.5 cm (67.5 x 55¾ x 55 3/4 in.)', 'in', 'HxWxL', true);
npm i dimension-parser

Metadata

  • MIT
  • Whatever
  • Chad Scira
  • released 6/8/2020

Downloads

Maintainers