mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { Config } from '../index';
|
|
import { PlatformConfig } from './platform-configs';
|
|
|
|
|
|
export function createConfigController(configObj: any, platforms: PlatformConfig[]): Config {
|
|
configObj = configObj || {};
|
|
|
|
function get(key: string, fallback?: any): any {
|
|
if (configObj[key] !== undefined) {
|
|
return configObj[key];
|
|
}
|
|
|
|
let settings: any = null;
|
|
|
|
for (let i = 0; i < platforms.length; i++) {
|
|
settings = platforms[i]['settings'];
|
|
if (settings && settings[key] !== undefined) {
|
|
return settings[key];
|
|
}
|
|
}
|
|
|
|
return fallback !== undefined ? fallback : null;
|
|
}
|
|
|
|
function getBoolean(key: string, fallback: boolean): boolean {
|
|
const val = get(key);
|
|
if (val === null) {
|
|
return fallback !== undefined ? fallback : false;
|
|
}
|
|
if (typeof val === 'string') {
|
|
return val === 'true';
|
|
}
|
|
return !!val;
|
|
}
|
|
|
|
function getNumber(key: string, fallback: number): number {
|
|
const val = parseFloat(get(key));
|
|
return isNaN(val) ? (fallback !== undefined ? fallback : NaN) : val;
|
|
}
|
|
|
|
return {
|
|
get: get,
|
|
getBoolean: getBoolean,
|
|
getNumber: getNumber
|
|
};
|
|
}
|