本文整理匯總了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;
})