Skip to content

pantoken / packages/core/src / collectLeaves

Ֆունկցիա: collectLeaves()

collectLeaves(obj, path?, out?): Leaf[]

Բետա

Հավաքեք Tokens Studio tree-ի յուրաքանչյուր տերեւ: Տերեւը .value-ով հանգույց է՝ string արժեքը տալիս է մեկ տերեւ; composite object արժեքը (typography) տալիս է մեկ տերեւ <token>-<subProperty>-ով անվանված sub-property-ի համար; array արժեքները (box-shadow ցանկեր) բաց են թողնվել:

Պարամետրեր

obj

unknown

path?

string[] = []

out?

Leaf[] = []

Վերադարձվող արժեք

Leaf[]

Օրինակ

ts
import { collectLeaves } from "@pantoken/core";

const tree = {
  color: {
    white: { value: "#ffffff", type: "color" },
    hover: { value: "{color.white}", type: "color" },
  },
  typography: { body: { value: { fontFamily: "Lato", fontSize: "1rem", type: "typography" } } },
};

collectLeaves(tree).map((l) => [l.path.join("."), l.value]);
// → [
//   ["color.white", "#ffffff"],
//   ["color.hover", "{color.white}"],
//   ["typography.body.fontFamily", "Lato"],
//   ["typography.body.fontSize", "1rem"],
// ]