0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-08 07:50:44 -05:00
penpot-plugins/libs/plugins-data-parser
2024-04-08 11:44:59 +02:00
..
src fix(parser): clean up 2024-03-19 13:57:54 +01:00
.eslintrc.json feat: plugin libraries 2024-04-08 11:44:59 +02:00
package.json feat: plugin libraries 2024-04-08 11:44:59 +02:00
project.json feat: module boundaries 2024-03-07 14:21:05 +01:00
README.md fix(parser): clean up 2024-03-19 13:57:54 +01:00
tsconfig.json chore: eslint config 2024-03-12 13:19:33 +01:00
tsconfig.lib.json feat: parser library 2024-03-04 08:46:07 +01:00
tsconfig.spec.json chore: eslint config 2024-03-12 13:19:33 +01:00
vite.config.ts feat: parser library 2024-03-04 08:46:07 +01:00

Parser

This library exports cleanObject() and getSelectedUuids() funtions and the model Selection.

The cleanObject() function cleans up objects from useless properties and transforms the remaining ones to camelCase. It returns unknown.

The getSelectedUuids() functions, given an Selection object, returns the selected Uuids as an array of string.

Helpers

File Helper

File Helper functions

  • setData()

You can either pass the data in the constructor or use the setData() function.

example:

const fileHelper = new FileHelper();
fileHelper.setData(data);

or

const fileHelper = new FileHelper(data);
  • getCleanData()

Gets the cleaned up data. It deletes useless properties and and transforms the remaining ones to camelCase.

example:

const clean = fileHelper.getCleanData();

Page Helper

Page Helper functions

  • setData()

You can either pass the data in the constructor or use the setData() function.

example:

const pageHelper = new PageHelper();
pageHelper.setData(data);

or

const pageHelper = new PageHelper(data);
  • getCleanData()

Gets the cleaned up data. It deletes useless properties and and transforms the remaining ones to camelCase.

example:

const clean = pageHelper.getCleanData();
  • getObjectsArray()

Returns the objects array, which can contain heavily nested arrays with objects data.

example:

const objects = pageHelper.getObjectsArray();
  • getObjectById(id: string)

Returns an object by given uuid. The object is cleaned up and formatted as a PObject.

const obj: PObject = pageHelper.getObjectById(
  '3aba0744-11fe-4c41-80fb-1b42aa7ef3e5'
);

Selection Helper

Selection Helper functions

  • static getUuids(selection: Selection)

Returns the selected items in an array.

example:

const ids = SelectionHelper.getUuids(selection);