Latest updates from IceHrmPro
This commit is contained in:
51
web/node_modules/json2mq/index.js
generated
vendored
Normal file
51
web/node_modules/json2mq/index.js
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
var camel2hyphen = require('string-convert/camel2hyphen');
|
||||
|
||||
var isDimension = function (feature) {
|
||||
var re = /[height|width]$/;
|
||||
return re.test(feature);
|
||||
};
|
||||
|
||||
var obj2mq = function (obj) {
|
||||
var mq = '';
|
||||
var features = Object.keys(obj);
|
||||
features.forEach(function (feature, index) {
|
||||
var value = obj[feature];
|
||||
feature = camel2hyphen(feature);
|
||||
// Add px to dimension features
|
||||
if (isDimension(feature) && typeof value === 'number') {
|
||||
value = value + 'px';
|
||||
}
|
||||
if (value === true) {
|
||||
mq += feature;
|
||||
} else if (value === false) {
|
||||
mq += 'not ' + feature;
|
||||
} else {
|
||||
mq += '(' + feature + ': ' + value + ')';
|
||||
}
|
||||
if (index < features.length-1) {
|
||||
mq += ' and '
|
||||
}
|
||||
});
|
||||
return mq;
|
||||
};
|
||||
|
||||
var json2mq = function (query) {
|
||||
var mq = '';
|
||||
if (typeof query === 'string') {
|
||||
return query;
|
||||
}
|
||||
// Handling array of media queries
|
||||
if (query instanceof Array) {
|
||||
query.forEach(function (q, index) {
|
||||
mq += obj2mq(q);
|
||||
if (index < query.length-1) {
|
||||
mq += ', '
|
||||
}
|
||||
});
|
||||
return mq;
|
||||
}
|
||||
// Handling single media query
|
||||
return obj2mq(query);
|
||||
};
|
||||
|
||||
module.exports = json2mq;
|
||||
Reference in New Issue
Block a user