Specify Docs
Specify ↗︎Changelog ↗︎Guide ↗︎
V2
V2
  • Getting started
    • Introduction
    • What is Specify?
    • Pulling your first tokens with the CLI
    • Glossary
  • Collect
    • What is a Source?
    • Available sources
      • Figma Variables & Styles
      • Tokens Studio
  • Distribute
    • What is a Destination?
    • Available destinations
      • GitHub
      • Specify CLI
      • Specify SDK
      • HTTP API
  • Concepts
    • Overview
    • Parsers Engine
    • SDTF Client
      • SDTF Engine
    • Specify Design Token Format
  • Guides
    • Configuration file 101
    • Specify CLI usage 101
      • Getting started
      • Authentication
      • Generate Files
    • Specify SDK usage 101
      • Getting started
      • Retrieving and working with the tokens
      • Updating tokens
      • Converting a token to XXX
      • Executing generation parsers
    • Specify SDK Cheatsheet
    • Manage font files
    • Querying a SDTF graph
  • Reference
    • Parsers Engine
    • Parsers
      • change-case
      • convert-color
      • convert-dimension
      • make-line-height-relative
      • filter
      • register-view
      • select-modes
      • prefix-by
      • suffix-by
      • replace-string
      • to-css-custom-properties
      • to-css-text-style
      • to-css-font-import
      • to-flutter
      • to-javascript
      • to-json
      • to-json-list
      • to-kotlin
      • to-react-native
      • to-scss-mixin-text-style
      • to-scss-map
      • to-sdtf
      • to-style-dictionary
      • to-swift
      • to-tailwind
      • to-typescript
      • svgo
      • svg-to-jsx
      • svg-to-tsx
      • to-svg-file
      • to-bitmap-file
      • to-file
    • Specify SDK
      • SpecifyClient
      • SDTFClient
      • Converters
        • CSS
      • ParsersEngineResults
    • SDTF Engine
      • Query API
      • Mutation API
      • SDTF Query Language
      • SDTF QueryResult
      • TokenState
        • Stateful Value
    • HTTP API
      • POST /parsers-engine-rpc
    • Specify CLI
  • Resources
    • Parser Rules templates
      • CSS Custom Properties
      • Tailwind
      • React Native
      • Flutter
      • SDTF
      • JSON
    • Specify CLI VS Specify SDK
    • Playground
    • Best practices
  • Useful links
    • Discord
    • YouTube
    • Twitter
    • Help Center
    • Canny
Powered by GitBook
On this page
  • Interface
  • Options
  • Basic usage: Rename design token by keeping only characters present after the last slash character (/).

Was this helpful?

Export as PDF
  1. Reference
  2. Parsers

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
        }
      }
    }
  }
}
.specifyrc.json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Rename tokens",
      "parsers": [
        {
          "name": "replace-string",
          "options": {
            "token": {
              "regex": {
                "pattern": "(.*?)\\/",
                "flags": "g"
              },
              "replaceBy": ""
            }
          }
        },
        {
          "name": "to-sdtf",
          "output": {
            "type": "file",
            "filePath": "tokens.json"
          }
        }
      ]
    }
  ]
}
tokens.json
{
  "colors": {
    "Black": {
      "$type": "color",
      "$value": {
        "default": {
          "model": "hex",
          "hex": "#000000",
          "alpha": 1
        }
      }
    }
  }
}
Previoussuffix-byNextto-css-custom-properties

Last updated 1 year ago

Was this helpful?

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

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

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

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

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

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

string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}
string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}
string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}
string | {
  regex: string | { pattern: string, flags: 'g' & 'm' & 'i' },
  replaceBy: string
}
| { collection: string | true }
| { group: string | true }
| { token: string | true }
| SDTFQuery
constructor of the regex
constructor
constructor of the regex
This method
This method
SDTFQuery