Skip to content

Instantly share code, notes, and snippets.

@Geolykt
Created July 8, 2023 21:27
Show Gist options
  • Save Geolykt/9d5d798d95ed839429da2b8232dc87ed to your computer and use it in GitHub Desktop.
Save Geolykt/9d5d798d95ed839429da2b8232dc87ed to your computer and use it in GitHub Desktop.
# This configuration file is written in HOCON - HOCON syntax applies.
[
{
"name" : "Generic Currency",
"id": "eca:generic",
"uuid": "00000000-086a-b989-0000-000000526bc6", # This specific UUID marks your primary currency. This UUID must be considered constant.
# The supply attribute describes the format that should be used when formatting a currency
"supply": [
{
"priority": 1, # Higher priority means applied later. In this case the format with the lowest applicable priority scalar value is choosen.
"format": "%0.2fc",
"langauges": [
# Empty list means that it is applicable to any language
]
}
],
"accept": {
"transforms": [
{
"data": "false", # Reject input string by default (can also be 0)
"store": { "variable": "return", "as": "STRING", "via": "STORE" }
},{
"validFor": {
"patternMatches": "[0-9]+(?:[\.,][0-9]+)?[kKmMgGtTpP]?\s*[cC]",
"from": "input"
},
"data": "true" # Accept input string if condition applies
"store": { "variable": "return", "as": "STRING", "via": "STORE" }
}
]
},
"consumes": {
"pattern": "([0-9]+)(?:[\.,]([0-9]+))?([kKmMgGtTpP])?(?:\s*[cC])?",
"capture": [
{ "group": 1, "variable": "prePointDigits", "as": "STRING", "via": "STORE" },
{ "group": 2, "variable": "postPointDigits", "as": "STRING", "via": "STORE" },
{ "group": 3, "variable": "amplitude", "as": "STRING", "via": "STORE" }
],
"transforms": [
{
"concat": [ "{prePointDigits}", ".", "{postPointDigits}" ],
"store": { "variable": "return", "as": "DECIMAL", "via": "STORE" }
},
{
"validFor": {
"ifPresent": "amplitude"
}
"switch": {
"K": 1000,
"k": 1000,
"M": 1000000,
"m": 1000000,
"G": 1000000000,
"g": 1000000000,
"T": 1000000000000,
"t": 1000000000000,
"P": 1000000000000000,
"p": 1000000000000000
},
"from": "amplitude"
"store": { "variable": "return", "as": "DECIMAL", "via": "MULTIPLY" }
}
]
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment