Skip to content

Releases: ZiadMansourM/fstr

LTS Version

05 Jan 18:24
Compare
Choose a tag to compare

fstr v1.0.0 LTS

We are excited to announce the first stable release of fstr - v1.0.0! After rigorous testing, numerous enhancements, and valuable community feedback, fstr is now mature and robust, providing a comprehensive string interpolation and formatting solution inspired by Python's f-strings, tailored for the Go community.

🚀 What's New in v1.0.0?

Stable and Robust: fstr v1.0.0 marks a milestone in reliability and stability. With an extensive suite of tests and refined error handling, you can trust fstr for critical and complex string manipulation tasks in your production applications.

Enhanced Number Formatting: Improved the precision and formatting capabilities of numbers, ensuring accurate representation for financial, scientific, and other precision-sensitive applications.

Extended Syntax Support: Introducing a shorthand notation {key=} for easier key-value pair generation, ideal for creating query strings, configuration files, or detailed reports.

Performance Optimizations: Under-the-hood enhancements to make fstr faster and more efficient, ensuring minimal impact on application performance even in high-load scenarios.

Community-Driven Features: Incorporating feedback and requested features from our users to make fstr more intuitive and powerful.

🌟 Features at a Glance

  1. Simple and Formatted Placeholders: Replace {key} or {key:.2f} with values, supporting various formatting options.
  2. Custom Formatting: Versatile formatNumber function for complex numeric representations.
  3. Error Handling: Explicit error reporting for robust application development.
  4. Convenience Wrappers: Quick and panic-free string interpolation with Eval.
  5. Extended Syntax: New {key=} syntax for streamlined key-value pair generation.
  6. Improved Precision: Accurate number formatting for all your precision needs.

💡 Example Usage

// Using fstr in your Go application
fmt.Println(fstr.Eval(
    "Welcome, {name}! Balance: {balance:,.2f} USD.",
    map[string]interface{}{
        "name":    "Alex",
        "balance": 98765.432,
    },
))

📝 Release Checklist

  • Extensive Testing and QA.
  • Continuous Integration and Automated Builds.
  • Documentation and Examples Updated.
  • Community Feedback Incorporated.

⏩ Next Steps

As we celebrate the release of fstr 1.0, we are already looking forward to the next enhancements, including more customization options, performance tweaks, and additional utility functions. Stay tuned!

🙏 Acknowledgments

A huge thank you to all the contributors, users, and supporters of fstr who have made this milestone possible. Your insights, feedback, and encouragement have been invaluable.


Embrace the power of string formatting in Go with fstr v1.0.0. Happy coding!

Production Ready Release

31 Dec 10:04
cdca18f
Compare
Choose a tag to compare

The fstr package v0.1.0 provides a robust string interpolation utility inspired by Python's f-strings, suitable for dynamic text generation. Here are the summarized features:

  1. Interpolate Function:
  • Simple Placeholders: Substitute {key} with the value of key from the provided data map.
  • Formatted Placeholders: Replace {key:.2f} with the value of key formatted according to the specifier, supporting both decimal precision (e.g., .2f) and thousands separator (e.g., :,).
  1. Custom Formatting Function (formatNumber):
  • Handles both decimal precision and thousands separators in one function.
  • Supports mixed formatting (e.g., {value:,.2f}) for numbers, providing flexibility in number representation.
  1. Error Handling:
  • Interpolate returns a formatted string or an explicit error if template parsing or execution fails, allowing for robust error handling in applications.
  1. Convenience Wrapper (Eval):
  • For scenarios where error handling isn't critical, Eval provides a straightforward way to perform string interpolation, panicking if an error occurs. It's ideal for quick scripts or applications where the format string and data are known not to cause errors.
  1. Extended Syntax Support:
  • In addition to traditional placeholders, the package now supports a new syntax {key=} which is effectively a shorthand notation for {key}={value} within the template, useful for generating query parameters, configuration files, or other scenarios where key-value pairs are needed in the output.
  1. Improved Precision Handling:
  • The formatNumber function has been enhanced to handle floating-point rounding more accurately, ensuring that numbers are represented as expected in the output.
  1. Usage Simplicity:
  • With just a single line of code using fstr.Eval or fstr.Interpolate, complex and dynamic strings can be generated, making the package extremely easy to integrate and use in various Go applications.

