{"id":19917402,"url":"https://github.com/uditalias/jminor","last_synced_at":"2025-08-29T13:29:33.505Z","repository":{"id":69249704,"uuid":"156195777","full_name":"uditalias/jminor","owner":"uditalias","description":"🗜 JSON Minifier","archived":false,"fork":false,"pushed_at":"2018-11-08T09:57:23.000Z","size":71,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-19T01:32:45.647Z","etag":null,"topics":["json","mangle","minified","minifier","minify","minor","payload","small"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/uditalias.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2018-11-05T09:57:13.000Z","updated_at":"2021-08-20T01:50:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"4bf75f90-9f38-423f-a9b5-b5ec29c1d026","html_url":"https://github.com/uditalias/jminor","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/uditalias/jminor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditalias%2Fjminor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditalias%2Fjminor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditalias%2Fjminor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditalias%2Fjminor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uditalias","download_url":"https://codeload.github.com/uditalias/jminor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uditalias%2Fjminor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272692113,"owners_count":24977287,"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-08-29T02:00:10.610Z","response_time":87,"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":["json","mangle","minified","minifier","minify","minor","payload","small"],"created_at":"2024-11-12T21:49:48.700Z","updated_at":"2025-08-29T13:29:33.454Z","avatar_url":"https://github.com/uditalias.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JMinor [![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=JMinor%20reduces%20your%20payload%20size%20and%20saves%20you%20bandwidth\u0026url=https://github.com/uditalias/jminor\u0026via=uditalias\u0026hashtags=javascript,JSON,minify,developers,webdeveloper)\n\n### ✂️ A configurable Two-Way JSON minifier to reduce your payload size.\n\n[![Travis](https://img.shields.io/travis/uditalias/jminor.svg?style=flat-square)](https://travis-ci.org/uditalias/jminor)\n[![Npm](https://img.shields.io/npm/v/jminor.svg?style=flat-square)](https://www.npmjs.com/package/jminor)\n[![npm bundle size (minified)](https://img.shields.io/bundlephobia/min/jminor.svg?style=flat-square)](https://unpkg.com/jminor/umd/jminor.min.js)\n[![npm bundle size (minified + gzip](https://img.shields.io/bundlephobia/minzip/jminor.svg?style=flat-square)](https://unpkg.com/jminor/umd/jminor.min.js)\n[![GitHub](https://img.shields.io/github/license/uditalias/jminor.svg?style=flat-square)](https://github.com/uditalias/jminor/blob/master/LICENSE)\n\n## What is it good for?\n\nWhen passing data back and forth between servers and clients its always a good idea to reduce your payload size to the minimum, that will save you money and time for your users.\n\nJMinor will help you achive this task by reducing the size of your payload with a generated payload translation dictionary.\n\n#### Turn (~136 Bytes):\n```json\n{\n    \"my_very_long_key\": 1,\n    \"deep_object\": {\n        \"a_falsy_value\": false,\n        \"filled_array\": [1, 2, 3],\n        \"empty_array\": [],\n        \"another_array\": [\n            {\n                \"some_number\": 0\n            }\n        ]\n    }\n}\n```\n\n#### Into (~25 Bytes):\n```json\n{\n    \"a\": 1,\n    \"b\": {\n        \"d\": [1, 2, 3]\n    }\n}\n```\n\n#### And then back into (~61 Bytes):\n```json\n{\n    \"my_very_long_key\": 1,\n    \"deep_object\": {\n        \"filled_array\": [1, 2, 3]\n    }\n}\n```\n\n## Wait what??\n\nI know what you're thinking, its kind of weird, where `\"empty_array\": []` and \n`\"another_array\": [{ \"some_number\": 0 }]` disappeared??\n\n### The config options has all the answers!\n\n```json\n{\n    \"number\": {\n        \"removeZero\": true\n    },\n    \"object\": {\n        \"removeEmpty\": true\n    },\n    \"array\": {\n        \"removeEmpty\": true\n    }\n}\n```\n\n1. We remove all numbers with the value 0 with `number.removeZero` config\n\n```diff\n    {\n        ...\n        \"empty_array\": [],\n        \"another_array\": [\n            {\n-                \"some_number\": 0\n            }\n        ]\n        ...\n    }\n```\n2. After that we remove all empty objects with `object.removeEmpty` config\n\n```diff\n    {\n        ...\n        \"empty_array\": [],\n        \"another_array\": [\n-          {}\n        ]\n        ...\n    }\n```\n3. And in the end, we remove all empty arrays with `array.removeEmpty` config\n\n```diff\n    {\n        ...\n-        \"empty_array\": [],\n-        \"another_array\": []\n        ...\n    }\n```\n\nSee the [configurations](#config-and-defaults) section for more config options.\n\n\n## Install\nInstall via npm with\n```sh\n$ npm install --save jminor\n```\n\nOr use the CDN:\n\n```html\n\u003cscript src=\"https://unpkg.com/jminor/umd/jminor.js\"\u003e\u003c/script\u003e\n```\nOr the minified version:\n```html\n\u003cscript src=\"https://unpkg.com/jminor/umd/jminor.min.js\"\u003e\u003c/script\u003e\n```\n\n\u003e You can use JMinor both in the Client and the Server (or any other ECMAScript runtime).\n\n\n## Usage\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eDictionary\u003c/b\u003e\u003c/summary\u003e\n\nThe first thing to do is to create a Dictionary. The dictionary will hold all the original payload keys mapped to their translations.\n\n```javascript\nimport { createDictionary } from \"jminor\";\n\nconst dictionary = createDictionary();\n```\n\n`createDictionary()` is a factory function that receive a key generator factory.  \nA key generator is a module that generates dictionary keys.\n\n**`createDictionary(keyGeneratorFactory)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| keyGeneratorFactory | [`() =\u003e IKeyGenerator`](src/generators/IKeyGenerator.ts) | false | [`createDefaultKeyGenerator`](src/generators/defaultKeyGenerator.ts) | [See below]() |\n\n#### Dictionary API\n\n**`dictionary.replaceKeyGenerator(keyGenerator)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| keyGenerator | [`IKeyGenerator`](src/generators/IKeyGenerator.ts) | true | - | - |\n\n- replaces the current key generator.  \n***Note!*** that this will reset the dictionary.\n\n**`dictionary.fromJSON(data)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| data | JSON | true | - | - |\n\n- This method will digest the json object passed to it, and generates a uniqe key for each property for later translation\n\n**`dictionary.extendWith(data)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| data | JSON | true | - | - |\n\n- After dictionary is craeted and generated, you can pass another object to extend the dictionary that was created with the `fromJSON` method.\n\n**`dictionary.export()`**\n\n- Returns the generated dictionary as a raw object.\n\n**`dictionary.import(rawDictionary)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| rawDictionary | JSON | true | - | exported raw dictionary |\n\n- If you have exported dictionary received from the `export` method, you can import it.\n\n**`dictionary.ktoc(key)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| key | String | true | - | - |\n\n- Translates original key to generated key, if it exist in the dictionary.\n\n**`dictionary.ctok(ckey)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| ckey | String | true | - | - |\n\n- Translates generated key to original key, if it exist in the dictionary.\n\u003c/details\u003e\n\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eCompress\u003c/b\u003e\u003c/summary\u003e\n\nAfter we have our dictionary with the generated keys, we can go and compress some data.\n\n```javascript\nimport { compress } from \"jminor\";\n\nconst compressed = compress(data, dictionary, config);\n```\n\n**`compress(data, dictionary, config)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| data | JSON | true | - | A JSON with keys that presented in the dictionary |\n| dictionary | Dictionary | true | - | - |\n| config | [`ICompressConfig`](src/minifier/ICompressConfig.ts) | false | [See below](#config-and-defaults) | - |\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eDecompress\u003c/b\u003e\u003c/summary\u003e\n\nAfter compressing some data we can decompres it.  \n***Note!*** that some data may be truncated based on your compress config.\n\n```javascript\nimport { decompress } from \"jminor\";\n\nconst data = decompress(compressed, dictionary);\n```\n\n**`decompress(compressed, dictionary)`**\n\n| Name | Type | Required | Default | Description |\n| - | - | - | - | - |\n| compressed | JSON | true | - | A JSON with keys that presented in the dictionary |\n| dictionary | Dictionary | true | - | - |\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eGenerators\u003c/b\u003e\u003c/summary\u003e\n\n### JMinor comes with two built in key generators:\n- `DefaultKeyGenerator` - generates keys in the form of `aaa`, `aab`, `zxc` etc.  \n\n- `NumericKeyGenerator` - generates keys in the form of a numeric ascending series.\n\nYou can create your own key generator, if you will, you should implement the [`IKeyGenerator`](src/generators/IKeyGenerator.ts) interface.\n\nSee the `generators/` folder for source example\n\u003c/details\u003e\n\n## Config and defaults\n```javascript\n{\n    // Translate object keys\n    // Default: true\n    translateKeys: true,\n\n    null: {\n\n        // Remove null values (null)\n        // Default: false\n        removeNull: false,\n\n        // If removeNull is true, exclude this keys\n        // Default: []\n        exclude: []\n    },\n\n    boolean: {\n\n        // Remove false values (false)\n        // Default: false\n        removeFalse: false,\n\n        // If removeFalse is true, exclude this keys\n        // Default: []\n        exclude: []\n    },\n\n    string: {\n\n        // Remove empty strings (\"\")\n        // Default: false\n        removeEmpty: false,\n\n        // If removeEmpty is true, exclude this keys\n        // Default: []\n        exclude: []\n    },\n\n    number: {\n\n        // Remove zero values (0)\n        // Default: false\n        removeZero: false,\n\n        // If removeZero is true, exclude this keys\n        // Default: []\n        exclude: []\n    },\n\n    object: {\n\n        // Remove empty objects ({})\n        // Default: false\n        removeEmpty: false,\n\n        // If removeEmpty is true, exclude this keys\n        // Default: []\n        exclude: []\n    },\n\n    array: {\n\n        // Remove empty arrays ([])\n        // Default: false\n        removeEmpty: false,\n\n        // If removeEmpty is true, exclude this keys\n        // Default: []\n        exclude: []\n    }\n}\n```\n\n***Note!*** All config keys are optionals\n\n## Examples\n\nCheck out `example/` folder for usage examples\n\n## Reporting Issues\n\nWe use GitHub Issues as the official bug tracker for JMinor. Here are some advices for our users that want to report an issue:\n\n1. Make sure that you are using the latest version of JMinor. The issue that you are about to report may be already fixed in the latest master branch version: https://github.com/uditalias/jminor/tree/master.\n2. Providing us reproducible steps for the issue will shorten the time it takes for it to be fixed. A JSFiddle is always welcomed, and you can start from this [basic one](https://jsfiddle.net/udidu/7x38s4gb/1).\n3. Some issues may be browser specific, so specifying in what browser you encountered the issue might help.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuditalias%2Fjminor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuditalias%2Fjminor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuditalias%2Fjminor/lists"}