本文整理汇总了TypeScript中lodash.transform函数的典型用法代码示例。如果您正苦于以下问题:TypeScript transform函数的具体用法?TypeScript transform怎么用?TypeScript transform使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了transform函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: disabledAxisMap
export function disabledAxisMap(h: McuParams): Record<Xyz, boolean> {
return transform<boolean, Record<Xyz, boolean>>(
enabledAxisMap(h),
(d: Record<Xyz, boolean>[], value: boolean, key: Xyz) => {
d[0][key] = !value;
}, [{ x: false, y: false, z: false }])[0];
}
示例2: function
const handleV2CoinSpecificREST = function(req, res, next) {
const method = req.method;
const bitgo = req.bitgo;
try {
const coin = bitgo.coin(req.params.coin);
const coinURL = coin.url(createAPIPath(req));
return redirectRequest(bitgo, method, coinURL, req, next);
} catch (e) {
if (e instanceof errors.UnsupportedCoinError) {
const queryParams = _.transform(req.query, (acc, value, key) => {
for (const val of _.castArray(value)) {
acc.push(`${key}=${val}`);
}
}, []);
const baseUrl = bitgo.url(req.baseUrl.replace(/^\/api\/v2/, ''), 2);
const url = _.isEmpty(queryParams) ? baseUrl : `${baseUrl}?${queryParams.join('&')}`;
debug(`coin ${req.params.coin} not supported, attempting to handle as a coinless route with url ${url}`);
return redirectRequest(bitgo, method, url, req, next);
}
throw e;
}
};
示例3: difference
export function difference (obj: _.Dictionary<any>, base: _.Dictionary<any>) {
return _.transform(obj, (result, value, key) => {
if (!_.isEqual(value, base[key])) {
result[key] = _.isObject(value) && _.isObject(base[key]) ? difference(value, base[key]) : value
}
})
}
示例4: constructor
/**
* Server is a gRPC transport provider for serving.
*
* @param {Object} config Configuration object.
* Requires properties:addr,package,proto,service
* Optional properties: credentials.ssl.certs
*/
constructor(config: any, logger: any) {
if (_.isNil(logger)) {
throw new Error('gRPC server transport provider requires a logger');
}
if (!_.has(config, 'addr')) {
throw new Error('server is missing addr config field');
}
if (!_.has(config, 'services')) {
throw new Error('server is missing services config field');
}
this.config = config;
this.logger = logger;
// console['error'] = logger.debug;
// gRPC logger
grpc.setLogger(console);
this.server = new grpc.Server();
// build protobuf
const protoRoot = config.protoRoot || path.join(process.cwd(), 'protos');
if (_.isNil(protoRoot) || _.size(protoRoot) === 0) {
throw new Error('config value protoRoot is not set');
}
const protos = config.protos;
if (_.isNil(protos) || _.size(protos) === 0) {
throw new Error('config value protos is not set');
}
this.logger.verbose(`gRPC Server loading protobuf files from root ${protoRoot}`, { protos });
const proto = [];
for (let i = 0; i < protos.length; i++) {
const filePath = { root: protoRoot, file: protos[i] };
this.proto = grpc.load(filePath, 'proto', {
longsAsStrings: false
});
proto[i] = this.proto;
}
let k = 0;
this.service = _.transform(this.config.services, (service: any, protobufServiceName: string, serviceName: string) => {
const serviceDef = _.get(proto[k], protobufServiceName);
if (_.isNil(serviceDef)) {
throw new Error(`Could not find ${protobufServiceName} protobuf service`);
}
_.set(service, serviceName, serviceDef.service);
k++;
logger.verbose('gRPC service loaded', serviceName);
});
this.name = NAME;
}
示例5: flattenObject
export function flattenObject(obj: any) {
return _.transform(obj, function (result, value, key) {
if (_.isObject(value) && !_.isArray(value)) {
const flatMap = _.mapKeys(flattenObject(value), (_mvalue, mkey) => {
return `${key}.${mkey}`;
});
_.assign(result, flatMap);
} else {
result[key] = value;
}
return result;
}, {});
}
示例6: async
const checkPrivilegesAtResources = async (
resources: string[],
privilegeOrPrivileges: string | string[]
): Promise<CheckPrivilegesAtResourcesResponse> => {
const privileges = Array.isArray(privilegeOrPrivileges)
? privilegeOrPrivileges
: [privilegeOrPrivileges];
const allApplicationPrivileges = uniq([actions.version, actions.login, ...privileges]);
const hasPrivilegesResponse: HasPrivilegesResponse = await callWithRequest(
request,
'shield.hasPrivileges',
{
body: {
applications: [
{
application,
resources,
privileges: allApplicationPrivileges,
},
],
},
}
);
validateEsPrivilegeResponse(
hasPrivilegesResponse,
application,
allApplicationPrivileges,
resources
);
const applicationPrivilegesResponse = hasPrivilegesResponse.application[application];
if (hasIncompatibileVersion(applicationPrivilegesResponse)) {
throw new Error(
'Multiple versions of Kibana are running against the same Elasticsearch cluster, unable to authorize user.'
);
}
return {
hasAllRequested: hasPrivilegesResponse.has_all_requested,
username: hasPrivilegesResponse.username,
// we need to filter out the non requested privileges from the response
resourcePrivileges: transform(applicationPrivilegesResponse, (result, value, key) => {
result[key!] = pick(value, privileges);
}),
};
};
示例7: convert
export function convert(obj) {
return _.transform(obj, function (result, value, key) {
if (_.isObject(value)) {
let flatMap = _.mapKeys(convert(value), function (mvalue, mkey) {
if (_.isArray(value)) {
let index = mkey.indexOf('.');
if (-1 !== index) {
return `${key}[${mkey.slice(0, index)}]${mkey.slice(index)}`;
}
return `${key}[${mkey}]`;
}
return `${key}.${mkey}`;
});
_.assign(result, flatMap);
} else {
result[key] = value;
}
return result;
}, {});
}
示例8: checkPrivilegesWithRequest
return function checkPrivilegesWithRequest(request: Record<string, any>): CheckPrivileges {
const checkPrivilegesAtResources = async (
resources: string[],
privilegeOrPrivileges: string | string[]
): Promise<CheckPrivilegesAtResourcesResponse> => {
const privileges = Array.isArray(privilegeOrPrivileges)
? privilegeOrPrivileges
: [privilegeOrPrivileges];
const allApplicationPrivileges = uniq([actions.version, actions.login, ...privileges]);
const hasPrivilegesResponse: HasPrivilegesResponse = await callWithRequest(
request,
'shield.hasPrivileges',
{
body: {
applications: [
{
application,
resources,
privileges: allApplicationPrivileges,
},
],
},
}
);
validateEsPrivilegeResponse(
hasPrivilegesResponse,
application,
allApplicationPrivileges,
resources
);
const applicationPrivilegesResponse = hasPrivilegesResponse.application[application];
if (hasIncompatibileVersion(applicationPrivilegesResponse)) {
throw new Error(
'Multiple versions of Kibana are running against the same Elasticsearch cluster, unable to authorize user.'
);
}
return {
hasAllRequested: hasPrivilegesResponse.has_all_requested,
username: hasPrivilegesResponse.username,
// we need to filter out the non requested privileges from the response
resourcePrivileges: transform(applicationPrivilegesResponse, (result, value, key) => {
result[key!] = pick(value, privileges);
}),
};
};
const checkPrivilegesAtResource = async (
resource: string,
privilegeOrPrivileges: string | string[]
) => {
const { hasAllRequested, username, resourcePrivileges } = await checkPrivilegesAtResources(
[resource],
privilegeOrPrivileges
);
return {
hasAllRequested,
username,
privileges: resourcePrivileges[resource],
};
};
return {
async atSpace(spaceId: string, privilegeOrPrivileges: string | string[]) {
const spaceResource = ResourceSerializer.serializeSpaceResource(spaceId);
return await checkPrivilegesAtResource(spaceResource, privilegeOrPrivileges);
},
async atSpaces(spaceIds: string[], privilegeOrPrivileges: string | string[]) {
const spaceResources = spaceIds.map(spaceId =>
ResourceSerializer.serializeSpaceResource(spaceId)
);
const { hasAllRequested, username, resourcePrivileges } = await checkPrivilegesAtResources(
spaceResources,
privilegeOrPrivileges
);
return {
hasAllRequested,
username,
// we need to turn the resource responses back into the space ids
spacePrivileges: transform(resourcePrivileges, (result, value, key) => {
result[ResourceSerializer.deserializeSpaceResource(key!)] = value;
}),
};
},
async globally(privilegeOrPrivileges: string | string[]) {
return await checkPrivilegesAtResource(GLOBAL_RESOURCE, privilegeOrPrivileges);
},
};
};
示例9: extractSymbols
export function extractSymbols(
element: any,
document: string,
documentLines: string[],
symbolsType: RefractSymbolMap[],
): SymbolInformation[] {
const queryResults = query(element, symbolsType);
return lodash.transform(queryResults, (result, queryResult) => {
/*
WARNING: This might be your reaction when you'll look into this code: 😱
Thing is there is no really source map here and I do not want to solve this
thing in this release. The long term idea would be to wait till the underlying
parser will be updated to generate sourcemaps on generated content as well
and everybody will be happy; till that moment, please bear with me.
*/
let sourceMap;
['meta.title.attributes.sourceMap',
'attributes.href.attributes.sourceMap',
(qs) => query(qs, [{ query: { attributes: { method: {} } }, symbolKind: 0 }]),
].some((path: string | Function): boolean => {
if (typeof (path) === 'function') {
sourceMap = lodash.get((path as Function)(queryResult)[0], 'attributes.method.attributes.sourceMap');
return true;
} else {
if (lodash.has(queryResult, path)) {
sourceMap = lodash.get(queryResult, path);
return true;
}
}
});
const lineReference = createLineReferenceFromSourceMap(
sourceMap,
document,
documentLines,
);
let description = '';
['meta.title.content',
'attributes.href.content',
(qs) => query(qs, [{ query: { attributes: { method: {} } }, symbolKind: 0 }]),
].some((path: string | Function): boolean => {
if (typeof (path) === 'function') {
description = decodeURI(lodash.get((path as Function)(queryResult)[0], 'attributes.method.content'));
return true;
} else {
if (lodash.has(queryResult, path)) {
description = decodeURI(lodash.get(queryResult, path));
return true;
}
}
});
if (!lodash.isEmpty(lineReference)) {
result.push(SymbolInformation.create(
description,
queryResult.symbolKind,
Range.create(
lineReference.startRow,
lineReference.startIndex,
lineReference.endRow,
lineReference.endIndex,
),
null,
queryResult.container));
}
});
}
示例10:
(sentence_answers, sentence_answer, sentence_num) => sentence_answers[sentence_num] = _.transform(sentence_answer,
(word_answers, word_answer, word_index) => word_answers[word_index] = {
word: word_answer.word,
valid: state.sentences[sentence_num].words[+word_index] === word_answer.word
}
)