-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wtb.js
54 lines (49 loc) · 1.21 KB
/
wtb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/** @preserve npm.im/wtb */
!function() {
var free
var api = wtb
var dimension = /[\deE.]+/g
var match = "".match
var slice = [].slice
var area = "area"
var aspect = "aspect"
var height = "height"
var width = "width"
var own = {}.hasOwnProperty
function get(safe, o, k) {
var v = safe || own.call(o, k) ? o[k] : free
return typeof v == "function" ? v.call(o) : v
}
function wtb(given) {
var gob = given instanceof Object
var sob = typeof given == "object" != gob
var num = sob && given ? NaN : +given
var met = num === num || !given
? [num]
: given.match === match
? given.match(dimension)
: given instanceof Array
? slice.call(given)
: [
get(!gob, given, width),
get(!gob, given, height)
]
var h = met && met.pop()
var w = met && met.pop()
h = h || h != 0 && w
w = w || w != 0 && h
h = +h || 0
w = +w || 0
h = h < 0 ? -h : h
w = w < 0 ? -w : w
var b = this instanceof wtb ? this : new wtb
b[area] = w * h
b[aspect] = w == h ? 1 : w / h
b[height] = h
b[width] = w
return b
}
typeof module != "undefined" && module.exports
? module.exports = api
: this[api.name] = api
}();