lodash#defaultsDeep TypeScript Examples
The following examples show how to use
lodash#defaultsDeep.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: completion-items-utils.ts From ui5-language-assistant with Apache License 2.0 | 7 votes |
/** Use ⇶ to mark the cursor position */
export function getSuggestions(
xmlSnippet: string,
ui5SemanticModel: UI5SemanticModel,
settings?: Partial<Settings>
): CompletionItem[] {
const { document, position } = getXmlSnippetDocument(xmlSnippet);
const uri: TextDocumentIdentifier = { uri: "uri" };
const textDocPositionParams: TextDocumentPositionParams = {
textDocument: uri,
position: position,
};
if (settings === undefined) {
// In the tests - show experimental and deprecated by default
settings = { codeAssist: { deprecated: true, experimental: true } };
}
const allSettings = defaultsDeep(
{},
settings,
getDefaultSettings()
) as Settings;
const suggestions = getCompletionItems({
model: ui5SemanticModel,
textDocumentPosition: textDocPositionParams,
document,
documentSettings: allSettings,
});
// Check that all returned suggestions will be displayed to the user
assertSuggestionsAreValid(suggestions, xmlSnippet);
return suggestions;
}
Example #2
Source File: pluginMocks.ts From grafana-chinese with Apache License 2.0 | 6 votes |
export function getMockPlugin(overrides?: Partial<PluginMeta>): PluginMeta {
const defaults: PluginMeta = {
defaultNavUrl: 'some/url',
enabled: false,
hasUpdate: false,
id: '1',
info: {
author: {
name: 'Grafana Labs',
url: 'url/to/GrafanaLabs',
},
description: 'pretty decent plugin',
links: [{ name: 'project', url: 'one link' }],
logos: { small: 'small/logo', large: 'large/logo' },
screenshots: [{ path: `screenshot`, name: 'test' }],
updated: '2018-09-26',
version: '1',
},
latestVersion: '1',
name: 'pretty cool plugin 1',
baseUrl: 'path/to/plugin',
pinned: false,
type: PluginType.panel,
module: 'path/to/module',
};
return defaultsDeep(overrides || {}, defaults) as PluginMeta;
}
Example #3
Source File: index.ts From cards-against-formality-services with BSD 2-Clause "Simplified" License | 5 votes |
export default function (opts?: Options) {
opts = defaultsDeep(opts, {
port: 3001,
readiness: {
path: "/ready"
},
liveness: {
path: "/live"
},
});
let state = "down";
let server;
function handler(req, res) {
if (req.url == opts.readiness.path || req.url == opts.liveness.path) {
const resHeader = {
"Content-Type": "application/json; charset=utf-8"
};
const content = {
state,
uptime: process.uptime(),
timestamp: Date.now()
};
if (req.url == opts.readiness.path) {
// Readiness if the broker started successfully.
// https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-readiness-probes
res.writeHead(state == "up" ? 200 : 503, resHeader);
} else {
// Liveness if the broker is not stopped.
// https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#define-a-liveness-command
res.writeHead(state != "down" ? 200 : 503, resHeader);
}
res.end(JSON.stringify(content, null, 2));
} else {
res.writeHead(404, http.STATUS_CODES[404], {});
res.end();
}
}
return {
created(broker) {
state = "starting";
server = http.createServer(handler);
server.on("request", handler);
server.listen(opts.port, err => {
if (err) {
return broker.logger.error("Unable to start health-check server", err);
}
broker.logger.info("");
broker.logger.info("K8s health-check server listening on");
broker.logger.info(` http://localhost:${opts.port}${opts.readiness.path}`);
broker.logger.info(` http://localhost:${opts.port}${opts.liveness.path}`);
broker.logger.info("");
});
},
// After broker started
started(broker) {
state = "up";
},
// Before broker stopping
stopping(broker) {
state = "stopping";
},
// After broker stopped
stopped(broker) {
state = "down";
server.close();
}
};
}