ramda#ascend TypeScript Examples

The following examples show how to use ramda#ascend. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From reskript with MIT License 7 votes vote down vote up
drawAssetReport = (assets: Asset[]) => {
    const toTemplateData = (asset: Asset) => {
        const config = getExtensionConfig(path.extname(asset.name));
        return {
            name: asset.name,
            color: config.color,
            typeOrder: config.order,
            size: (asset.size / 1024).toFixed(2) + 'KB',
            sizeInBytes: asset.size,
            indicator: asset.initial ? 'initial' : '',
        };
    };
    const templateSegments = sortWith(
        [
            ascend(data => data.typeOrder),
            ascend(data => (data.indicator === 'initial' ? 0 : 1)),
            ascend(asset => asset.name),
        ],
        uniqBy(v => v.name, assets).map(toTemplateData)
    );
    const maxNameLength = templateSegments.map(segment => segment.name.length).reduce((x, y) => Math.max(x, y), 0);
    const maxSizeLength = templateSegments.map(segment => segment.size.length).reduce((x, y) => Math.max(x, y), 0);
    for (const {color, name, size, indicator} of templateSegments) {
        logger.log(kolorist[color](`${name.padStart(maxNameLength)} ${size.padEnd(maxSizeLength)} ${indicator}`));
    }
}