# masterminds/sprig

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/masterminds-sprig).**

4,692 stars · 473 forks · Go · mit

## Links

- GitHub: https://github.com/Masterminds/sprig
- Homepage: http://masterminds.github.io/sprig/
- awesome-repositories: https://awesome-repositories.com/repository/masterminds-sprig.md

## Topics

`go` `template` `templates`

## Description

Sprig is a comprehensive library of helper functions designed to extend the Go text template engine. It provides a wide array of custom functions that can be injected into the engine to enable complex data manipulation and logic directly within templates.

The project offers specialized capabilities for cryptography, including the generation of private keys, X.509 certificates, and secure password hashes. It also includes advanced logic extensions for semantic versioning comparison, ternary evaluations, and the resolution of environment variables from the host operating system.

The library covers a broad surface of general-purpose utilities, including extensive string processing for case conversion and regular expressions, mathematical operations for floating-point and integer arithmetic, and temporal tools for date and time formatting. It further provides data structure management for deeply merging dictionaries, filtering lists, and encoding or decoding JSON.

The project is implemented as a function map that integrates with the standard Go template system.

## Tags

### Part of an Awesome List

- [Template Extensions](https://awesome-repositories.com/f/awesome-lists/devtools/template-extensions.md) — Extends the Go template engine with a comprehensive library of helper functions for data manipulation.
- [Structured Data Format Converters](https://awesome-repositories.com/f/awesome-lists/data/data-formats-and-parsing/structured-data-format-converters.md) — Converts dictionaries and lists into formatted JSON and other structured outputs within the template pipeline.
- [Math Utilities](https://awesome-repositories.com/f/awesome-lists/devtools/math-utilities.md) — Implements basic mathematical operations including sums, products, and maximums. ([source](http://masterminds.github.io/sprig/))
- [Regex Pattern Matching](https://awesome-repositories.com/f/awesome-lists/devtools/regex-and-pattern-matching/regex-pattern-matching.md) — Performs pattern matching, replacements, and string splitting using regular expressions. ([source](http://masterminds.github.io/sprig/strings.html))
- [JSON Parsing](https://awesome-repositories.com/f/awesome-lists/data/json-parsing.md) — Decodes JSON documents into usable data structures within templates. ([source](http://masterminds.github.io/sprig/defaults.html))

### Development Tools & Productivity

- [Custom Function Maps](https://awesome-repositories.com/f/development-tools-productivity/data-transformation/template-helpers/go-template-rendering/custom-function-maps.md) — Injects a custom map of Go functions into the template engine to provide helper capabilities.
- [Template Functions](https://awesome-repositories.com/f/development-tools-productivity/template-extensions/template-functions.md) — Provides a comprehensive set of reusable helper functions to extend logic and data manipulation within Go templates. ([source](https://cdn.jsdelivr.net/gh/masterminds/sprig@master/README.md))
- [Configuration File Generators](https://awesome-repositories.com/f/development-tools-productivity/configuration-generators/configuration-file-generators.md) — Generates configuration files by combining environment variables and conditional logic.
- [Date and Time Utilities](https://awesome-repositories.com/f/development-tools-productivity/date-and-time-utilities.md) — Provides comprehensive functions for transforming timestamps and date strings into specific layouts. ([source](http://masterminds.github.io/sprig/date.html))
- [Duration Calculations](https://awesome-repositories.com/f/development-tools-productivity/date-and-time-utilities/duration-calculations.md) — Computes elapsed time since a specific date and rounds durations for human-readable display. ([source](http://masterminds.github.io/sprig/date.html))
- [Date String Parsers](https://awesome-repositories.com/f/development-tools-productivity/date-and-time-utilities/relative-date-formatting/date-string-parsers.md) — Includes tools for parsing date strings using specific layouts to create date objects. ([source](http://masterminds.github.io/sprig/date.html))
- [Temporal Arithmetic](https://awesome-repositories.com/f/development-tools-productivity/date-and-time-utilities/temporal-arithmetic.md) — Allows adjusting timestamps by adding or subtracting time increments via modification strings. ([source](http://masterminds.github.io/sprig/date.html))
- [Date Formatting Utilities](https://awesome-repositories.com/f/development-tools-productivity/date-formatting-utilities.md) — Offers utilities to retrieve the current time and format timestamps into human-readable strings. ([source](http://masterminds.github.io/sprig/))
- [String Case Transformers](https://awesome-repositories.com/f/development-tools-productivity/string-case-transformers.md) — Converts strings between various naming conventions including camelCase, snake_case, and kebab-case. ([source](http://masterminds.github.io/sprig/strings.html))
- [Text Case Transformers](https://awesome-repositories.com/f/development-tools-productivity/string-case-transformers/text-case-transformers.md) — Transforms raw data into formatted text using casing, pluralization, and regular expression tools.
- [Cryptographic Helpers](https://awesome-repositories.com/f/development-tools-productivity/template-extensions/template-functions/cryptographic-helpers.md) — Ships specialized template functions for generating security credentials, hashes, and X.509 certificates.
- [Template Logic Controllers](https://awesome-repositories.com/f/development-tools-productivity/template-logic-controllers.md) — Implements conditional branching and logic helpers, such as ternary evaluations and semantic versioning checks, for templates.
- [Version Constraints](https://awesome-repositories.com/f/development-tools-productivity/version-constraints.md) — Implements logic to verify if a version string satisfies specific constraints or ranges. ([source](http://masterminds.github.io/sprig/semver.html))

### Data & Databases

- [Collection Manipulation Utilities](https://awesome-repositories.com/f/data-databases/collection-manipulation-utilities.md) — Provides a comprehensive toolkit for creating, sorting, filtering, and extracting values from lists and dictionaries. ([source](http://masterminds.github.io/sprig/))
- [Dictionary Copying](https://awesome-repositories.com/f/data-databases/data-dictionaries/dictionary-copying.md) — Creates independent deep copies of dictionaries to prevent unintended mutations. ([source](http://masterminds.github.io/sprig/dicts.html))
- [Data Manipulation Libraries](https://awesome-repositories.com/f/data-databases/data-manipulation-libraries.md) — Provides a toolkit for transforming structured data, including merging dictionaries and filtering lists, during template execution.
- [Numeric Extremum Identification](https://awesome-repositories.com/f/data-databases/numeric-fields/numeric-extremum-identification.md) — Identifies the largest or smallest integer from a given set of values. ([source](http://masterminds.github.io/sprig/math.html))
- [Language Runtime Type Inspection](https://awesome-repositories.com/f/data-databases/type-inspection-tools/language-runtime-type-inspection.md) — Provides reflection-based type inspection to retrieve or compare the underlying type of a value. ([source](http://masterminds.github.io/sprig/reflection.html))
- [Unique Identifier Generators](https://awesome-repositories.com/f/data-databases/data-management/unique-identifier-generators.md) — Generates randomly produced version 4 universally unique identifiers. ([source](http://masterminds.github.io/sprig/uuid.html))
- [Dictionary Manipulation Utilities](https://awesome-repositories.com/f/data-databases/key-value-pair-managers/nested-dictionary-utilities/dictionary-manipulation-utilities.md) — Enables retrieval of specific values from dictionaries using keys and deep traversal. ([source](http://masterminds.github.io/sprig/dicts.html))
- [Null Value Handling](https://awesome-repositories.com/f/data-databases/null-value-handling.md) — Provides fallback values for empty variables and handles null values within template logic. ([source](http://masterminds.github.io/sprig/))

### Programming Languages & Runtimes

- [Random Value Generators](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/core-conceptual-frameworks/programming-language-concepts/random-number-generation/animation-randomizers/random-value-generators.md) — Produces a random integer within a specified inclusive-minimum and exclusive-maximum range. ([source](http://masterminds.github.io/sprig/math.html))
- [Whitespace Removers](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/language-syntax/whitespace-based-block-scoping/whitespace-cleaners/whitespace-removers.md) — Implements functions to remove leading and trailing whitespace or specific characters from strings. ([source](http://masterminds.github.io/sprig/strings.html))
- [Merging Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structures/dictionaries/merging-utilities.md) — Implements logic for recursively combining nested maps with configurable precedence rules.
- [Extremum Finding](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-type-utilities/array-element-finding/extremum-finding.md) — Identifies the largest or smallest number from a series of floating-point values. ([source](http://masterminds.github.io/sprig/mathf.html))
- [String Manipulators](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/string-utilities/string-manipulators.md) — Provides utilities for splitting strings into lists or maps based on specific delimiters. ([source](http://masterminds.github.io/sprig/string_slice.html))
- [Runtime Type Introspection](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-type-introspection.md) — Returns the kind of an object to enable conditional logic within templates. ([source](http://masterminds.github.io/sprig/reflection.html))
- [Text Processing Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/text-templating-engines/text-processing-utilities.md) — Offers extensive text processing utilities for case conversion, regex operations, and date formatting within templates.
- [Dictionary Management Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/dictionary-management-utilities.md) — Implements core dictionary operations including key creation, updates, deletion, and existence checks. ([source](http://masterminds.github.io/sprig/dicts.html))
- [Environment Variable Resolution](https://awesome-repositories.com/f/programming-languages-runtimes/environment-variable-resolution.md) — Interfaces with the host operating system to retrieve and expand environment variables within templates.
- [List Filtering Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/list-filtering-utilities.md) — Includes capabilities to remove duplicates and strip empty entries from lists. ([source](http://masterminds.github.io/sprig/lists.html))
- [List Manipulation Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/list-manipulation-utilities.md) — Ships functions to append, prepend, concatenate, and slice immutable sequential lists. ([source](http://masterminds.github.io/sprig/lists.html))
- [List Query Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/list-query-utilities.md) — Provides utilities to retrieve the first, last, or remaining elements of a list. ([source](http://masterminds.github.io/sprig/lists.html))
- [List Transformation Utilities](https://awesome-repositories.com/f/programming-languages-runtimes/list-transformation-utilities.md) — Provides functions to reverse the sequence of elements or split lists into smaller chunks. ([source](http://masterminds.github.io/sprig/lists.html))
- [Key Filtering](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structures/dictionaries/key-filtering.md) — Provides logic for extracting a new dictionary containing only a specified subset of keys. ([source](http://masterminds.github.io/sprig/dicts.html))
- [Runtime Type Inspection](https://awesome-repositories.com/f/programming-languages-runtimes/runtime-type-inspection.md) — Includes functions to identify the underlying type or kind of a variable at runtime. ([source](http://masterminds.github.io/sprig/))

### Scientific & Mathematical Computing

- [Rounding Utilities](https://awesome-repositories.com/f/scientific-mathematical-computing/absolute-value-computations/rounding-utilities.md) — Adjusts floating-point values using rounding, flooring, and ceiling operations to a specific precision. ([source](http://masterminds.github.io/sprig/math.html))
- [Floating Point Arithmetic](https://awesome-repositories.com/f/scientific-mathematical-computing/floating-point-arithmetic.md) — Executes fundamental arithmetic operations including addition and division on floating-point numbers. ([source](http://masterminds.github.io/sprig/mathf.html))

### Security & Cryptography

- [Cryptography Libraries](https://awesome-repositories.com/f/security-cryptography/cryptography-libraries.md) — Wraps Go's standard cryptography and encoding packages to provide high-level hashing and encryption functions.
- [Binary-to-Text Encodings](https://awesome-repositories.com/f/security-cryptography/binary-to-text-encodings.md) — Converts text into Base64 or Base32 formats and back again. ([source](http://masterminds.github.io/sprig/encoding.html))
- [Certificate Management](https://awesome-repositories.com/f/security-cryptography/certificate-management.md) — Provides capabilities for generating self-signed and CA-signed X.509 certificates. ([source](http://masterminds.github.io/sprig/crypto.html))
- [Cryptographic Operations](https://awesome-repositories.com/f/security-cryptography/cryptographic-operations.md) — Implements cryptographic primitives for generating private keys, hashing data, and deriving secure passwords. ([source](http://masterminds.github.io/sprig/))
- [Cryptographic Random Number Generators](https://awesome-repositories.com/f/security-cryptography/cryptographic-random-number-generators.md) — Creates cryptographically secure random strings using alphanumeric or ASCII character sets. ([source](http://masterminds.github.io/sprig/strings.html))
- [Encryption](https://awesome-repositories.com/f/security-cryptography/encryption.md) — Implements AES-256 CBC encryption to transform plain text into base64 encoded strings. ([source](http://masterminds.github.io/sprig/crypto.html))
- [Algorithm-Driven Key Generation](https://awesome-repositories.com/f/security-cryptography/key-generation-templates/algorithm-driven-key-generation.md) — Produces new private keys encoded in PEM blocks using various cryptographic algorithms. ([source](http://masterminds.github.io/sprig/crypto.html))
- [Credential Generation](https://awesome-repositories.com/f/security-cryptography/secure-randomizers/password-generators/credential-generation.md) — Produces random UUIDs, private keys, and password hashes for secure system initialization.
- [Cryptographic Hash Computations](https://awesome-repositories.com/f/security-cryptography/security/cryptography-and-secrets/cryptographic-primitives-management/cryptographic-hash-computations.md) — Calculates message digests and checksums using standard algorithms like SHA256 and bcrypt. ([source](http://masterminds.github.io/sprig/crypto.html))
- [Password Hash Generators](https://awesome-repositories.com/f/security-cryptography/security/cryptography-and-secrets/cryptographic-primitives-management/password-hashing-utilities/password-hash-generators.md) — Generates secure password hashes for authentication using bcrypt and SHA algorithms. ([source](http://masterminds.github.io/sprig/crypto.html))

### Software Engineering & Architecture

- [Deep Equality Comparison](https://awesome-repositories.com/f/software-engineering-architecture/deep-equality-comparison.md) — Determines if two non-primitive data structures are deeply equal by value. ([source](http://masterminds.github.io/sprig/reflection.html))
- [Integer Arithmetic](https://awesome-repositories.com/f/software-engineering-architecture/integer-arithmetic.md) — Calculates sums and products using a series of integer inputs. ([source](http://masterminds.github.io/sprig/math.html))
- [Text Block Formatting](https://awesome-repositories.com/f/software-engineering-architecture/string-formatting-utilities/content-format-transformers/text-block-formatting.md) — Formats text blocks by wrapping content at specific widths or adding indentation. ([source](http://masterminds.github.io/sprig/strings.html))
- [String Manipulators](https://awesome-repositories.com/f/software-engineering-architecture/string-manipulators.md) — Concatenates multiple strings, replaces characters, and wraps text in quotes. ([source](http://masterminds.github.io/sprig/strings.html))
- [Environment Variable Injection](https://awesome-repositories.com/f/software-engineering-architecture/application-lifecycle-management/configuration-management/environment-variable-management/environment-variable-injection.md) — Injects operating system environment variables into strings using template syntax. ([source](http://masterminds.github.io/sprig/os.html))
- [First Non-Empty Selection](https://awesome-repositories.com/f/software-engineering-architecture/conditional-branching/conditional-expression-returns/conditional-value-selection/first-non-empty-selection.md) — Scans a list of provided values and returns the first one that is not empty. ([source](http://masterminds.github.io/sprig/defaults.html))
- [Fallback Value Logic](https://awesome-repositories.com/f/software-engineering-architecture/default-configuration-values/fallback-value-logic.md) — Returns a fallback value if the provided input is empty, null, or zero. ([source](http://masterminds.github.io/sprig/defaults.html))
- [Pluralization Rules](https://awesome-repositories.com/f/software-engineering-architecture/localization/pluralization-rules.md) — Provides logic to select different string representations based on integer counts for singular and plural forms. ([source](http://masterminds.github.io/sprig/strings.html))
- [Empty Value Validations](https://awesome-repositories.com/f/software-engineering-architecture/runtime-value-validation/empty-value-validations.md) — Evaluates whether various data types are empty or non-empty based on their zero-value state.
- [Multi-Value Emptiness Checks](https://awesome-repositories.com/f/software-engineering-architecture/runtime-value-validation/empty-value-validations/multi-value-emptiness-checks.md) — Checks a list of values to determine if all or any are non-empty. ([source](http://masterminds.github.io/sprig/defaults.html))
- [Lexicographical Sorting](https://awesome-repositories.com/f/software-engineering-architecture/string-manipulators/lexicographical-sorting.md) — Arranges lists of strings into lexicographical order. ([source](http://masterminds.github.io/sprig/string_slice.html))
- [String Joining](https://awesome-repositories.com/f/software-engineering-architecture/string-manipulators/string-joining.md) — Combines multiple string elements into a single string using a specified separator. ([source](http://masterminds.github.io/sprig/string_slice.html))
- [Content Analysis](https://awesome-repositories.com/f/software-engineering-architecture/string-processing-algorithms/content-analysis.md) — Checks if strings contain specific substrings or start and end with certain characters. ([source](http://masterminds.github.io/sprig/strings.html))

### Web Development

- [URL Construction](https://awesome-repositories.com/f/web-development/url-construction.md) — Assembles structured URL strings from a map of components. ([source](http://masterminds.github.io/sprig/url.html))
- [URL Data Parsing](https://awesome-repositories.com/f/web-development/url-data-parsing.md) — Deconstructs raw URL strings into structured dictionaries of their constituent parts. ([source](http://masterminds.github.io/sprig/url.html))
- [Ternary Expression Evaluators](https://awesome-repositories.com/f/web-development/conditional-rendering/ternary-expression-evaluators.md) — Implements ternary logic to return one of two values based on a boolean test. ([source](http://masterminds.github.io/sprig/defaults.html))
- [JSON Encoding](https://awesome-repositories.com/f/web-development/json-encoding.md) — Encodes data structures into JSON strings with support for pretty-printing and HTML escaping. ([source](http://masterminds.github.io/sprig/defaults.html))

### DevOps & Infrastructure

- [Semantic Versioning Systems](https://awesome-repositories.com/f/devops-infrastructure/dependency-management/version-compatibility-management/semantic-versioning-systems.md) — Parses version strings to determine relative order according to semantic versioning specifications.

### System Administration & Monitoring

- [Environment Variable Access](https://awesome-repositories.com/f/system-administration-monitoring/monitoring-and-observability/observability-platforms/distributed-tracing-execution-analysis/execution-metadata/environment-variable-access.md) — Reads and expands environment variables from the host operating system for use in templates. ([source](http://masterminds.github.io/sprig/))
