Module

Substitute

Package
purescript-substitute
Repository
ursi/purescript-substitute

#normalize Source

normalize :: String -> String

Remove whitespace in a way that lets you use multi-line strings independent of indentation, and allows the first line to be lined up with the rest of the string. Single-line strings are unchanged.

-- str1 = str2

str1 =
  normalize
    """
    foo

    bar
       baz
    """

str2 =
  """foo

bar
   baz
"""

#makeSubstituter Source

#Options Source

type Options = { close :: Char, indent :: Boolean, marker :: Char, missing :: String -> String, normalizeString :: Boolean, normalizeSubstitutions :: Boolean, open :: Char, suppress :: Boolean }

marker, open, close :: Char

These three characters are used for detecting places to substitute values. Unless preceded by a \, sequences of the form <marker><open>key<close> will be replaced by the value at key in the substitution record, if it exists. When it doesn't exist, see missing below.

missing :: String -> String

When there is no value associated with key, the substituter returns the result of passing key into missing.

normalizeString :: Boolean

Use normalize on the string passed to the function.

normalizeSubstitutions :: Boolean

Use normalize on the substitutions.

indent :: Boolean

When substituting in multi-line strings, pad with the appropriate whitespace so that all the lines are at the indentation level of the marker. Empty lines are not padded.

-- str1 = str2

str1 =
  substitute
    """
    f = do
      ${body}
    """
    { body:
        """
        log foo
        log bar
        log baz
        """
    }

str2 =
  """f = do
  log foo
  log bar
  log baz
"""

suppress :: Boolean

When substituting in multi-line strings that end in a \n, drop the \n. With suppress = false, str1 in the example above evaluates to

"""f = do
  log foo
  log bar
  log baz

"""

#defaultOptions Source

defaultOptions :: Options
{ marker: '$'
, open: '{'
, close: '}'
, missing: \key -> "[MISSING KEY: \"" <> key <> "\"]"
, normalizeString: true
, normalizeSubstitutions: true
, indent: true
, suppress: true
}

#substitute Source

substitute :: forall r. Homogeneous r String => String -> Record r -> String

makeSubstituter defaultOptions

#minimalOptions Source

minimalOptions :: Options
{ marker: '$'
, open: '{'
, close: '}'
, missing: \key -> "[MISSING KEY: \"" <> key <> "\"]"
, normalizeString: false
, normalizeSubstitutions: false
, indent: false
, suppress: false
}

Re-exports from Type.Row.Homogeneous

#Homogeneous Source

class Homogeneous row fieldType | row -> fieldType

Instances

Modules
Substitute