本文整理汇总了TypeScript中lodash.isEmpty函数的典型用法代码示例。如果您正苦于以下问题:TypeScript isEmpty函数的具体用法?TypeScript isEmpty怎么用?TypeScript isEmpty使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了isEmpty函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setEditMode
angular.module("eperusteApp").factory("Editointikontrollit", ($rootScope, $q, Utils, Notifikaatiot,
YleinenData, $uibModal) => {
let scope = $rootScope.$new(true);
scope.editingCallback = null;
scope.editMode = false;
scope.editModeDefer = $q.defer();
let cbListener = _.noop;
let editmodeListener = null;
async function setEditMode(mode) {
scope.editMode = mode;
scope.editModeDefer = $q.defer();
scope.editModeDefer.resolve(scope.editMode);
if (scope.editingCallback) {
scope.editingCallback.notify(mode);
}
if (editmodeListener) {
editmodeListener(mode);
}
}
return {
lastModified: null,
async startEditing() {
try {
await scope.editingCallback.edit();
setEditMode(true);
$rootScope.$broadcast("enableEditing");
$rootScope.$$ekEditing = true;
} catch (ex) {
$rootScope.$$ekEditing = false;
}
},
notifySentenceCaseWarnings(obj) {
const warnings = [];
_.each(obj.paths, path => {
this.sentenceCaseValidator(_.get(obj.obj, path), warnings);
});
if (warnings.length > 0) {
$uibModal.open({
template: require("views/modals/sisaltoMuotoiluVaroitusModal.html"),
resolve: {
warnings: () => warnings
},
controller: ($scope, $uibModalInstance, warnings) => {
$scope.warnings = warnings;
$scope.ok = () => {
$uibModalInstance.close();
};
$scope.cancel = () => {
$uibModalInstance.dismiss('cancel');
};
},
}).result.then(() => {
if (_.isFunction(obj.after)) {
obj.after();
}
});
} else {
if (_.isFunction(obj.after)) {
obj.after();
}
}
},
sentenceCaseValidator(obj, warnings) {
function validateSentenceCase(input, lang?) {
const isValid = _.isEmpty(input) || (_.isString(input) && _.eq(input, _.capitalize(input.toLowerCase())));
if (!isValid) {
warnings.push({
text: input,
lang
});
}
return isValid;
}
if (_.isObject(obj) && !_.isEmpty(obj)) {
const langs = _(obj)
.keys()
.filter(key => _.includes(_.values(YleinenData.kielet), key))
.value();
_.each(langs, (key: any) => {
validateSentenceCase(obj[key], key)
});
} else {
validateSentenceCase(obj)
}
},
async saveEditing(kommentti) {
$rootScope.$broadcast("editointikontrollit:preSave");
$rootScope.$broadcast("notifyCKEditor");
let err;
//.........这里部分代码省略.........
示例2: emptyXOR
function emptyXOR(foo: any, bar: any): boolean {
return (_.isEmpty(foo) || _.isEmpty(bar)) && !(_.isEmpty(foo) && _.isEmpty(bar));
}
示例3: isValidSignature
import { ECSignature } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash';
import { signatureUtils } from '../utils/signature_utils';
export const assert = {
...sharedAssert,
isValidSignature(orderHash: string, ecSignature: ECSignature, signerAddress: string) {
const isValidSignature = signatureUtils.isValidSignature(orderHash, ecSignature, signerAddress);
this.assert(isValidSignature, `Expected order with hash '${orderHash}' to have a valid signature`);
},
async isSenderAddressAsync(
variableName: string,
senderAddressHex: string,
web3Wrapper: Web3Wrapper,
): Promise<void> {
sharedAssert.isETHAddressHex(variableName, senderAddressHex);
const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
sharedAssert.assert(
isSenderAddressAvailable,
`Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
);
},
async isUserAddressAvailableAsync(web3Wrapper: Web3Wrapper): Promise<void> {
const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 provider');
},
};
示例4: require
import isMobile = require('is-mobile');
import * as _ from 'lodash';
import { scroller } from 'react-scroll';
import { EtherscanLinkSuffixes, Networks } from '../types';
import { constants } from './constants';
export const utils = {
setUrlHash(anchorId: string) {
window.location.hash = anchorId;
},
scrollToHash(hash: string, containerId: string): void {
let finalHash = hash;
if (_.isEmpty(hash)) {
finalHash = constants.SCROLL_TOP_ID; // scroll to the top
}
scroller.scrollTo(finalHash, {
duration: 0,
offset: 0,
containerId,
});
},
isUserOnMobile(): boolean {
const isUserOnMobile = isMobile();
return isUserOnMobile;
},
getIdFromName(name: string) {
const id = name.replace(/ /g, '-');
return id;
示例5: return
var queries = _.filter(options.targets, item => {
return (
item.hide !== true && !!item.region && !!item.namespace && !!item.metricName && !_.isEmpty(item.statistics)
);
}).map(item => {
示例6: getTrackedTokensByUserAddress
let trackedTokensByNetworkId = trackedTokensByUserAddress[userAddress];
if (_.isUndefined(trackedTokensByNetworkId)) {
trackedTokensByNetworkId = {};
}
const trackedTokens = !_.isUndefined(trackedTokensByNetworkId[networkId])
? trackedTokensByNetworkId[networkId]
: [];
trackedTokens.push(token);
trackedTokensByNetworkId[networkId] = trackedTokens;
trackedTokensByUserAddress[userAddress] = trackedTokensByNetworkId;
const trackedTokensByUserAddressJSONString = JSON.stringify(trackedTokensByUserAddress);
localStorage.setItem(TRACKED_TOKENS_KEY, trackedTokensByUserAddressJSONString);
},
getTrackedTokensByUserAddress(): TrackedTokensByUserAddress {
const trackedTokensJSONString = localStorage.getItemIfExists(TRACKED_TOKENS_KEY);
if (_.isEmpty(trackedTokensJSONString)) {
return {};
}
const trackedTokensByUserAddress = JSON.parse(trackedTokensJSONString);
return trackedTokensByUserAddress;
},
getTrackedTokensByAddress(userAddress: string, networkId: number): TokenByAddress {
const trackedTokensByAddress: TokenByAddress = {};
const trackedTokensJSONString = localStorage.getItemIfExists(TRACKED_TOKENS_KEY);
if (_.isEmpty(trackedTokensJSONString)) {
return trackedTokensByAddress;
}
const trackedTokensByUserAddress = JSON.parse(trackedTokensJSONString);
const trackedTokensByNetworkId = trackedTokensByUserAddress[userAddress];
if (_.isUndefined(trackedTokensByNetworkId)) {
return trackedTokensByAddress;
示例7: function
this.query = function(options) {
var self = this;
var start = this.getPrometheusTime(options.range.from, false);
var end = this.getPrometheusTime(options.range.to, true);
var queries = [];
var activeTargets = [];
options = _.clone(options);
_.each(options.targets, target => {
if (!target.expr || target.hide) {
return;
}
activeTargets.push(target);
var query: any = {};
query.expr = templateSrv.replace(target.expr, options.scopedVars, self.interpolateQueryExpr);
query.requestId = options.panelId + target.refId;
var interval = templateSrv.replace(target.interval, options.scopedVars) || options.interval;
var intervalFactor = target.intervalFactor || 1;
target.step = query.step = this.calculateInterval(interval, intervalFactor);
var range = Math.ceil(end - start);
// Prometheus drop query if range/step > 11000
// calibrate step if it is too big
if (query.step !== 0 && range / query.step > 11000) {
target.step = query.step = Math.ceil(range / 11000);
}
queries.push(query);
});
// No valid targets, return the empty result to save a round trip.
if (_.isEmpty(queries)) {
var d = $q.defer();
d.resolve({ data: [] });
return d.promise;
}
var allQueryPromise = _.map(queries, query => {
return this.performTimeSeriesQuery(query, start, end);
});
return $q.all(allQueryPromise).then(function(allResponse) {
var result = [];
_.each(allResponse, function(response, index) {
if (response.status === 'error') {
self.lastErrors.query = response.error;
throw response.error;
}
delete self.lastErrors.query;
_.each(response.data.data.result, function(metricData) {
result.push(self.transformMetricData(metricData, activeTargets[index], start, end));
});
});
return { data: result };
});
};
示例8: function
!_.every(mustHave, function(item) {
return (
_.includes(keys, item) &&
(!_.isEmpty(opts[item]) || _.isNumber(opts[item]))
);
})
示例9: addYAxis
addYAxis() {
let ticks = Math.ceil(this.chartHeight / DEFAULT_Y_TICK_SIZE_PX);
let tickInterval = ticksUtils.tickStep(this.data.heatmapStats.min, this.data.heatmapStats.max, ticks);
let { yMin, yMax } = this.wideYAxisRange(this.data.heatmapStats.min, this.data.heatmapStats.max, tickInterval);
// Rewrite min and max if it have been set explicitly
yMin = this.panel.yAxis.min !== null ? this.panel.yAxis.min : yMin;
yMax = this.panel.yAxis.max !== null ? this.panel.yAxis.max : yMax;
// Adjust ticks after Y range widening
tickInterval = ticksUtils.tickStep(yMin, yMax, ticks);
ticks = Math.ceil((yMax - yMin) / tickInterval);
const decimalsAuto = ticksUtils.getPrecision(tickInterval);
let decimals = this.panel.yAxis.decimals === null ? decimalsAuto : this.panel.yAxis.decimals;
// Calculate scaledDecimals for log scales using tick size (as in jquery.flot.js)
const flotTickSize = ticksUtils.getFlotTickSize(yMin, yMax, ticks, decimalsAuto);
const scaledDecimals = ticksUtils.getScaledDecimals(decimals, flotTickSize);
this.ctrl.decimals = decimals;
this.ctrl.scaledDecimals = scaledDecimals;
// Set default Y min and max if no data
if (_.isEmpty(this.data.buckets)) {
yMax = 1;
yMin = -1;
ticks = 3;
decimals = 1;
}
this.data.yAxis = {
min: yMin,
max: yMax,
ticks: ticks,
};
this.scope.yScale = this.yScale = d3
.scaleLinear()
.domain([yMin, yMax])
.range([this.chartHeight, 0]);
const yAxis = d3
.axisLeft(this.yScale)
.ticks(ticks)
.tickFormat(this.tickValueFormatter(decimals, scaledDecimals))
.tickSizeInner(0 - this.width)
.tickSizeOuter(0)
.tickPadding(Y_AXIS_TICK_PADDING);
this.heatmap
.append('g')
.attr('class', 'axis axis-y')
.call(yAxis);
// Calculate Y axis width first, then move axis into visible area
const posY = this.margin.top;
const posX = this.getYAxisWidth(this.heatmap) + Y_AXIS_TICK_PADDING;
this.heatmap.select('.axis-y').attr('transform', 'translate(' + posX + ',' + posY + ')');
// Remove vertical line in the right of axis labels (called domain in d3)
this.heatmap
.select('.axis-y')
.select('.domain')
.remove();
}
示例10: isValid
public isValid(value: string): boolean {
return !_.isEmpty(value);
}