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

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

group

false

Select all groups in your SDTF token graph.

collection

false

Select all collections in your SDTF token graph.

token

false

Select all tokens in your SDTF token graph.

regex

required

object | string

regex.pattern

required

string

regex.flags

false

string

replaceBy

required

string

trim

false

boolean

false

applyTo

false

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