# suffix-by

## Interface

```typescript
interface parser {
  name: 'suffix-by';
  options: ({
    all: string
  } | 
  {
    group?: string;
    collection?: string;
    token?: string;
  }) & { applyTo?: SDTFQuery }
}
```

## Options

<table><thead><tr><th width="170">Parameter</th><th width="127.33333333333331">Required</th><th width="330">Type</th><th width="136">Default</th><th width="253">Description</th></tr></thead><tbody><tr><td><code>all</code></td><td><code>false</code></td><td><code>string</code></td><td></td><td>Select all collections, groups and tokens in your SDTF token graph.</td></tr><tr><td><code>group</code></td><td><code>false</code></td><td><code>string</code></td><td></td><td>Select all groups in your SDTF token graph.</td></tr><tr><td><code>collection</code></td><td><code>false</code></td><td><code>string</code></td><td></td><td>Select all collections in your SDTF token graph.</td></tr><tr><td><code>token</code></td><td><code>false</code></td><td><code>string</code></td><td></td><td>Select all tokens in your SDTF token graph.</td></tr><tr><td><code>applyTo</code></td><td><code>false</code></td><td><pre class="language-typescript"><code class="lang-typescript">| { collection: string | true }
| { group: string | true }
| { token: string | true }
| SDTFQuery
</code></pre></td><td></td><td>The selection where to apply the transformation.<br><br><code>collection</code>, <code>group</code>, <code>token</code> take a Regex string or <code>true</code> to select anything of the kind.<br><br>An <a href="../../../guides/querying-a-sdtf-graph#introduction"><code>SDTFQuery</code></a> can be used for advance use cases.</td></tr></tbody></table>

## Basic usage: Suffix color tokens

{% tabs %}
{% tab title="Input" %}
{% code lineNumbers="true" %}

```json
{
  "spacing": {
    "1": {
      "$type": "dimension",
      "$value": {
        "default": {
          "value": 4,
          "unit": "px"
        }
      }
    }
  },
  "colors": {
    "black": {
      "$type": "color",
      "$value": {
        "default": {
          "model": "hex",
          "hex": "#000000",
          "alpha": 1
        }
      }
    }
  }
}
```

{% endcode %}
{% endtab %}

{% tab title="Config" %}
{% code title=".specifyrc.json" lineNumbers="true" %}

```json5
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "Prefix color tokens",
      "parsers": [
        {
          "name": "suffix-by",
          "options": {
            "token": "-color",
            "applyTo": {
              "where": {
                "token": ".*",
                "withTypes": {
                  "include": [
                    "color"
                  ]
                },
                "select": {
                  "parents": true
                }
              }
            }
          }
        },
        {
          "name": "to-sdtf",
          "output": {
            "type": "file",
            "filePath": "tokens.json"
          }
        }
      ]
    }
  ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Output" %}
{% code title="tokens.json" lineNumbers="true" %}

```css
{
  "colors": {
    "black-color": {
      "$type": "color",
      "$value": {
        "default": {
          "model": "hex",
          "hex": "#000000",
          "alpha": 1
        }
      }
    }
  },
  "spacing": {
    "1": {
      "$type": "dimension",
      "$value": {
        "default": {
          "value": 4,
          "unit": "px"
        }
      }
    }
  }
}
```

{% endcode %}
{% endtab %}
{% endtabs %}
