replace-string

This parser helps you replace a part or the whole name of your collections, groups and tokens from your SDTF token tree.

Interface

interface parser {
  name: 'replace-string';
  options: ({
    all?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    }
  } | 
  {
    group?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    };
    collection?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    };
    token?: string | {
      regex: string | { pattern: string, flags?: 'g' & 'm' & 'i' },
      replaceBy: string
    }
  }) & { applyTo?: SDTFQuery }
}

Options

Parameter
Required
Type
Default
Description

all

false

string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}

Select all collections, groups and tokens in your SDTF token graph.

group

false

string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}

Select all groups in your SDTF token graph.

collection

false

string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}

Select all collections in your SDTF token graph.

token

false

string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}

Select all tokens in your SDTF token graph.

regex

required

object | string

If string: the parameter used for the constructor of the regex. If your use case need to use flags prefer object notation.

regex.pattern

required

string

The pattern of the regex used as first argument of the constructor.

regex.flags

false

string

The flags to use for regex. In the regex constructor it's the second argument constructor of the regex.

replaceBy

required

string

The value will used as replacement. This method is used to apply the replacement.

trim

false

boolean

false

Set true to remove spaces before and after the transformed values. This method is used to trim.

applyTo

false

| { collection: string | true }
| { group: string | true }
| { token: string | true }
| SDTFQuery

The selection where to apply the transformation. collection, group, token take a Regex string or true to select anything of the kind. An SDTFQuery can be used for advance use cases.

Basic usage: Rename design token by keeping only characters present after the last slash character (/).

{
  "colors": {
    "Colors/Black": {
      "$type": "color",
      "$value": {
        "default": {
          "model": "hex",
          "hex": "#000000",
          "alpha": 1
        }
      }
    }
  }
}

Last updated