{"id":15387140,"url":"https://github.com/wildhoney/moggy","last_synced_at":"2026-03-24T11:30:15.320Z","repository":{"id":57301048,"uuid":"81142239","full_name":"Wildhoney/Moggy","owner":"Wildhoney","description":"Miniature ~2kb library that brings immutability to existing prototype functions employing the principle of least astonishment.","archived":false,"fork":false,"pushed_at":"2017-02-16T10:23:52.000Z","size":1613,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T02:35:26.465Z","etag":null,"topics":["functional","immutability","immutable","prototype","side-effect","tuples"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Wildhoney.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-06T22:55:49.000Z","updated_at":"2017-03-29T01:04:16.000Z","dependencies_parsed_at":"2022-09-26T16:31:25.300Z","dependency_job_id":null,"html_url":"https://github.com/Wildhoney/Moggy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FMoggy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FMoggy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FMoggy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wildhoney%2FMoggy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wildhoney","download_url":"https://codeload.github.com/Wildhoney/Moggy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239942753,"owners_count":19722330,"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":["functional","immutability","immutable","prototype","side-effect","tuples"],"created_at":"2024-10-01T14:52:12.916Z","updated_at":"2026-03-24T11:30:15.267Z","avatar_url":"https://github.com/Wildhoney.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Moggy](media/logo.png)\n\n\u003e \u003csub\u003e\u003csup\u003e*moggy → transmogrify → \"transform in a surprising or magical manner.\"*\u003c/sup\u003e\u003c/sub\u003e\u003cbr /\u003e\n\u003e Miniature ~2kb library that brings immutability to existing prototype functions employing the [principle of least astonishment](https://en.wikipedia.org/wiki/Principle_of_least_astonishment).\n\n[![forthebadge](http://forthebadge.com/images/badges/contains-cat-gifs.svg)](http://forthebadge.com)\n[![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com)\n\n## Getting Started\n\nMoggy inspects the `prototype` of the value and creates an `object` that takes the functions from the prototype \u0026ndash; it's therefore not easy to say *which* functions Moggy implements, since ECMAScript functions that mutate the value will respond with a tuple of `[sideEffect, returnValue]`, whereas functions that are already immutable in their nature will respond as-is.\n\n```javascript\nimport m from 'moggy';\n\nconst a = m([1, 2, 3]);\nconst b = a.push(4); \nconst c = a.pop();\n\nconsole.log(a); // [1, 2, 3]\nconsole.log(b); // [sideEffect = [1, 2, 3, 4], returnValue = 4]\nconsole.log(c); // [sideEffect = [1, 2], returnValue = 3]\n```\n\nIn such cases it's not always obvious which value you may require \u0026ndash; that's why Moggy returns both as a tuple. In the case of `push` you're more likely to require `sideEffect`, however in `pop` you're more likely to require the `returnValue`.\n\nUsing destructuring it's easy to take what you need \u0026ndash; ignoring what you don't need.\n\n```javascript\nimport m from 'moggy';\n\nconst a = m([1, 2, 3]);\nconst [b] = a.push(4);\nconst [, c] = a.pop();\n\nconsole.log(a); // [1, 2, 3]\nconsole.log(b); // [1, 2, 3, 4]\nconsole.log(c); // 3\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildhoney%2Fmoggy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwildhoney%2Fmoggy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwildhoney%2Fmoggy/lists"}