{"id":18990185,"url":"https://github.com/cheesegrinder/templatestr-python","last_synced_at":"2025-10-05T20:12:56.967Z","repository":{"id":118776044,"uuid":"393150273","full_name":"CheeseGrinder/TemplateStr-Python","owner":"CheeseGrinder","description":"TemplateStr allows to add variable, function, condition and switch in a string.","archived":false,"fork":false,"pushed_at":"2025-03-16T15:07:30.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-16T16:20:53.838Z","etag":null,"topics":["parser","python","strings"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CheeseGrinder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-05T19:24:45.000Z","updated_at":"2025-03-16T15:07:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"ace42fc1-a290-4485-9459-59dd2b721d0f","html_url":"https://github.com/CheeseGrinder/TemplateStr-Python","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/CheeseGrinder/TemplateStr-Python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CheeseGrinder","download_url":"https://codeload.github.com/CheeseGrinder/TemplateStr-Python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CheeseGrinder%2FTemplateStr-Python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278510944,"owners_count":25999011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","python","strings"],"created_at":"2024-11-08T17:09:09.200Z","updated_at":"2025-10-05T20:12:56.961Z","avatar_url":"https://github.com/CheeseGrinder.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n    \u003ch1\u003eTemplateStr-Python\u003c/h1\u003e\n    \u003ch3\u003eTemplateStr allows to add variable, function, condition and switch in a string.\u003c/h3\u003e\n    \u003cimg src=\"https://img.shields.io/badge/Python-v3.8%5E-green?style=flat-square\u0026logo=python\u0026logoColor=ffd13e\u0026color=3470a2\"/\u003e\n    \u003ca href=\"https://github.com/CheeseGrinder/TemplateStr-Python/actions/workflows/python-app.yml\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/CheeseGrinder/TemplateStr-Python/python_test.yml?label=Test\u0026style=flat-square\"/\u003e\n    \u003c/a\u003e\n\u003c/div\u003e\n\n### Install :\n\n```\npip install https://github.com/CheeseGrinder/TemplateStr-Python/archive/vX.X.X.tar.gz\n```\n\n### Import :\n\n```python\nfrom templateStr import TemplateStr\n```\n\n### Construtor :\n\n```python\nparser = TemplateStr(functionList: list, variableDict: dict)\n```\n\n\u003cul\u003e\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003efunctionList\u003c/code\u003e: is an list of functions passed to the constructor that can be called in the parsed text\u003c/summary\u003e\u003cbr\u003e\n\n```python\nfuncs: list = [meCustomFunc, otherCustomFunc]\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003ccode\u003evariableDict\u003c/code\u003e: is a dict of variables passed to the constructor that can be used in the parsed text\u003c/summary\u003e\u003cbr\u003e\n\n```python\nvarDict: dict = {\n    \"foo\": \"bar\",\n    \"str\": \"Jame\",\n    \"int\": 32,\n    \"float\": 4.2,\n    \"bool\": True,\n    \"list\": [\"test\", 42],\n    \"Dict\": {\"value\": \"Dict in Dict\"},\n    \"Dict1\": {\"Dict2\": {\"value\": \"Dict in Dict in Dict\"}},\n}\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\n### Function :\n\n```python\nparser.parse(text)\n```\n\n- `parse(text: str) -\u003e str` : parse all (variable, function, condition and switch)\n- `parseVariable(text: str) -\u003e str` : parse Variable ; ${variableName}\n- `parseFunction(text: str) -\u003e str` : parse Function and Custom Function ; @{functionName}\n- `parseCondition(text: str) -\u003e str` : parse Condition ; #{value1 == value2; trueValue | falseValue}\n- `parseSwitch(text: str) -\u003e str` : parse Switch ; ?{var; value1::#0F0, value2::#00F, ..., _::#000}\n- `hasOne(text: str) -\u003e bool` : check if there are one syntaxe\n- `hasVariable(text: str) -\u003e bool` : check if there are any Variable\n- `hasFunction(text: str) -\u003e bool` : check if there are any Function\n- `hasCondition(text: str) -\u003e bool` : check if there are any Condition\n- `hasSwitch(text: str) -\u003e bool` : check if there are any Switch\n\n### Exemple Syntaxe :\n\n\u003cul\u003e\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eVariable\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Variables is like :\n- `${variable}`\n- `${Map.value}`\n- `${MasterMap.SecondMap.value. ...}`\n- `${variable[0]}`\u003c/br\u003e\u003c/br\u003e\n\nIf the value does not exist an error is returned\n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"Jame\"\n\n\"name is ${name}\"\nparse()\n\"name is Jame\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eFunction\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Function is like : \n- `@{function; parameter}`\n- `@{function}`\u003c/br\u003e\u003c/br\u003e\n\nHere is a list of the basic functions available  :\n\n- `@{uppercase; variableName}`\n- `@{uppercaseFirst; variableName}`\n- `@{lowercase; variableName}`\n- `@{swapcase; variableName}`\n- `@{time}` HH/mm/ss\n- `@{date}` DD/MM/YYYY\n- `@{dateTime}` DD/MM/YYYY HH/mm/ss\u003c/br\u003e\u003c/br\u003e \n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"jame\"\n\n\"name is @{uppercase; name}\"\nparse()\n\"name is JAME\"\n//=================================\n\n\"what time is it ? it's @{time}\"\nparse()\n\"what time is it ? it's 15:30:29\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCustom Function\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of Custom function is the same as the basic functions, they can have 0,1 or more parameters : \n- `@{customFunction; param1 param2 variableName ...}`\n- `@{customFunction}`\u003c/br\u003e\u003c/br\u003e\n\nThe developer who adds his own function will have to document it\n\n`Syntaxe Typing` can be used at the parameter level of custom functions\n\nFor developers :\n- Parameters to be passed in a `list/vec/array`\n- The custom function must necessarily return a `str/string`\u003c/br\u003e\u003c/br\u003e\n\n```python\ndef YourFunction(array: list) -\u003e str:\n\n    # Your code\n\n    return str\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eCondition\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Condition is like :\n- `#{value1 == value2; trueValue | falseValue}`\u003c/br\u003e\u003c/br\u003e\n  \ncomparator:\n- `==`\n- `!=`\n- `\u003c=` *\n- `\u003c` *\n- `\u003e=` *\n- `\u003e` *\n\u003c/br\u003e\u003c/br\u003e\n\u003cdetails\u003e\n\u003csummary\u003e* \u003ci\u003efor this comparator the type \u003ccode\u003estring\u003c/code\u003e and \u003ccode\u003ebool\u003c/code\u003e are modified\u003c/i\u003e :\u003c/summary\u003e\n\n- `string` it's the number of characters that is compared ('text' = 4)\n- `bool` it's the value in int that is compared (True = 1)\n\n\u003c/details\u003e\n\n`value1` is compared with `value2`\n\n`Syntaxe Typing` can be used at `value1` and `value2` level\n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"Jame\"\n\n\"Jame is equal to James ? #{name == 'James'; Yes | No}\"\nparse()\n\"Jame is equal to James ? No\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\n\u003cli\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eSwitch\u003c/strong\u003e\u003c/summary\u003e\n\u003c/br\u003e\n\nThe syntax of the Switch is like :\n- `?{variableName; value1::#0F0, value2::#00F, ..., _::#000}`\n- `?{type/variableName; value1::#0F0, value2::#00F, ..., _::#000}`\u003c/br\u003e\u003c/br\u003e\n\nThe value of `variableName` is compared with all the `values*`,\nif a `values*` is equal to the value of `variableName` then the value after the `::` will be returned.\u003c/br\u003e\nIf no `values*` matches, the value after `_::` is returned\n\nyou can specify the type of `variableName`, but don't use `Syntaxe Typing`.\u003c/br\u003e\nIf the type is specified then all `values*` will be typed with the same type.\n\nsyntax to specify the type of `variableName` :\n- `str/variableName`\n- `int/variableName`\n- `float/variableName`\u003c/br\u003e\u003c/br\u003e\n\n\u003c!-- V Be careful, it's not a \"go\" code, it's just to have some colour in the rendering --\u003e\n```go\n//Example of parsing | is not code\n\nname = \"Jame\"\nyearsOld = 36\n\n\"how old is Jame ? ?{name; Jame::42 years old, William::36 years old, _::I don't know}\"\nparse()\n\"how old is Jame ? 42 years old\"\n//=================================\n\n\"who at 36 years old ? ?{int/yearsOld; 42::Jame !, 36::William !, _::I don't know}\"\nparse()\n\"who at 42 years old ? William !\"\n```\n\n\u003c/details\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\n### Syntaxe Typing :\n\n| Format                       | Type    | Return                 | Note                                                                    |\n|------------------------------|---------|------------------------|-------------------------------------------------------------------------|\n| variableName                 | `*`     | value of `variableName`| Is the key of the value in the dictionary pass to the constructor       |\n| b/True                       | `bool`  | True                   | Type the string True as `bool`                                          |\n| i/123                        | `int`   | 123                    | Type the string 123 as type `int`                                       |\n| f/123.4                      | `float` | 123.4                  | Type the string 123.4 as type `float`                                   |\n| \"text\" or 'text' or \\`text\\` | `str`   | text                   | It just takes what's in quote, not to be interpreted as a variable name |\n| (\"test\", i/56)               | `list`  | [test 56]              | Use typing for typed otherwise text will be used as variable name       |\n\n```diff\n\nThis function takes as parameters a Bool, Int and String\n+ @{MyCustomFunction; b/True i/15 \"foo\"}\n- @{MyCustomFunction; True 15 foo}\n\n\n+ #{\"test\" == \"test\"; Yes | No}\n+ #{\"56\" == i/56; Yes | No}\n- #{foo == 56; Yes | No}\n\n```\n\n### More\nIf you want another example you can look in the test file (`test_TemplateStr.py`)\n\n### TODO\n\n- [ ] : Add exemple\n- [x] : Add test\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesegrinder%2Ftemplatestr-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcheesegrinder%2Ftemplatestr-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcheesegrinder%2Ftemplatestr-python/lists"}