Generator Functions

Generator functions can be called on the value attribute of a variable definition. They are useful for doing things like generating secrets or inserting timestamps into files.

Year

Adds this year as YYYY

This would be defined in the manifest as:

{
  "name": "this_year",
  "description": "Example rendering the current year",
  "value": "#this_year"
}

And used in a filename or template (handlebars) thus:

{{this_year}}

This is useful for rendering things like copyright lines in READMES or LICENCES.

Current Timestamp

Renders a timestamp of the current time.

This would be defined in the manifest as:

{
  "name": "current_time",
  "description": "Example rendering the current time",
  "value": "#timestamp_now"
}

And used in a filename or template (handlebars) thus:

{{current_time}}

The output will be something like this:

2020110112000100

This is useful for rendering things like database migration timestamps.

Current Timestamp UTC

Exactly the same as timestamp, but instead of using local time, it will render a timestamp in utc time.

This would be defined in the manifest as:

{
  "name": "current_time_utc",
  "description": "Example rendering the current time in utc",
  "value": "#timestamp_utc_now"
}

And used in a filename or template (handlebars) thus:

{{current_time_utc}}

The output will be something like this:

2020110112000100

Random String

Renders a random string to the specified length. To use this you may wish to provide an optional argument that specifies the length of the random string. By default this will be 256 characters.

This would be defined in the manifest as:

{
  "name": "random_256_char_string",
  "description": "Example rendering a 256 character random string",
  "value": "#random_string"
}

To specify the length:

{
  "name": "random_10_char_string",
  "description": "Example rendering a 10 character random string",
  "value": "#random_string, 10"
}

And used in a filename or template (handlebars) thus:

{{random_256_char_string}}

# Or:

{{random_10_char_string}}

The output will be something like this:

AbA083HJFhfhjfHF

This is useful for generating secrets or salt hashes.

Randomize String

Appends some random characters to the end of a string. You must call this with a string, and optionally the randomized component length. By default the random character length will be 5 characters.

This would be defined in the manifest as:

{
  "name": "randomized_string",
  "description": "Example randomizing a given string",
  "value": "#randomize, name"
}

This will produce a string like this:

name_AbC30

To specify the length of the random component:

{
  "name": "randomized_string_ten_char",
  "description": "Example randomizing a string with 10 character entropy",
  "value": "#randomize, name, 10"
}

This will produce a string like this:

name_AbC30AbC30

This is useful for ensuring a string is always unique, for example when generating seed files.

Upcase String

Ensures that given string is all in upper case

This would be defined in the manifest as:

{
  "name": "upcase_string",
  "description": "Example rendering an upper case string",
  "value": "#upcase, yolo"
}

And used in a filename or template (handlebars) thus:

{{upcase_string}}

And would return a value like:

YOLO

Downcase String

Ensures that given string is all in lower case

This would be defined in the manifest as:

{
  "name": "downcase_string",
  "description": "Example rendering an lower case string",
  "value": "#downcase, YOLO"
}

And used in a filename or template (handlebars) thus:

{{downcase_string}}

And would return a value like:

yolo

Join String

Ensures joins a set of strings. The first argument is the delimiter, this could be anything like /, . etc. The following arguments are the strings to be joined, you can specify as many as you like.

This would be defined in the manifest as:

{
  "name": "joined_string",
  "description": "Example joinging a string with a delimiter",
  "value": "#join, /, path, to, file"
}

And used in a filename or template (handlebars) thus:

{{joined_string}}

And would return a value like:

path/to/file

This is useful for specifying a known value with a variable delimiter in jsonnet.

Snake Case

Converts a given string to snake case (i.e. SoMe ThIng to some_thing)

This would be defined in the manifest as:`

{
  "name": "snake_case_string",
  "description": "Example converting a string to snake case",
  "value": "#snake_case, SoMe ThIng"
}

And used in a filename or template (handlebars) thus:

{{snake_case_string}}

And would return a value like:

some_thing

Dash Case

Converts a given string to dash case (i.e. SoMe ThIng to some-thing)

This would be defined in the manifest as:`

{
  "name": "dash_case_string",
  "description": "Example converting a string to dash case",
  "value": "#dash_case, SoMe ThIng"
}

And used in a filename or template (handlebars) thus:

{{dash_case_string}}

And would return a value like:

some-thing

Camel Case

Converts a given string to camel case (i.e. SoMe ThIng to SomeThing)

This would be defined in the manifest as:`

{
  "name": "camel_case_string",
  "description": "Example converting a string to camel case",
  "value": "#camel_case, SoMe ThIng"
}

And used in a filename or template (handlebars) thus:

{{camel_case_string}}

And would return a value like:

SomeThing

Pluralize

Attempts to convert a singular string in English to its plural form.

This would be defined in the manifest as:`

{
  "name": "pluralize_string",
  "description": "Example converting a singluar string to its plural form",
  "value": "#pluralize, Thing"
}

And used in a filename or template (handlebars) thus:

{{pluralize_string}}

And would return a value like:

Things

Singularize

Attempts to convert a plural string in English to its singular form.

This would be defined in the manifest as:`

{
  "name": "singularize_string",
  "description": "Example converting a plural string to its singular form",
  "value": "#pluralize, Things"
}

And used in a filename or template (handlebars) thus:

{{pluralize_string}}

And would return a value like:

Thing