> For the complete documentation index, see [llms.txt](https://docs.specifyapp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.specifyapp.com/reference/parsers/to-kotlin.md).

# to-kotlin

## Interface

```typescript
interface parser {
  name: 'to-kotlin';
  output: {
    type: 'file';
    filePath: string;
  };
  options?:{
    tokenNameTemplate?: string;
    scopeName?: string;
    androidMinVersion?: number;
  }
}
```

## Options

<table data-full-width="true"><thead><tr><th width="230">Parameter</th><th>Required</th><th>Type</th><th width="286">Default</th><th width="265">Description</th></tr></thead><tbody><tr><td><code>tokenNameTemplate</code></td><td><code>false</code></td><td><code>string</code></td><td><code>{{path}}{{token}}{{mode}}</code></td><td>The template the parser follows to name your tokens.<br><br>You can use the <code>path</code> of your tokens, their <code>token</code> name, and their respective <code>mode</code>.</td></tr><tr><td><code>scopeName</code></td><td><code>false</code></td><td><code>string</code></td><td><code>DesignTokens</code></td><td>The name of the parent class which contains all classes for all your token types.</td></tr><tr><td><code>androidMinVersion</code></td><td><code>false</code></td><td><code>number</code></td><td>33</td><td>The min Android version supported by your app.</td></tr></tbody></table>

## Basic usage

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

```json
{
  "colors": {
    "$collection": {
      "$modes": [
        "light",
        "dark"
      ]
    },
    "aliases": {
      "border": {
        "active": {
          "$type": "color",
          "$value": {
            "dark": {
              "$alias": "colors.core.label.blue-base",
              "$mode": "dark"
            },
            "light": {
              "$alias": "colors.core.label.blue-base",
              "$mode": "light"
            }
          }
        }
      }
    },
    "core": {
      "label": {
        "blue-base": {
          "$type": "color",
          "$value": {
            "dark": {
              "model": "rgb",
              "red": 96,
              "green": 168,
              "blue": 250,
              "alpha": 1
            },
            "light": {
              "model": "rgb",
              "red": 17,
              "green": 125,
              "blue": 249,
              "alpha": 1
            }
          }
        },
        "blue-lighter": {
          "$type": "color",
          "$value": {
            "dark": {
              "model": "rgb",
              "red": 41,
              "green": 52,
              "blue": 67,
              "alpha": 1
            },
            "light": {
              "model": "rgb",
              "red": 219,
              "green": 236,
              "blue": 254,
              "alpha": 1
            }
          }
        }
      }
    }
  },
  "dimensions": {
    "$collection": {
      "$modes": [
        "desktop",
        "mobile"
      ]
    },
    "base": {
      "dimension-01": {
        "$type": "dimension",
        "$value": {
          "mobile": {
            "value": 2,
            "unit": "px"
          },
          "desktop": {
            "value": 4,
            "unit": "px"
          }
        }
      },
      "dimension-02": {
        "$type": "dimension",
        "$value": {
          "mobile": {
            "value": 4,
            "unit": "px"
          },
          "desktop": {
            "value": 8,
            "unit": "px"
          }
        }
      }
    }
  }
}
```

{% endcode %}
{% endtab %}

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

```json
{
  "version": "2",
  "repository": "@organization/repository",
  // Only use the personalAccessToken when working with the CLI
  "personalAccessToken": "<your-personal-access-token>",
  "rules": [
    {
      "name": "To Kotlin",
      "parsers": [
        {
          "name": "to-kotlin",
          "output": {
            "type": "file",
            "filePath": "public/tokens.kt"
          }
        }
      ]
    }
  ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Output" %}
{% code title="output/tokens.kt" lineNumbers="true" %}

```kotlin
import android.content.res.Resources
import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.*
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp

object DesignTokens {
  fun pxToDp(px: Double): Float {
    return (px / Resources.getSystem().displayMetrics.density).toFloat()
  }
  fun pxToDp(px: Int): Float {
    return px / Resources.getSystem().displayMetrics.density
  }

  fun pxToSp(px: Double): TextUnit {
    return (px / Resources.getSystem().displayMetrics.scaledDensity).sp
  }
  fun pxToSp(px: Int): TextUnit {
    return (px / Resources.getSystem().displayMetrics.scaledDensity).sp
  }

  object Color_ {
    val colorsCoreLabelBlue_baseDark = Color(0.37647f, 0.65882f, 0.98039f, 1f)
    val colorsCoreLabelBlue_baseLight = Color(0.06667f, 0.49020f, 0.97647f, 1f)
    val colorsAliasesBorderActiveDark = Color(0.37647f, 0.65882f, 0.98039f, 1f)
    val colorsAliasesBorderActiveLight = Color(0.06667f, 0.49020f, 0.97647f, 1f)
    val colorsCoreLabelBlue_lighterDark = Color(0.16078f, 0.20392f, 0.26275f, 1f)
    val colorsCoreLabelBlue_lighterLight = Color(0.85882f, 0.92549f, 0.99608f, 1f)
  }

  object Dimension {
    val dimensionsBaseDimension_01Desktop = pxToDp(4)
    val dimensionsBaseDimension_01Mobile = pxToDp(2)
    val dimensionsBaseDimension_02Desktop = pxToDp(8)
    val dimensionsBaseDimension_02Mobile = pxToDp(4)
  }
}
```

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.specifyapp.com/reference/parsers/to-kotlin.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
