本文整理匯總了TypeScript中underscore.chain函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript chain函數的具體用法?TypeScript chain怎麽用?TypeScript chain使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了chain函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: encodeURIComponent
_.each(result.Results, (v, k) => {
if (_.filter(v.Values, x => x.Hits > 0).length < 2) {
delete result.Results[k];
return;
}
v.Values = _.chain(v.Values)
.map((x) => {
var val = JSON.stringify(x.Range)
.replace(/^\"|\"$/gi, "")
.replace(/\:/gi, "\\:")
.replace(/\(/gi, "\\(")
.replace(/\)/gi, "\\)")
;
if (x.Range.indexOf(" TO ") <= 0 || x.Range.indexOf("[") !== 0) {
val = val.replace(/\ /gi, "\\ ");
}
val = encodeURIComponent(val);
x.q = k + ":" + val;
x.Range = x.Range.replace(/^\[Dx/, "").replace(/ Dx/, " ").replace(/\]$/, "").replace(/ TO /, "-")
return x;
})
.filter((x) => x.Hits > 0)
.sortBy((x) => x.Range)
.value();
});
示例2: save
save() {
_.chain(this.tnxs)
.forEach((t:Transaction) => {
this._tnxService.saveItem(t);
this._pTnxService.deleteItem(t);
});
}
示例3: function
static respondToResourceGET<T>(requestBody, res, dao: DAO<T>, whereArray: string[], likeArray: string[]) {
let whereQuery = _.omit(_.pick(requestBody, whereArray),
function (value, key, object) {
return value === "";
});
let likeQuery_ = _.chain(requestBody)
.pick(requestBody, likeArray)
.omit(function (value, key, object) {
return value === "";
}).value();
let likeQuery = _.mapObject(likeQuery_, function (value, key) {
return "%" + value + "%";
});
dao.find({
where: whereQuery, like: likeQuery, orderBy: requestBody.orderBy
}, function (err, results) {
if (err) {
APIHelper.sendDatabaseErrorResponse(res, err);
} else {
if (results.length === 0) {
APIHelper.sendNotFoundResponse(res, "Not found.");
} else {
APIHelper.sendResponse(res, results);
}
}
});
}
示例4: async
checkMembershipUnicity: async (block:BlockDTO, conf:ConfDTO, index:IndexEntry[]) => {
const mindex = Indexer.mindex(index);
const pubkeys = _.chain(mindex).pluck('pub').uniq().value();
if (pubkeys.length !== mindex.length) {
throw Error('Unicity constraint PUBLIC_KEY on MINDEX is not respected');
}
return true;
},
示例5: isEmpty
public static isEmpty(queryBuilderExpression: QueryBuilderExpression) {
const allNonEmptyValues = _.chain(queryBuilderExpression)
.values()
.compact()
.value();
return _.isEmpty(allNonEmptyValues);
}
示例6: update
update() {
_.chain(this.tnxs)
.filter(t=> t.accountId == this.selectedFrom)
.forEach((t:Transaction) => {
t.accountId = this.selectedTo;
this._pTnxService.updateItem(t);
});
}
示例7: cb
return through2.obj(function (chunk, enc, cb) {
const pushGerritEventForward = (gerritEvent: GerritEvent) => this.push(gerritEvent);
_.chain(getGerritEventsStringByChunk(chunk))
.compact()
.map(parseToGerritEvent)
.compact()
.map(pushGerritEventForward);
cb();
});
示例8: instantiateToString
public instantiateToString(object: IQueryResult, instantiateOptions: IInstantiateTemplateOptions = {}): string {
Assert.exists(object);
let mergedOptions = new DefaultInstantiateTemplateOptions().merge(instantiateOptions);
object = _.extend({}, object, UnderscoreTemplate.templateHelpers);
const templates = _.chain(TemplateCache.getDefaultTemplates())
.map(name => TemplateCache.getTemplate(name))
.value();
// Put templates with conditions first
const sortedTemplates = _.chain(templates)
.sortBy(template => template.condition == null)
.sortBy(template => template.fieldsToMatch == null)
.value();
for (let i = 0; i < sortedTemplates.length; i++) {
const result = sortedTemplates[i].instantiateToString(object, mergedOptions);
if (result != null) {
return result;
}
}
return this.getFallbackTemplate();
}