{"id":17725655,"url":"https://github.com/fedemartinm/lexical-minifier","last_synced_at":"2025-07-28T09:13:33.776Z","repository":{"id":65752901,"uuid":"595326315","full_name":"fedemartinm/lexical-minifier","owner":"fedemartinm","description":"A minifier that allows for compressing and decompressing the JSON data exported by the lexical editor.","archived":false,"fork":false,"pushed_at":"2024-03-11T03:57:04.000Z","size":421,"stargazers_count":15,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-11T12:05:51.030Z","etag":null,"topics":["editor","lexical","minifier","minify"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fedemartinm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-30T21:17:25.000Z","updated_at":"2025-05-21T20:03:59.000Z","dependencies_parsed_at":"2024-10-25T20:09:58.953Z","dependency_job_id":"6df1dbd5-2b7f-43d1-a576-60a0278e7fc3","html_url":"https://github.com/fedemartinm/lexical-minifier","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":"0.14814814814814814","last_synced_commit":"caecab6fd98a73ad4124ae656050c6e72230c3ac"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/fedemartinm/lexical-minifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedemartinm%2Flexical-minifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedemartinm%2Flexical-minifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedemartinm%2Flexical-minifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedemartinm%2Flexical-minifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fedemartinm","download_url":"https://codeload.github.com/fedemartinm/lexical-minifier/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedemartinm%2Flexical-minifier/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267491284,"owners_count":24096159,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["editor","lexical","minifier","minify"],"created_at":"2024-10-25T16:05:15.273Z","updated_at":"2025-07-28T09:13:33.719Z","avatar_url":"https://github.com/fedemartinm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![npm](https://img.shields.io/npm/v/lexical-minifier) \n![npm bundle size](https://img.shields.io/bundlephobia/minzip/lexical-minifier?color=green)\n\n# Lexical Minifier\n\nExporting the state of the [lexical editor](https://github.com/facebook/lexical) can result in a large and unoptimized JSON structure. This package offers a solution by minifying and unminifying the code produced by the lexical editor, reducing the time it takes to obtain or send the serialized state in a request and freeing up valuable storage space. \n\n\n### How does the package work?\n\nIts philosophy is to create a simple and secure minification through the use of these strategies:\n\n- Mapping all known values to numerical values\n- Shortening property length to one character\n- Removing default values\n- Providing complete reversibility to the original state.\n\n### Testing \n\nUnit testing has been conducted to ensure the functionality and reliability of the code. The test-coverage also checks all the minifiers included in the package to guarantee that every aspect has been thoroughly tested and optimized for optimal performance. \n\n### Example\n\nIf you serialize the content \"Here are some text formats: `code`, **bold**, _italic_ and so on\" in lexical, you will get something like:\n\n\n```js\n{\"children\":[{\"children\":[{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\"Here are some text formats: \",\"type\n\":\"text\",\"version\":1},{\"detail\":0,\"format\":16,\"mode\":\"normal\",\"style\":\"\",\"text\":\"code\",\"type\":\"text\",\"version\":1},{\"det\nail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\", \",\"type\":\"text\",\"version\":1},{\"detail\":0,\"format\":1,\"mode\":\"norm\nal\",\"style\":\"\",\"text\":\"bold\",\"type\":\"text\",\"version\":1},{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\", \",\"\ntype\":\"text\",\"version\":1},{\"detail\":0,\"format\":2,\"mode\":\"normal\",\"style\":\"\",\"text\":\"italic\",\"type\":\"text\",\"version\":1},\n{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\" and so on.\",\"type\":\"text\",\"version\":1}],\"direction\":null,\"fo\nrmat\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":null,\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}\n```\n\nThis package lets you minify the nodes, resulting in this:\n\n```js\n{\"c\":[{\"c\":[{\"x\":\"Here are some text formats: \",\"t\":\"t\",\"v\":1},{\"f\":16,\"x\":\"code\",\"t\":\"t\",\"v\":1},{\"x\":\", \",\"t\":\"t\",\"v\":\n1},{\"f\":1,\"x\":\"bold\",\"t\":\"t\",\"v\":1},{\"x\":\", \",\"t\":\"t\",\"v\":1},{\"f\":2,\"x\":\"italic\",\"t\":\"t\",\"v\":1},{\"x\":\" and so on.\",\"t\":\n\"t\",\"v\":1}],\"t\":\"p\",\"v\":1}],\"t\":\"r\",\"v\":1}\n```\n\nAnd transform the nodes to array pack to further reduce the size:\n\n```js\n[[[\"p\",[[\"t\",{\"x\":\"Here are some text formats: \"}],[\"t\",{\"f\":16,\"x\":\"code\"}],[\"t\",{\"x\":\", \"}],[\"t\",{\"f\":1,\"x\":\"bold\"}],\n[\"t\",{\"x\":\", \"}],[\"t\",{\"f\":2,\"x\":\"italic\"}],[\"t\",{\"x\":\" and so on.\"}]]]]]\n```\n\n### Installation\n\n```shell\nyarn add lexical-minifier\n```\n\nor\n\n```shell\nnpm install lexical-minifier --save\n```\n\n### Usage\n\nThe following code snippet demonstrates the usage of this package. You can also see a demo and usage examples in this [sandbox](https://codesandbox.io/s/lexical-minifier-pqwwg7?file=/src/plugins/MinifierPlugin.js).\n\n```js\neditor.update(() =\u003e {\n  // get the minified state, to persist it or do what is necessary\n  const minified = minify($getRoot());\n  //\n  // ...\n  //\n  // get the serialized nodes, to import them back into lexical\n  const serialized = unminify(minified);\n\n  const editorState = editor.parseEditorState({ root: serialized });\n  editor.setEditorState(editorState);\n});\n```\n\n### Built-in minifiers\n\nThis package aims to minify all the nodes included in the lexical package and its official modules. \nBelow is a list of nodes that are supported by default. If you have created a custom node, you can easily write your minifier. If there is an existing node that you think should be included in this package, please open an [issue](https://github.com/fedemartinm/lexical-minifier/issues) and we'll check it.\n\n`root`, `text`, `link`, `code`, `mark`, `table`, `quote`, `list`, `heading`, `listitem`, `overflow`, `autolink`, `tablerow`, `tablecell`, `linebreak`, `paragraph`\n\n### Writing a custom minifier\n\nBelow is a basic example of how to write a custom minifier. You can see the complete API documentation [here](https://github.com/fedemartinm/lexical-minifier/tree/main/docs).\n\n```js\n\n// as a pre-requisite, your node must implement the exportJSON() method. \n// the first step is to define a minifier for your node:\nconst videoMinifier = buildMinifier(\n  {\n    type: \"video\",\n    minifiedType: \"v\",\n    version: 1,\n  },\n  (serialized: SerializedVideoNode, config) =\u003e ({\n    // here you must write the logic to minify the serialized object\n    // this package provide some tools like lookup-table and removeDefault\n    a: serialized.autoplay,\n    // these fields are required\n    t: config.minifiedType,\n    v: config.version,\n  }),\n  (minified, config) =\u003e ({\n    autoplay: minified.a,\n    // these fields are required\n    type: config.type,\n    version: config.version,\n  })\n);\n\n// then you must create an instance of the lexical minifier class and register the new node minifier\nconst lexicalMinifier = new LexicalMinifier();\nlexicalMinifier.register(\"video\", videoMinifier);\n\n// now you can minify and un-minify your state by passing the lexical minifier class as an argument\nconst minifiedData = minify(state, lexicalMinifier);\nconst serializedData = unminify(minifiedData, lexicalMinifier)\n```\n\n### Arraypack\n\nThe package is designed to use the result of the `minify()` and `unminify()` functions. Nevertheless, if you need a higher minification ratio, you can try using the array-pack format, which is a way of representing minified nodes using arrays.\n\nIn the Arraypack format, each node has the following structure:\n\n```js\n[\n    \"t\", // A string representing the node name. If it is not present, it is assumed to be 'r'.\n     1 , // A number representing the node version. If it is not present, it is assumed to be 1.\n    [ ], // An optional array with child nodes.\n    { }, // An optional object with node properties.\n]\n```\n\nA simple paragraph would look like this:\n\n```js\n[[[\"p\",[[\"t\",{\"x\":\"Hello World\"}]]]]]\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedemartinm%2Flexical-minifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffedemartinm%2Flexical-minifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedemartinm%2Flexical-minifier/lists"}