mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
33 lines
1.0 KiB
Go
33 lines
1.0 KiB
Go
package types
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/hanzoai/commerce/models/types/currency"
|
|
)
|
|
|
|
// DisplayPrice renders a price for a human: symbol, grouped thousands, the
|
|
// currency's own number of decimals ("$1,234.56", "¥10,000").
|
|
//
|
|
// This is the display funnel — every storefront, order and receipt string in
|
|
// commerce comes through here, so it holds no arithmetic of its own. The
|
|
// amount is rendered from the integer by money, which cannot round a cent away
|
|
// the way the float this used to compute could.
|
|
//
|
|
// A negative now renders "-$100.00" rather than the old "$-100.00": the sign
|
|
// belongs to the amount, not to the digits after the symbol, and a refund is
|
|
// the most common negative there is.
|
|
func DisplayPrice(t currency.Type, price currency.Cents) string {
|
|
return t.Amount(price).Display()
|
|
}
|
|
|
|
// Non-breaking hyphens in title
|
|
func DisplayTitle(title string) string {
|
|
return strings.Replace(title, "-", "‑", -1)
|
|
}
|
|
|
|
func SplitParagraph(text string) []string {
|
|
return regexp.MustCompile("\\n\\s*\\n").Split(text, -1)
|
|
}
|