/JTokens

Simple parser for JSON design tokens.

Primary LanguageJavaGNU Lesser General Public License v2.1LGPL-2.1

JTokens

JTokens is a general purpose library to parse JSON design tokens.

Including JTokens

Groovy:

repositories {
  maven { url "https://repo.polyfrost.cc/releases" }
}

dependencies {
  implementation("cc.polyfrost:jtokens:1.0.0") 
}

Kotlin:

repositories {
  maven("https://repo.polyfrost.cc/releases")
}

dependencies {
  implementation("cc.polyfrost:jtokens:1.0.0")
}

Usage

Creating a DesignToken

json can be a JsonObject, Json String, Reader or JsonReader

DesignToken token = new DesignToken(json);

You can load multiple jsons like so:

DesignToken token = new DesignToken(json1, json2);

Getting values

Example design token json;

{
  "colors": {
    "$type": "color",
    "white": {
      "$value": "#ffffff"
    }
  }
}

To get the white color do the following:

Color white = token.getColor("colors.white");

Custom types

JTokens allows you to use custom types, to do this implement the TypeResolutionStrategy class or extend the DefaultTypeResolutionStrategy class, then use it like this:

DesignToken token = new DesignToken(new MyTypeResolutionStrategy(), json);

Checklist

  • Basic JSON types
  • Aliases / references
  • Types
    • Color
    • Dimension
    • Font Family (NOT FINALIZED IN STANDARD)
    • Font Weight
    • Duration
    • Cubic Bezier
  • Allow loading of multiple files and references to the other file in the same design token instance
  • Extensions
  • Composite types (NOT FINALIZED IN STANDARD)
    • Stroke style
    • Border
    • Transition
    • Shadow
    • Gradient
    • Typography