Example Usage:

// Standard interpolation with formatting
fmt.Println(fstr.Eval(
    "Hello, {name}! This is {person} {age} years old. With {balance:,.2f} USD in the bank. With GPA of {gpa:.2f}.",
    map[string]interface{}{
        "name":    "World",
        "person":  "John Doe",
        "age":     23,
        "balance": 123456789.64789,
        "gpa":     3.57869,
    },
))

// Extended syntax for key-value pairing
fmt.Println(fstr.Eval(
    "{name=} {age=} {gpa=:,.2f} {total=:,.3f}",
    map[string]interface{}{
        "name":  "Ziad Mansour",
        "age":   23,
        "gpa":   3.1495,
        "total": 123456789.9787968,
    },
))
ziadh@Ziads-MacBook-Air main % go run main.go
Hello, World! This is John Doe 23 years old. With 123,456,789.65 USD in the bank. With GPA of 3.58.

name=Ziad Mansour age=23 gpa=3.15 total=123,456,789.979

With these features and enhancements, fstr v0.1.0 offers a flexible and powerful tool for handling a wide range of string formatting and interpolation tasks, promoting code efficiency and readability.

📝 ToDo Checklist

  • Well tested.
  • Automate build and test on push.
  • Supports nearly all features which f-strings in python support.

First Production Ready Release

30 Dec 19:30
Compare
Choose a tag to compare
Pre-release

The fstr package v0.0.6 provides a robust string interpolation utility inspired by Python's f-strings, suitable for dynamic text generation. Here are the summarized features:

  1. Interpolate Function:
  • Simple Placeholders: Substitute {key} with the value of key from the provided data map.
  • Formatted Placeholders: Replace {key:.2f} with the value of key formatted according to the specifier, supporting both decimal precision (e.g., .2f) and thousands separator (e.g., :,).
  1. Custom Formatting Function (formatNumber):
  • Handles both decimal precision and thousands separators in one function.
  • Supports mixed formatting (e.g., {value:,.2f}) for numbers, providing flexibility in number representation.
  1. Error Handling:
  • Interpolate returns a formatted string or an explicit error if template parsing or execution fails, allowing for robust error handling in applications.
  1. Convenience Wrapper (Eval):
  • For scenarios where error handling isn't critical, Eval provides a straightforward way to perform string interpolation, panicking if an error occurs. It's ideal for quick scripts or applications where the format string and data are known not to cause errors.
  1. Extended Syntax Support:
  • In addition to traditional placeholders, the package now supports a new syntax {key=} which is effectively a shorthand notation for {key}={value} within the template, useful for generating query parameters, configuration files, or other scenarios where key-value pairs are needed in the output.
  1. Improved Precision Handling:
  • The formatNumber function has been enhanced to handle floating-point rounding more accurately, ensuring that numbers are represented as expected in the output.
  1. Usage Simplicity:
  • With just a single line of code using fstr.Eval or fstr.Interpolate, complex and dynamic strings can be generated, making the package extremely easy to integrate and use in various Go applications.

Example Usage:

// Standard interpolation with formatting
fmt.Println(fstr.Eval(
    "Hello, {name}! This is {person} {age} years old. With {balance:,.2f} USD in the bank. With GPA of {gpa:.2f}.",
    map[string]interface{}{
        "name":    "World",
        "person":  "John Doe",
        "age":     23,
        "balance": 123456789.64789,
        "gpa":     3.57869,
    },
))

