本文整理汇总了TypeScript中ramda.find函数的典型用法代码示例。如果您正苦于以下问题:TypeScript find函数的具体用法?TypeScript find怎么用?TypeScript find使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: matchesToMigration
function matchesToMigration(directory: string, matches: RegExpMatchArray[]): Migration {
if (matches.length === 1) {
let match = matches[0];
// Single match is a split migration file.
if (match[3]) throw new SplitFileMissingError(match[0]);
return {
id: match[1],
name: match[2],
split: false,
path: path.join(directory, match[0])
};
} else if (matches.length === 2) {
let upMatch = R.find(R.propEq(3, 'up'), matches);
let downMatch = R.find(R.propEq(3, 'down'), matches);
if (!upMatch) throw new SplitFileMissingError(downMatch[0]);
if (!downMatch) throw new SplitFileMissingError(upMatch[0]);
return {
id: upMatch[1],
name: upMatch[2],
split: true,
upPath: path.join(directory, upMatch[0]),
downPath: path.join(directory, downMatch[0])
};
} else {
// Too many matches.
throw new SplitFileConflictError(R.map(m => m[0], matches));
}
}
示例2: exec
exec('git branch --no-color -a', options, (error, stdout, stderr) => {
if (stderr || error) return reject(stderr || error);
const getCurrentBranch = R.compose(
R.trim,
R.replace('*', ''),
R.find(line => line.startsWith('*')),
R.split('\n')
);
const processBranches = R.compose(
R.filter(br => stdout.match(new RegExp(`remotes\/.*\/${br}`))),
R.uniq
);
const currentBranch = getCurrentBranch(stdout);
const branches = processBranches([currentBranch, defaultBranch]);
return excludeCurrentRevision
? resolve(branches)
: getCurrentRevision(exec, projectPath)
.then((currentRevision) => {
return resolve(branches.concat(currentRevision));
});
});
示例3: createCorrectReplacementSet
private createCorrectReplacementSet(syllable: string) {
const vowels = ['a', 'e', 'i', 'o', 'u'];
const knownVowels = intersection(vowels, this.letters);
const longVowels = map(vowel => vowel + vowel, vowels);
const knownLongVowels = map(vowel => vowel + vowel, knownVowels);
const diphtongs = ['ie', 'ei', 'au', 'eu', 'äu'];
const umlauts = ['ä', 'ö', 'ü'];
// start with the sets containing strings of length two!
const possibleReplacementSetsLowercase = [
knownLongVowels,
diphtongs,
longVowels,
umlauts,
knownVowels,
vowels
];
const possibleReplacementSetsCapitalized = map(
set => map(capitalizeFirstLetter, set),
possibleReplacementSetsLowercase
);
return find(
set => set.length > 0 && new RegExp(join('|', set), 'g').test(syllable),
[
...possibleReplacementSetsCapitalized,
...possibleReplacementSetsLowercase
]
);
}
示例4: getUser
.map(([claim, users]) => {
if (claim.approver) {
const getUser = R.find(R.propEq('$key', claim.approver));
return Object.assign(claim, { $approver: getUser(users) })
}
return claim;
})
示例5: findEntity
public findEntity(id: string): Optional<AbstractNode> {
const entity = super.findEntity(id);
if (entity) {
return entity;
}
const recursiveFind = map(child => child.findEntity(id), this.children);
return find(found => typeof found !== 'undefined', recursiveFind);
}
示例6: getPidByPidCode
export function getPidByPidCode (pidstring: string) : PID|null {
let names:Array<string> = keys(PIDS);
let pidname:string = find((name:string) => {
let curpid:PID = PIDS[name];
return curpid.getPid() === pidstring;
})(names);
if (pidname) {
return PIDS[pidname];
} else {
return null;
}
};
示例7: findImmediate
function findImmediate(id: string): User|undefined {
const userMatches: (user: User|undefined) => boolean = R.propEq('id', id);
return R.find(userMatches, userStore);
}
示例8: compose
import { DataResolver } from './app.resolver';
import { routes as blogRoutes, asyncRoutes as blogAsyncRoutes } from './blog/blog.routing';
import { prop, compose, split, find, trim, equals, nth, ifElse, identity } from 'ramda';
export const appNavLinks: NavigationConfig = [
...Pages.navLinks,
...Layouts.navLinks,
...Authentication.navLinks,
];
const layout = compose(
ifElse(identity, compose(nth(1), split('=')), identity),
find(compose(equals('layout'), trim, nth(0), split('='))),
split(';')
)(document.cookie);
const layouts = {
'horizontal': HorizontalLayout,
'vertical' : VerticalLayout
};
export const routes: RouterConfig = [
{
path: '',
component: layouts[layout],
children: [
...Pages.routes,
...Authentication.routes
示例9: find
const findStr = (target: string, set: string[]) => find((a: string) => a.toLocaleLowerCase() === target, set)
示例10:
.map(res => R.find(R.propEq('$key', typeKey))(res))
示例11:
if (user) {
if (roles && roles.items) {
const currentRoles = R.compose(
R.filter(role => {
// 判断返回的是否是 ids
if (user.roles && _.isObjectLike(user.roles[0])) {
return R.contains(role.id)(R.values(R.pluck('id', user.roles)));
}
return R.contains(role.id)(user.roles);
}),
R.propOr([], 'items'),
)(roles);
logger.debug('[init]', 'current roles is', currentRoles);
const isSysAdmin = !!R.find(role => role.name === 'SYS_ADMIN')(currentRoles);
logger.debug('[init]', 'current user isSysAdmin', isSysAdmin);
const authoritiesList = R.compose(
// remove null values
R.filter(R.identity),
// 后端返回字符串时需要反序列化为 JSON
R.map(role => {
const each = R.prop('authorities')(role);
return R.is(String, each) ? JSON.parse(each) : each;
}),
)(currentRoles);
logger.debug('[init]', 'current authoritiesList is', authoritiesList);
const authorities = R.reduce(R.mergeWith(R.or), {})(authoritiesList);
logger.debug('[init]', 'current authorities is', authorities);
示例12:
.map(([onLogin, user, employees]) => onLogin ? R.find(R.propEq('user', user))(employees) : undefined)
示例13: getEmployee
.map(([userKey, employees]) => {
const getEmployee = R.find(R.propEq('user', userKey));
return (getEmployee(employees) && getEmployee(employees).isAdmin) || false;
})
示例14:
R.map((n: any) => Object.assign(n, { $user: R.find(R.propEq('$key', n.user))(users) }))(items));
示例15:
let safeQuote = (str: string) => R.find(qt => !str.includes(qt));