本文整理汇总了TypeScript中lodash/fp.sortBy函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sortBy函数的具体用法?TypeScript sortBy怎么用?TypeScript sortBy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sortBy函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: curry
export const sortByMap = curry(function(
mapToSortBy: Record<string, number>,
listToSort: string[]
): string[] {
return sortBy(function(listItem) {
return mapToSortBy[listItem];
}, listToSort);
});
示例2: flow
(snippets) => flow([
map('files'),
flattenDeep,
groupBy('language'),
map((language: string[]) => ({
language: get('language', head(language)),
size: size(language)
})),
sortBy('size'),
reverse
])(snippets)
示例3: lowfp
() => {
const adapterLS = new LocalStorage<DbSchema>("test.json");
const dbFP = lowfp(adapterLS);
// Get posts
const postsFP = dbFP("posts");
// replace posts with a new array resulting from concat
// and persist database
const write: Post[] = postsFP.write(
concat<Post>({ title: "lowdb is awesome", views: random(0, 5) })
);
// Find post by id
const post: Post | undefined = postsFP(find<Post>({ id: 1 }));
// Find top 5 fives posts
const popular: Post[] = postsFP([
sortBy<Post>("views") as PostsAction,
take(5) as PostsAction
]);
const filtered: Post[] = dbFP("posts")(filter<Post>({ published: true }));
const writeAction: Post[] = dbFP("posts").write(concat<Post>({ id: 123 }));
const writeAction2: string = dbFP(["user", "name"]).write(() => "typicode");
async () => {
const adapterAsync = new FileAsync<DbSchema>("test.json");
const dbAsyncPromise = lowfp(adapterAsync);
const dbAsync = await dbAsyncPromise;
const postsWithDefault = dbAsync("posts", [{ title: "baz" }] as Post[]);
const func: Promise<Post[]> = postsWithDefault.write(post => [
...post,
{ title: "another" }
]);
};
type PostsAction = (posts: Post[]) => Post[];
};
示例4: test
test('Test Basic functionality', async () => {
expect(
sortBy(
'name',
formatIndexFields(
[mockAuditbeatIndexField, mockFilebeatIndexField, mockPacketbeatIndexField],
['auditbeat', 'filebeat', 'packetbeat']
)
)
).toEqual(
sortBy('name', [
{
aggregatable: true,
category: 'base',
description:
'Date/time when the event originated. For log events this is the date/time when the event was generated, and not when it was read. Required field for all events.',
example: '2016-05-23T08:05:34.853Z',
indexes: ['auditbeat', 'filebeat', 'packetbeat'],
name: '@timestamp',
searchable: true,
type: 'date',
},
{
aggregatable: true,
category: 'agent',
description:
'Ephemeral identifier of this agent (if one exists). This id normally changes across restarts, but `agent.id` does not.',
example: '8a4f500f',
indexes: ['auditbeat'],
name: 'agent.ephemeral_id',
searchable: true,
type: 'string',
},
{
aggregatable: true,
category: 'agent',
indexes: ['filebeat'],
name: 'agent.hostname',
searchable: true,
type: 'string',
},
{
aggregatable: true,
category: 'agent',
description:
'Unique identifier of this agent (if one exists). Example: For Beats this would be beat.id.',
example: '8a4f500d',
indexes: ['packetbeat'],
name: 'agent.id',
searchable: true,
type: 'string',
},
{
aggregatable: true,
category: 'agent',
description:
'Name of the agent. This is a name that can be given to an agent. This can be helpful if for example two Filebeat instances are running on the same host but a human readable separation is needed on which Filebeat instance data is coming from. If no name is given, the name is often left empty.',
example: 'foo',
indexes: ['auditbeat', 'filebeat'],
name: 'agent.name',
searchable: true,
type: 'string',
},
{
aggregatable: true,
category: 'agent',
description:
'Type of the agent. The agent type stays always the same and should be given by the agent used. In case of Filebeat the agent would always be Filebeat also if two Filebeat instances are run on the same machine.',
example: 'filebeat',
indexes: ['auditbeat', 'packetbeat'],
name: 'agent.type',
searchable: true,
type: 'string',
},
{
aggregatable: true,
category: 'agent',
description: 'Version of the agent.',
example: '6.0.0-rc2',
indexes: ['auditbeat', 'filebeat'],
name: 'agent.version',
searchable: true,
type: 'string',
},
])
);
});
示例5: postprocessGroupPVJSON
.map(function(
groupedEntities: (PvjsonSingleFreeNode | PvjsonEdge)[]
): PvjsonGroup {
const pvjsonGroup = postprocessGroupPVJSON(
groupedEntities,
pvjsonEntity
);
const graphIdToZIndex = processor.graphIdToZIndex;
pvjsonGroup.contains = sortBy(
[
function(thisEntityId) {
return graphIdToZIndex[thisEntityId];
}
],
groupedEntities.map(x => x.id)
);
const { id, x, y } = pvjsonGroup;
const groupedEntitiesFinal = groupedEntities.map(function(
groupedEntity
) {
if (isPvjsonEdge(groupedEntity)) {
groupedEntity.points = map(function(point) {
point.x -= x;
point.y -= y;
return point;
}, groupedEntity.points);
} else if (isPvjsonSingleFreeNode(groupedEntity)) {
groupedEntity.height;
groupedEntity.x -= x;
groupedEntity.y -= y;
} else {
return hl.fromError(
new Error(
`
Encountered unexpected entity
${JSON.stringify(groupedEntity, null, " ")}
in Group
${JSON.stringify(pvjsonGroup, null, " ")}
`
)
);
}
// NOTE: this is needed for GPML2013a, because GPML2013a uses both
// GroupId/GroupRef and GraphId/GraphRef. GPML2017 uses a single
// identifier per entity. That identifier can be referenced by
// GroupRef and/or GraphRef. Pvjson follows GPML2017 in this, so
// we convert from GPML2013a format:
// GroupRef="GROUP_ID_VALUE"
// to pvjson format:
// {isPartOf: "GRAPH_ID_VALUE"}
groupedEntity.isPartOf = id;
return omit(["groupRef"], groupedEntity);
});
groupedEntitiesFinal.forEach(function(pvjsonEntity) {
setPvjsonEntity(pvjsonEntity);
});
setPvjsonEntity(pvjsonGroup);
processor.output = iassign(
processor.output,
function(o) {
return o.pathway.contains;
},
function(contains) {
return insertEntityIdAndSortByZIndex(
difference(contains, groupedEntitiesFinal.map(x => x["id"])),
id
);
}
);
return pvjsonGroup;
})