+20
-7
@@ -19,13 +19,25 @@ 'use strict' | ||
| } | ||
| else if (typeof arg === 'number') { | ||
| arg = [arg] | ||
| } | ||
| // 0, 0, 100, 100 - array-like | ||
| if (arg.length && typeof arg[0] === 'number') { | ||
| if (arg.length === 2) { | ||
| // [w, w] | ||
| if (arg.length === 1) { | ||
| rect = { | ||
| width: arg[0], | ||
| height: arg[0], | ||
| x: 0, y: 0 | ||
| } | ||
| } | ||
| // [w, h] | ||
| else if (arg.length === 2) { | ||
| rect = { | ||
| width: arg[0], | ||
| height: arg[1], | ||
| x: 0, | ||
| y: 0 | ||
| x: 0, y: 0 | ||
| } | ||
| } | ||
| // [l, t, r, b] | ||
| else { | ||
@@ -40,2 +52,3 @@ rect = { | ||
| } | ||
| // {x, y, w, h} or {l, t, b, r} | ||
| else if (arg) { | ||
@@ -45,6 +58,6 @@ arg = pick(arg, { | ||
| top: 'y t top Top', | ||
| width: 'w width', | ||
| height: 'h height', | ||
| bottom: 'b bottom', | ||
| right: 'r right' | ||
| width: 'w width W Width', | ||
| height: 'h height W Width', | ||
| bottom: 'b bottom Bottom', | ||
| right: 'r right Right' | ||
| }) | ||
@@ -51,0 +64,0 @@ |
+1
-1
| { | ||
| "name": "parse-rect", | ||
| "version": "1.1.1", | ||
| "version": "1.2.0", | ||
| "description": "Parse any input rectangle format", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+4
-0
@@ -22,2 +22,6 @@ # parse-rect [](http://github.com/badges/stability-badges) [](https://travis-ci.org/dfcreative/parse-rect) | ||
| parseRect([ 90, 80 ]) | ||
| // {x: 0, y: 0, width: 90, height: 90} | ||
| parseRect(90) | ||
| parseRect([90]) | ||
| ``` | ||
@@ -24,0 +28,0 @@ |
+2
-0
@@ -19,1 +19,3 @@ 'use strict' | ||
| assert.deepEqual(parseRect([10, 20]), {width: 10, height: 20, x: 0, y: 0}) | ||
| assert.deepEqual(parseRect(10), {width: 10, height: 10, x: 0, y: 0}) | ||
| assert.deepEqual(parseRect([10]), {width: 10, height: 10, x: 0, y: 0}) |
6515
8.64%135
12.5%31
14.81%