lookbook/vendor/github.com/mfridman/interpolate/README.md
soup fc625fb9cf
Initial lookbook implementation
Pinterest-style visual bookmarking app with:
- URL metadata extraction (OG/Twitter meta, oEmbed fallback)
- Image caching in Postgres with 480px thumbnails
- Multi-tag filtering with Ctrl/Cmd for OR mode
- Fuzzy tag suggestions and inline tag editing
- Browser console auth() with first-use password setup
- Brutalist UI with Commit Mono font and Pico CSS
- Light/dark mode via browser preference
2026-01-16 21:14:23 -05:00

3.1 KiB

Interpolate

Build Status Go Reference Go Report Card

A Go library for parameter expansion (like ${NAME} or $NAME) in strings from environment variables. An implementation of POSIX Parameter Expansion, plus some other basic operations that you'd expect in a shell scripting environment like bash.

Installation

go get github.com/mfridman/interpolate@latest

Usage

package main

import (
  "github.com/mfridman/interpolate"
  "fmt"
)

func main() {
  env := interpolate.NewSliceEnv([]string{
    "NAME=James",
  })

  output, _ := interpolate.Interpolate(env, "Hello... ${NAME} welcome to the ${ANOTHER_VAR:-🏖}")

  fmt.Println(output)
  // Output: Hello... James welcome to the 🏖
}

Supported Expansions

  • ${parameter} or $parameter

    • Use value. If parameter is set, then it shall be substituted; otherwise, it will be blank
  • ${parameter:-[word]}

    • Use default values. If parameter is unset or null, the expansion of word (or an empty string if word is omitted) shall be substituted; otherwise, the value of parameter shall be substituted.
  • ${parameter-[word]}

    • Use default values when not set. If parameter is unset, the expansion of word (or an empty string if word is omitted) shall be substituted; otherwise, the value of parameter shall be substituted.
  • ${parameter:[offset]}

    • Use the substring of parameter after offset. A negative offset must be separated from the colon with a space, and will select from the end of the string. If the value is out of bounds, an empty string will be substituted.
  • ${parameter:[offset]:[length]}

    • Use the substring of parameter after offset of given length. A negative offset must be separated from the colon with a space, and will select from the end of the string. If the offset is out of bounds, an empty string will be substituted. If the length is greater than the length then the entire string will be returned.
  • ${parameter:?[word]}

    • Indicate Error if Null or Unset. If parameter is unset or null, the expansion of word (or a message indicating it is unset if word is omitted) shall be returned as an error.

Prior work

This repository is a fork of buildkite/interpolate. I'd like to thank the authors of that library for their work. I've forked it to make some changes that I needed for my own use cases, and to make it easier to maintain. I've also added some tests and documentation.

License

Licensed under MIT license, in LICENSE.