// Extended syntax for key-value pairing
fmt.Println(fstr.Eval(
    "{name=} {age=} {gpa=:,.2f} {total=:,.3f}",
    map[string]interface{}{
        "name":  "Ziad Mansour",
        "age":   23,
        "gpa":   3.1495,
        "total": 123456789.9787968,
    },
))
ziadh@Ziads-MacBook-Air main % go run main.go
Hello, World! This is John Doe 23 years old. With 123,456,789.65 USD in the bank. With GPA of 3.58.

name=Ziad Mansour age=23 gpa=3.15 total=123,456,789.979

With these features and enhancements, fstr v0.0.6 offers a flexible and powerful tool for handling a wide range of string formatting and interpolation tasks, promoting code efficiency and readability.

First Enhanced Stable Version

30 Dec 17:58
Compare
Choose a tag to compare
Pre-release
  • Added support for the following.
package main

import (
	"fmt"

	"github.com/ZiadMansourM/fstr"
)

func main() {
    fmt.Println(fstr.Interpolate(
        "Hello, {name}! This is {person} {age} years old. With {balance:,.2f} USD in the bank. With GPA of {gpa:.2f}.",
        map[string]interface{}{
	    "name":    "World",
	    "person":  "John Doe",
	    "age":     23,
	    "balance": 123456789.64789,
	    "gpa":     3.57869,
        },
    ))
}

Output

ziadh@Ziads-MacBook-Air test % go run main.go
Hello, World! This is John Doe 23 years old. With 123,456,789.65 USD in the bank. With GPA of 3.58. <nil>
  • Add support for:
f"{name=}"

First Stable Version

30 Dec 17:44
Compare
Choose a tag to compare
First Stable Version Pre-release
Pre-release
  • Added support for the following.
data := map[string]interface{}{
    "name":    "John Doe",
    "age":     42,
    "balance": 123456789.111,
    "sum":     123456789,
    "gpa":     3.1657,
    "total":   123456789.9787968,
}
format := "{name} - {age} - {balance:,} - {gpa:.4f} - {total:,.3f} - {sum:,}"
// Output: John Doe - 42 - 123,456,789 - 3.1657 - 123,456,789.979 - 123,456,789
  • Add support for:
f"{name=}"

Formatted Placeholders

30 Dec 12:59
Compare
Choose a tag to compare
Pre-release
  • Added support for formatted placeholders.
  • Add support for:
$  ⁠f"Your class work grade is {total:,}"
$  ⁠⁠f"{name=}"

Hopeful start

30 Dec 11:20
ef0704e
Compare
Choose a tag to compare
Hopeful start Pre-release
Pre-release
  • Simplify import.
import (fstr "github.com/ZiadMansourM/fstr/Interpolate")

now became

import "github.com/ZiadMansourM/fstr"
  • Add tests.
package fstr

import "testing"

func TestInterpolate(t *testing.T) {
	tests := []struct {
		name   string
		format string
		data   map[string]interface{}
		want   string
	}{
		{
			name:   "Simple interpolation",
			format: "My name is {name} and I am {age} years old.",
			data: map[string]interface{}{
				"name": "Ziad Mansour",
				"age":  23,
			},
			want: "My name is Ziad Mansour and I am 23 years old.",
		},
		// Add more test cases as needed here.
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := Interpolate(tt.format, tt.data)
			if err != nil {
				t.Errorf("Interpolate() error = %v", err)
				return
			}
			if got != tt.want {
				t.Errorf("Interpolate() = %v, want %v", got, tt.want)
			}
		})
	}
}
  • Add support for more features.
$⁠  ⁠f"Hello Mr. {name}"
$  ⁠f"Your class work grade is {total:,.2f}"
$  ⁠⁠f"{name=}"

First Working Version

30 Dec 10:54
Compare
Choose a tag to compare
First Working Version Pre-release
Pre-release
  • Simplify import.
import (fstr "github.com/ZiadMansourM/fstr/Interpolate")
  • Add support for more features.
$⁠  ⁠f"Hello Mr. {name}"
$  ⁠f"Your class work grade is {total:,.2f}"
$  ⁠⁠f"{name=}"