Home

Awesome

Package mold

Project status Build Status Coverage Status Go Report Card GoDoc License

Package mold is a general library to help modify or set data within data structures and other objects.

How can this help me you ask, please see the examples here

Requirements

Installation

Use go get.

go get -u github.com/go-playground/mold/v4

Examples

ExampleDescription
simpleA basic example with custom function.
fullA more real life example combining the usage of multiple packages.

Modifiers

These functions modify the data in-place.

NameDescription
camelCamel Cases the data.
defaultSets the provided default value only if the data is equal to it's default datatype value.
emptySets the field equal to the datatype default value. e.g. 0 for int.
lcaselowercases the data.
ltrimTrims spaces from the left of the data provided in the params.
rtrimTrims spaces from the right of the data provided in the params.
setSet the provided value.
slugConverts the field to a slug
snakeSnake Cases the data.
strip_alphaStrips all ascii characters from the data.
strip_alpha_unicodeStrips all unicode characters from the data.
strip_numStrips all ascii numeric characters from the data.
strip_num_unicodeStrips all unicode numeric characters from the data.
strip_punctuationStrips all ascii punctuation from the data.
titleTitle Cases the data.
tprefixTrims a prefix from the value using the provided param value.
trimTrims space from the data.
tsuffixTrims a suffix from the value using the provided param value.
ucaseUppercases the data.
ucfirstUpper cases the first character of the data.

Special Notes: default and set modifiers are special in that they can be used to set the value of a field or underlying type information or attributes and both use the same underlying function to set the data.

Setting a Param will have the following special effects on data types where it's not just the value being set:

Scrubbers

These functions obfuscate the specified types within the data for pii purposes.

NameDescription
emailsScrubs multiple emails from data.
emailScrubs the data from and specifies the sha name of the same name.
textScrubs the data from and specifies the sha name of the same name.
nameScrubs the data from and specifies the sha name of the same name.
fnameScrubs the data from and specifies the sha name of the same name.
lnameScrubs the data from and specifies the sha name of the same name.

Special Information

Contributing

I am definitely interested in the communities help in adding more scrubbers and modifiers. Please send a PR with tests, and preferably no extra dependencies, at lease until a solid base has been built.

Complimentary Software

Here is a list of software that compliments using this library post decoding.

License

Distributed under MIT License, please see license file in code for more details.