{"id":15046876,"url":"https://github.com/senryoku/smol-string","last_synced_at":"2025-05-07T15:01:36.524Z","repository":{"id":204619815,"uuid":"712275540","full_name":"Senryoku/smol-string","owner":"Senryoku","description":"Compression for browsers' localStorage. Alternative to lz-string written in Zig.","archived":false,"fork":false,"pushed_at":"2025-04-11T23:42:59.000Z","size":5993,"stargazers_count":41,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-12T00:24:12.927Z","etag":null,"topics":["browser","compression","localstorage","typescript","web","zig"],"latest_commit_sha":null,"homepage":"https://senryoku.github.io/smol-string/","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Senryoku.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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},"funding":{"github":"Senryoku"}},"created_at":"2023-10-31T06:25:03.000Z","updated_at":"2025-04-11T23:42:29.000Z","dependencies_parsed_at":"2023-11-27T13:30:38.323Z","dependency_job_id":"86aaeea4-ff06-4f97-9c7d-24ac9bedb96e","html_url":"https://github.com/Senryoku/smol-string","commit_stats":{"total_commits":145,"total_committers":1,"mean_commits":145.0,"dds":0.0,"last_synced_commit":"f36795a36ea335a90c1ec3fd230418e05e57a518"},"previous_names":["senryoku/smol-string"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senryoku%2Fsmol-string","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senryoku%2Fsmol-string/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senryoku%2Fsmol-string/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Senryoku%2Fsmol-string/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Senryoku","download_url":"https://codeload.github.com/Senryoku/smol-string/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252902604,"owners_count":21822259,"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","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":["browser","compression","localstorage","typescript","web","zig"],"created_at":"2024-09-24T20:53:41.682Z","updated_at":"2025-05-07T15:01:36.499Z","avatar_url":"https://github.com/Senryoku.png","language":"Zig","funding_links":["https://github.com/sponsors/Senryoku"],"categories":[],"sub_categories":[],"readme":"# smol-string [![Zig Lib](https://github.com/Senryoku/smol-string/actions/workflows/zig.yml/badge.svg)](https://github.com/Senryoku/smol-string/actions/workflows/zig.yml) [![TS Lib](https://github.com/Senryoku/smol-string/actions/workflows/ts-lib.yml/badge.svg)](https://github.com/Senryoku/smol-string/actions/workflows/ts-lib.yml)\n\n`smol-string` is a compression library designed for use with browsers' `localStorage` (and `sessionStorage`). It serves as a faster alternative to [`lz-string`](https://github.com/pieroxy/lz-string).\n\nThe library is composed of a core algorithm written in [Zig](https://ziglang.org/) and compiled to WebAssembly, wrapped in an easy to use TypeScript library.\n\n## Installation\n\n```\nnpm install -S smol-string\n```\n\n## Usage\n\n```ts\nimport { compress, decompress } from \"smol-string\";\n\nconst input = \"Any JS String\";\n\nconst compressed = compress(input);\nconst decompressed = decompress(compressed);\n```\n\nAn async version offloading the processing to a webworker is also available. API is identical, except that each function returns a promise:\n\n```ts\nimport { compress, decompress } from \"smol-string/worker\";\n\nconst input = JSON.stringify({ imagine: \"this is a large object\" });\n\nconst compressed = await compress(input);\nconst decompressed = await decompress(compressed);\n```\n\n## Build\n\n```sh\nzig build         # Builds the wasm modules to `zig-out/lib/` by default.\n```\n\n```sh\ncd ts-lib\nnpm ci            # Installs dependencies.\nnpm run wasm-opt  # (Optional) Run wasm-opt on the wasm module generated by zig and copies it for the TS library. \n                  #   Only needed if you made changes to the zig library.\nnpm run build     # Builds the Typescript library to `ts-lib/dist`.\n```\n\n## Comparison to lz-string\n\n### Performance\n\nHere are some benchmark results comparing `smol-string` to `lz-string` in Chrome. You can run them yourself by visiting https://senryoku.github.io/smol-string/bench.\n\n![image](https://github.com/Senryoku/smol-string/assets/1338143/20df3f76-959a-428b-8c50-c8f9fbcf1020)\n\n![image](https://github.com/Senryoku/smol-string/assets/1338143/38d7ca8a-7ef5-4516-b5c1-02db2cdae6b7)\n\n![image](https://github.com/Senryoku/smol-string/assets/1338143/235683f0-75e8-4c4c-a2e1-2b89e50cc549)\n\n\n### UTF-16 Compatibility\n\nlz-string offers multiple output formats, including one producing only valid UTF-16 strings. This was done to ensure compatibility with localStorage in all browsers. \n\nHowever, this was never an issue in all my testing, regardless of the browser. I chose to simplify the API and only kept a single pair of compress/decompress functions that can produce technically invalid UTF-16 strings.\nThe library was originally written with this constraint in mind, meaning it would be trivial to introduce such constraints back in the future if needed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenryoku%2Fsmol-string","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsenryoku%2Fsmol-string","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsenryoku%2Fsmol-string/lists"}