本文整理汇总了TypeScript中lodash.defaultTo函数的典型用法代码示例。如果您正苦于以下问题:TypeScript defaultTo函数的具体用法?TypeScript defaultTo怎么用?TypeScript defaultTo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了defaultTo函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: stringify
export function stringify( value: any, ...args: Array<any> ) {
let options: {
replacer?: ( key: string, value: any ) => any | Array<number | string>;
space?: string | number;
quote?: string;
};
if ( reflection.getType( args[ 0 ] ) === reflection.Type.object ) {
options = args[ 0 ];
} else {
options = {
replacer: args[ 0 ],
space: _.defaultTo( args[ 1 ], "\t" ),
quote: args[ 2 ],
};
}
return json5.stringify( value, options );
}
示例2: function
$scope.validateModel = function() {
$scope.index = _.indexOf(bucketAggs, $scope.agg);
$scope.isFirst = $scope.index === 0;
$scope.bucketAggCount = bucketAggs.length;
var settingsLinkText = '';
var settings = $scope.agg.settings || {};
switch ($scope.agg.type) {
case 'terms': {
settings.order = settings.order || 'desc';
settings.size = settings.size || '10';
settings.min_doc_count = settings.min_doc_count || 1;
settings.orderBy = settings.orderBy || '_term';
if (settings.size !== '0') {
settingsLinkText = queryDef.describeOrder(settings.order) + ' ' + settings.size + ', ';
}
if (settings.min_doc_count > 0) {
settingsLinkText += 'Min Doc Count: ' + settings.min_doc_count + ', ';
}
settingsLinkText += 'Order by: ' + queryDef.describeOrderBy(settings.orderBy, $scope.target);
if (settings.size === '0') {
settingsLinkText += ' (' + settings.order + ')';
}
break;
}
case 'filters': {
settings.filters = settings.filters || [{ query: '*' }];
settingsLinkText = _.reduce(
settings.filters,
function(memo, value, index) {
memo += 'Q' + (index + 1) + ' = ' + value.query + ' ';
return memo;
},
''
);
if (settingsLinkText.length > 50) {
settingsLinkText = settingsLinkText.substr(0, 50) + '...';
}
settingsLinkText = 'Filter Queries (' + settings.filters.length + ')';
break;
}
case 'date_histogram': {
settings.interval = settings.interval || 'auto';
settings.min_doc_count = settings.min_doc_count || 0;
$scope.agg.field = $scope.target.timeField;
settingsLinkText = 'Interval: ' + settings.interval;
if (settings.min_doc_count > 0) {
settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count;
}
if (settings.trimEdges === undefined || settings.trimEdges < 0) {
settings.trimEdges = 0;
}
if (settings.trimEdges && settings.trimEdges > 0) {
settingsLinkText += ', Trim edges: ' + settings.trimEdges;
}
break;
}
case 'histogram': {
settings.interval = settings.interval || 1000;
settings.min_doc_count = _.defaultTo(settings.min_doc_count, 1);
settingsLinkText = 'Interval: ' + settings.interval;
if (settings.min_doc_count > 0) {
settingsLinkText += ', Min Doc Count: ' + settings.min_doc_count;
}
break;
}
case 'geohash_grid': {
// limit precision to 7
settings.precision = Math.max(Math.min(settings.precision, 7), 1);
settingsLinkText = 'Precision: ' + settings.precision;
break;
}
}
$scope.settingsLinkText = settingsLinkText;
$scope.agg.settings = settings;
return true;
};
示例3: defaultTo
export const typeId = (type: string): Type =>
defaultTo(namesToTypes[type.trim().toLowerCase()], Type.CURSE);
示例4: get
export const construct = (config: ServerConfig): {
rootAppConfig: RootAppConfig,
cmsConfig: CmsServerConfig,
graphqlConfig: GqlifyConfig,
authConfig: AuthConfig,
} => {
// merge common config with default config
const authMountPath = defaultConfig.authMountPath;
const hostname = get(config, 'common.hostname');
// cookieKeys will override auth & cms cookie config
const cookieKeys = defaultTo(get(config, 'common.cookieKeys'), defaultConfig.cookieKeys);
// Whether this cms is public access or not
const publicAuth = defaultTo(get(config, 'common.public'), defaultConfig.public);
// oidc clientId & clientSecret are shared between cms & auth services
const clientId = defaultTo(get(config, 'common.clientId'), defaultConfig.clientId);
const clientSecret = defaultTo(get(config, 'common.clientSecret'), defaultConfig.clientSecret);
// oidc issuer
const discoveryUrlFromHost = `${hostname}${authMountPath}/.well-known/openid-configuration`;
const discoveryUrl = defaultTo(get(config, 'common.discoveryUrl'), discoveryUrlFromHost);
const issuerConfig = get(config, 'common.issuerConfig');
// graphql endpoint
const graphqlEndpoint = `${hostname}/graphql`;
// construct config for cms service
const cmsConfig: CmsServerConfig = merge({
cookieKeys,
hostname,
oidc: {
discoveryUrl,
clientId,
clientSecret,
},
logger: jsonLogger,
}, config.cms);
// config for gqlify service
const graphqlConfig: GqlifyConfig = {
logger: jsonLogger,
oidc: {
discoveryUrl,
issuerConfig,
},
...config.graphql,
};
// config for auth service
let authConfig: AuthConfig = {
mountPath: defaultConfig.authMountPath,
issuer: hostname,
cookies: {
long: { signed: true, maxAge: (1 * 24 * 60 * 60) * 1000 }, // 1 day in ms
short: { signed: true },
keys: cookieKeys,
},
redirectUris: [`${hostname}/auth/callback`],
postLogoutRedirectUris: [`${hostname}/`],
clientId,
clientSecret,
logger: jsonLogger,
...config.auth,
};
const rootAppConfig = {
graphqlEndpoint,
cookieKeys,
};
// if publicAuth is true, we make this cms public
// mark cmsConfig.oidc as null to tell cmsServer we do not need oidc
// mark graphqlConfig.oidc as null to tell graphql server we do not need auth
// mark authConfig to null, so auth service won't start
if (publicAuth) {
cmsConfig.oidc = null;
graphqlConfig.oidc = null;
authConfig = null;
}
return {
rootAppConfig,
cmsConfig,
graphqlConfig,
authConfig,
};
};