Formats

Formats can be applied to properties in fundpress, and if specified will allow for data to be pre-formatted when emitted from the fundpress services. The format service relies upon two main libraries for its formatting - momentjs and numeraljs.

Parameter Value
End Point https://api.fundpress.io/config/addFormatCode
Headers X-KSYS-TOKEN
Content Type application/json
HTTP Method POST

The basic use of formats is to provide a single format rule, identified by a code, which will typically apply to a particular culture.

{
        "type": "DATE",
        "code": "date",
        "label": "standard date",
        "description": "standard date",
        "formatRules": [
            {
                "culture": "en-GB",
                "formatCode": "dd.MM.yyyy"
            }
        ]
}

IN the above case, we are specifying a simple dd.MM.yyyy format code for dates, applicable to data requested for users from en-GB. When applied to particular date data points, those dates will become formatted in this way when requested by a user in GB in English.

There are more sophisticated ways of formatting data too, allowing things such as prefixes and suffixes.

{
    "type": "Currency",
    "code": "ccy",
    "label": "standard ccy",
    "description": "standard ccy",
    "formatRules": [
        {
            "culture": "en-US",
            "formatCode": "0,0.00",
            "prefix":"$"
            "suffix":"USD"
        }
    ]
}

Furthermore, there is the ability to apply conditionals.

ltgte

In the example below, a less than, greater than or equal to operator has been used. In this instance, if the value breaches a certain threshold, a different format can be used. This is useful with very large numbers.

The format for the ltgte conditionals object is as follows:

"conditionals":[
    {
        "type":"ltgte",
        "boundary": number,
        "lt": string,
        "gte": string,
    }
]

In the example below, numbers over 1,000,000 would show as 1M.

{
    "type": "Currency",
    "code": "ccy",
    "label": "standard ccy",
    "description": "standard ccy",
    "formatRules": [
        {
            "culture": "en-US",
            "formatCode": "0,0.00",
            "conditionals":[
                {
                    "type":"ltgte",
                    "boundary":1000000,
                    "lt":"0,0.00",
                    "gte":"0.0a",
                }
            ]
        }
    ]
}

divideby

A divideby conditional will divide the number presented by a certain amount before formatting.

The format for the divideby conditionals object is as follows:

"conditionals":[
    {
        "type":"divideby",
        "by": number
    }
]

A full example is:

{
    "type": "percentage",
    "code": "perc",
    "label": "standard %",
    "description": "standard %",
    "formatRules": [
        {
            "culture": "en-GB",
            "formatCode": "0%",
            "conditionals":[
                {
                    "type":"divideby",
                    "by":100
                }
            ]
        }
    ]
}

labelOverride

A labelOverride conditional will change the format of a particular value based on the label it has associated with it. This is only used in allocations or statistics and their associated property definitions.

The format for the labelOverride conditionals object is as follows:

"conditionals":[
    {
        "type":"labelOverride",
        "labelrules":[
            {
                "label": string,
                "format": string
            }
        ]
    }
]

A full example is:

{
    "type": "percentage",
    "code": "perc",
    "label": "standard %",
    "description": "standard %",
    "formatRules": [
        {
            "culture": "en-GB",
            "formatCode": "0%",
            "conditionals":[
                {
                    "type":"labelOverride",
                    "labelrules":[
                        {
                            "label":"Average Duration",
                            "format":"0,0"
                        }
                    ]
                }
            ]
        }
    ]
}

valueOverride

A valueOverride conditional will change the actual returned value of a particular item based on the original value it has associated with it. This is useful for overriding things like zero values. This is only used in allocations or statistics and their associated property definitions.

The format for the valueOverride conditionals object is as follows:

"conditionals":[
    {
        "type": "valueOverride",
        "valueRules":[
            {
                "value": string,
                "format": string
            }
        ]
    }
]

A full example is:

{
    "type": "percentage",
    "code": "perc",
    "label": "standard %",
    "description": "standard %",
    "formatRules": [
        {
            "culture": "en-GB",
            "formatCode": "0%",
            "conditionals":[
                {
                    "type": "valueOverride",
                    "valueRules":[
                        {
                            "value": "0",
                            "format":"No Value Here!!!"
                        }
                    ]
                }
            ]
        }
    ]
}