Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/licht1stein/clj-fstring
Clojure implemenation of Python's f-string syntax
https://github.com/licht1stein/clj-fstring
Last synced: about 2 months ago
JSON representation
Clojure implemenation of Python's f-string syntax
- Host: GitHub
- URL: https://github.com/licht1stein/clj-fstring
- Owner: licht1stein
- License: epl-1.0
- Created: 2021-11-16T12:29:33.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-07-29T13:41:43.000Z (over 2 years ago)
- Last Synced: 2024-10-28T13:42:11.069Z (2 months ago)
- Language: Clojure
- Size: 25.4 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# clj-fstring
[![Clojars Version](https://img.shields.io/clojars/v/com.github.blasterai/clj-fstring)](https://clojars.org/com.github.blasterai/clj-fstring)Python's f-string for Clojure!
After switching to Clojure the only thing I really missed was the f-string syntax. Remember?
```python
name = "John Smith"
print(f'Hello, {name}!')
>>> Hello, John Smith!
```Real handy. So as an excercise, I made the same for Clojure:
```clojure
(require [blaster.clj-fstring :refer [f-str]])(def who "John Smith")
(f-str "Hello, {who}!") ;; => "Hello, John Smith!"
````f-string` has no dependencies, only the standard library.
## Installation
You can install from [Clojars](https://clojars.org/com.github.blasterai/clj-fstring):
```clojure
{com.github.blasterai/clj-fstring {:mvn/version "1.1.1"}}
```## Usage
Some examples, including escape syntax:
```clojure
(require [blaster.clj-fstring :refer [f-str]](def who "John Smith")
(f-str "Hello, {who}!") ;; => "Hello, John Smith!";; It also works with arbitrary expressions
(f-str "1 + 1 = {(+ 1 2)}") ;; => "1 + 1 = 3";; And it has a simple escape syntax in case you actually need the curly brackets
(f-str "This is not evaluated '{spam}");; => "This is not evaluated {spam}"(let [where "Sparta"]
(f-str "This is {where}!"))
```## Development
Run the project's tests (they'll fail until you edit them):
$ clojure -T:build test
Lint with Eastwood:
$ clojure -T:build eastwood
Build a deployable jar of this library:
$ clojure -T:build ci
Bump version:
$ clojure -T:build bump-version :bump :patch
Deploy to Clojars:
$ clojure -T:build deploy
Your library will be deployed to com.github.blasterai/clj-fstring.
## License
Copyright © 2021 blaster.ai
Distributed under the Eclipse Public License version 1.0.