本文整理汇总了TypeScript中lodash.startsWith函数的典型用法代码示例。如果您正苦于以下问题:TypeScript startsWith函数的具体用法?TypeScript startsWith怎么用?TypeScript startsWith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了startsWith函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: _getSuperType
private _getSuperType(cls: IClass, superName: string) {
var superClass = projectTypeMap[_.kebabCase(superName)] && projectTypeMap[_.kebabCase(superName)][this.name] || getMappedType(cls, superName);
if (_.startsWith(superClass, this._project.displayName + '.')) {
superClass = superClass.split('.')[1];
}
return superClass;
}
示例2:
_.forOwn(assignFunctions, (value, key) => {
if (_.startsWith(t, key)) {
af = value;
afKey = key;
return false;
}
});
示例3: summarize
export function summarize(statement: string): StatementSummary {
for (const keyword in keywords) {
if (_.startsWith(_.toLower(statement), _.toLower(keyword))) {
const tablePattern = keywords[keyword];
const tableMatch = tablePattern.exec(statement);
if (!tableMatch) {
return {
error: "unable to find table for " + keyword + " statement",
};
}
let table = tableMatch[1];
if (table[0] === "\"" && table[table.length - 1] === "\"") {
table = table.slice(1, table.length - 1);
}
return {
statement: keyword,
table: table,
};
}
}
return {
error: "unimplemented",
};
}
示例4:
return _.filter(templates, (template) => {
if (_.startsWith((template as any).name, collection.collection)) {
(template as any).label = _.replace((template as any).name, collection.collection + '/', '');
return template;
}
return false;
});
示例5: curryParams
function curryParams(
baseName: string,
sourceOverloadId: number,
sourceOverload: Overload,
interfaceIndex: number,
): Interface {
const params = getInterfaceParams(sourceOverload, interfaceIndex);
const interfaceTypeParams = getInterfaceTypeParams(sourceOverload, interfaceIndex);
const prevParams = _.without(sourceOverload.params, ...params);
const prevTypeParams = getUsedTypeParams(prevParams, sourceOverload.typeParams);
const typeParams = _.without(sourceOverload.typeParams, ...prevTypeParams);
// 1st overload takes no parameters and just returns the same interface (effectively a no-op)
// HACK: omit the parameterless overload because it's not very useful, and it causes the build to run out of memory
// This assumes params.length > 0, which is true because curryParams is only called when params.length >= 2.
/*const overloads: Overload[] = [{
typeParams: [],
params: [],
returnType: getInterfaceName(baseName, sourceOverloadId, interfaceIndex, interfaceTypeParams),
jsdoc: sourceOverload.jsdoc,
}];*/
const overloads: Overload[] = [];
const lastOverload = (1 << params.length) - 1;
for (let i = 1; i <= lastOverload; ++i) {
// xxxx i = number of parameters used by this overload
// const totalCombinations = nCk(params.length, i);
// i = binary representation of which parameters are used for this overload (reversed), e.g.
// 1 = 0001 -> 1000 = 1st parameter
// 6 = 1010 -> 0101 = 2nd and 4th parameters
const currentParams = params.map((p, j) => (i & (1 << j)) ? p : `${getParamName(p)}: __`);
while (currentParams.length > 0 && _.last(currentParams)!.endsWith("__"))
currentParams.pop(); // There's no point in passing a placeholder as the last parameter, so don't allow it.
const usedTypeParams = i < lastOverload ? getUsedTypeParams(currentParams, typeParams) : typeParams;
const combinedIndex = combineIndexes(interfaceIndex, i);
const passTypeParams = getInterfaceTypeParams(sourceOverload, combinedIndex);
const currentReturnType = i < lastOverload ? getInterfaceName(baseName, sourceOverloadId, combinedIndex, passTypeParams) : sourceOverload.returnType;
overloads.push({
typeParams: _.cloneDeep(usedTypeParams),
params: currentParams,
returnType: currentReturnType,
jsdoc: interfaceIndex === 0 ? sourceOverload.jsdoc : "",
});
}
const interfaceDef: Interface = {
name: getInterfaceName(baseName, sourceOverloadId, interfaceIndex, []),
typeParams: _.cloneDeep(interfaceTypeParams),
overloads,
constants: [],
};
// Remove the `extends` constraint from interface type parameters, because sometimes they extend things that aren't passed to the interface.
for (const typeParam of interfaceDef.typeParams) {
// 1. retain `extends keyof X` constraints so that TObject[TKey] still works.
// 2. retain `any[]` constraints so that variadic generics work.
if (!_.startsWith(typeParam.extends, "keyof ") && typeParam.extends !== "any[]")
delete typeParam.extends;
}
return interfaceDef;
}
示例6: BigNumber
const wrapIfBigNumber = (value: ContractEventArg): ContractEventArg => {
// HACK: The old version of BigNumber used by Web3@0.19.0 does not support the `isBigNumber`
// and checking for a BigNumber instance using `instanceof` does not work either. We therefore
// check if the value constructor is a bignumber constructor.
const isWeb3BigNumber = _.startsWith(value.constructor.toString(), 'function BigNumber(');
return isWeb3BigNumber ? new BigNumber(value) : value;
};
示例7: function
var fetch = function() {
var action = last(actionName.match(/(\$[c|m]:)?(.*)/))
var promise
if (startsWith(actionName, '$m')) {
promise = subject.$m(action, params)
}
else {
promise = subject.$c(action, params)
}
promise
.then(function(pageResult) {
page = page + 1
merge(params, { page: page })
result.objects = result.objects.concat(pageResult.objects)
if ((page <= 100) && (page <= (pageResult.headers && pageResult.headers['x-total-pages'] || 0))) {
fetch()
}
else {
resolve(result)
}
return true
}, function() {
reject(null)
})
}
示例8: convertSchemaIdToKey
function convertSchemaIdToKey(schemaId: string) {
let result = schemaId;
if (_.startsWith(result, '/')) {
result = result.substr(1);
}
result = `${result}Schema`;
return result;
}
示例9: function
$('#manifest_url').on('keyup', function () {
let url: string = $(this).val().trim();
const $result = $('#manifest_key');
// oldSheet: 'https://docs.google.com/spreadsheet/ccc?key={key}'
// newSheet: 'https://docs.google.com/spreadsheets/d/{key}'
if (!_.startsWith(url, 'https://docs.google.com/spreadsheet')) {
if (_.startsWith('https://docs.google.com/spreadsheet', url)) {
$result.val('');
} else {
$result.val('Invalid URL');
}
return;
}
url = url.slice(35); // 'https://docs.google.com/spreadsheet'.length
let gidMatch = url.match(/[#?&]gid=(.*)([#&]|$)/);
let gid: string = '';
if (gidMatch) {
gid = gid[1];
if (0 !== +gid) {
gid = `&gid=${gid}`;
} else {
gid = '';
}
}
if (_.startsWith(url, '/ccc?')) {
// ye olde URL style
const matches = url.match(/\?(.*&)?key=([^&#]*)([#&]|$)/)
if (matches) {
$result.val(matches[2] + gid);
} else {
$result.val('Invalid URL');
}
} else if (_.startsWith(url, '/s/d')) {
// new URL style
url = url.slice(4); // 's/d/'.length
$result.val(url.replace(/[#?/].*$/, '')) + gid
}
});
示例10: function
sails.router.bind(route, function (req: any, res: any, next: Function) {
let protocol: any = _.startsWith(swagger.host, 'http') ? '' : 'http://';
let targetUrlTemplate: any = protocol + swagger.host + ( swagger.basePath || '' ) + path;
let templateFn: any = _.template(targetUrlTemplate, {
interpolate: /{([\s\S]+?)}/g
});
let params: any = req.allParams();
let targetUrl: any = templateFn(params);
let headers: any = req.headers;
_.unset(headers, 'cookie');
_.unset(headers, 'host');
_.unset(headers, 'user-agent');
_.unset(headers, 'referer');
let reqOut: any = {
url: targetUrl,
method: vertex,
body: ( req.body || null ),
qs: req.transport != 'socket.io' ? req.query : req.body,
json: true,
headers: headers
};
let $request: any = sails.$request(req.session) || request;
$request(reqOut, function (err: Error, message: any, body: any): void {
console.log('*************************');
console.log('' + vertex + ' ' + targetUrl);
console.log('-------------------------');
console.dir(headers);
console.log('=========================');
console.dir(body);
if (params && body && !params.id && !_.isArray(body)) {
body.id = body.id || uuid.v4();
body = [body];
}
else if (_.isArray(body)) {
_.each(body, function (item: any) {
item.id = item.id || uuid.v4();
});
}
if (!err) {
res
.status(message.statusCode)
.send(body);
}
else {
res.serverError(err);
}
})
})