mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
497a74beb0
closes #5815 - replaces isNaN function call with isFinite in config service - adds config service unit test
44 lines
994 B
JavaScript
44 lines
994 B
JavaScript
import Ember from 'ember';
|
|
|
|
function isNumeric(num) {
|
|
return Ember.$.isNumeric(num);
|
|
}
|
|
|
|
function _mapType(val) {
|
|
if (val === '') {
|
|
return null;
|
|
} else if (val === 'true') {
|
|
return true;
|
|
} else if (val === 'false') {
|
|
return false;
|
|
} else if (isNumeric(val)) {
|
|
return +val;
|
|
} else if (val.indexOf('{') === 0) {
|
|
try {
|
|
return JSON.parse(val);
|
|
} catch (e) {
|
|
/*jshint unused:false */
|
|
return val;
|
|
}
|
|
} else {
|
|
return val;
|
|
}
|
|
}
|
|
|
|
export default Ember.Service.extend(Ember._ProxyMixin, {
|
|
content: Ember.computed(function () {
|
|
var metaConfigTags = Ember.$('meta[name^="env-"]'),
|
|
config = {};
|
|
|
|
metaConfigTags.each(function (i, el) {
|
|
var key = el.name,
|
|
value = el.content,
|
|
propertyName = key.substring(4);
|
|
|
|
config[propertyName] = _mapType(value);
|
|
});
|
|
|
|
return config;
|
|
})
|
|
});
|