@sit-onyx/figma-utils 1.0.0-alpha.1 → 1.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,6 +36,28 @@ export const parseFigmaVariables = (apiResponse, options) => {
36
36
  parsedData.forEach((data) => {
37
37
  if (data.modeName === DEFAULT_MODE_NAME)
38
38
  delete data.modeName;
39
+ const numberRegex = /\d+/;
40
+ // sort variables by name
41
+ // for variables with the same name that just end with a different number (e.g. my-var-100 and my-var-200)
42
+ // sort them by number instead of alphabetically so e.g. 100 is sorted before 1000
43
+ data.variables = Object.keys(data.variables)
44
+ .map((key) => {
45
+ const asNumber = numberRegex.exec(key)?.[0] ?? "";
46
+ return {
47
+ key,
48
+ asNumber: +asNumber || undefined, // prevent NaN
49
+ base: key.replace(asNumber, ""),
50
+ };
51
+ })
52
+ .sort((a, b) => {
53
+ if (a.asNumber && b.asNumber && a.base === b.base)
54
+ return a.asNumber - b.asNumber;
55
+ return a.key.localeCompare(b.key);
56
+ })
57
+ .reduce((variables, { key }) => {
58
+ variables[key] = data.variables[key];
59
+ return variables;
60
+ }, {});
39
61
  });
40
62
  return parsedData;
41
63
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sit-onyx/figma-utils",
3
3
  "description": "Utility functions and CLI for importing data from the Figma API into different formats (e.g. CSS, SCSS etc.)",
4
- "version": "1.0.0-alpha.1",
4
+ "version": "1.0.0-alpha.2",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "@sit-onyx/figma-utils": "./dist/cli.js"