dimensions-parser
v1.0.0-rc.1
Published
Parse dimensions stored in a string object
Downloads
1
Readme
dimensions-parser
What is this module?
A module to parse dimension strings into a format you can work with.
String formats include;
'L 10.1 x W 7.1 x H 5 inches'
'84.5cm(H) 55.3cm(W) 57.4cm(D)'
'L 1 x W 1 x H 1 inches'
'850 x 595 x 565 mm (H x W x D)'
'H143, W55, D58cm'
How to use
var dimensionParser = require('dimension-parser');
var dimension = '84.5cm(H) 55.3cm(W) 57.4cm(D)'
var dimensions = dimensionsParser.parse(dimension);
assert.equal(dimensions, {
height: {
type: 'height', units: 'cm', amount: 84.5
},
width: {
type: 'width', units: 'cm', amount: 55.3
},
depth: {
type: 'depth', units: 'cm', amount: 57.4
}
});
TODO
- [ ] Allow conversion to any format (Currently kicks out cm only)
- [ ] Add support for 2D dimensions
Contributing / I found a dimension that the module can't parse!
Please, at the very least, open an issue, stating the problem you are facing. I have provided an issue template to guide you.
Pull Requests are also appreciated. All existing tests must pass, and please add tests for your contribution.
Credits
I created this module whilst working for NearSt