{"id":19806619,"url":"https://github.com/timnew/mutator","last_synced_at":"2026-05-09T20:40:04.486Z","repository":{"id":19139896,"uuid":"22369968","full_name":"timnew/mutator","owner":"timnew","description":"A function to convert plain javascript object(usually deserialized from JSON) into some class instance","archived":false,"fork":false,"pushed_at":"2015-09-08T14:11:36.000Z","size":180,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T06:52:07.478Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","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/timnew.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":"2014-07-29T06:29:29.000Z","updated_at":"2021-08-28T01:08:17.000Z","dependencies_parsed_at":"2022-08-01T02:48:47.858Z","dependency_job_id":null,"html_url":"https://github.com/timnew/mutator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timnew%2Fmutator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timnew%2Fmutator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timnew%2Fmutator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timnew%2Fmutator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timnew","download_url":"https://codeload.github.com/timnew/mutator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241150393,"owners_count":19918350,"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":[],"created_at":"2024-11-12T09:08:01.425Z","updated_at":"2026-05-09T20:40:04.417Z","avatar_url":"https://github.com/timnew.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"mutator [![Bower version][bower-image]][homepage] [![NPM version][npm-image]][npm-url]\n=======\n\n\u003e A function to convert plain javascript object(usually deserialized from JSON) into some class instance\n\nInstall\n-------\n\nInstall using [bower][bower-url]:\n\n    $ bower install mutator --save\n\n\nInstall using [npm][npm-homepage]:\n\n    $ npm install mutator --save\n\n\nQuick Start\n------------\n\nSignature:\n\n```\nfunction mutate(instance, class, [argument passed to constructor])\n```\n\nIn Node.js:\n\n```javascript\nconst mutate = require('mutator');\n\nmutate(instance, klass);\n```\n\nIn Browser:\n\n```javascript\nmutate(instance, klass);\n```\n\nEnvironment Support\n---------------\n`Mutator` works fine in most browsers and `Node.js`.\n\nFor `Internet Explorer`, prior than `IE 11`, because of lack of `object.__proto__`, a hard-copy work around is applied.\n\nQuick Sample\n------------\n\nA simple `Rect` class definition\n\n```coffeescript\nclass Rect\n  constructor: (width, height) -\u003e\n  \t@width = width if width?\n  \t@height = height if height?\n  \t\n  area: -\u003e\n  \t@width * @height\n\nrect = new Rect(100, 100) # A rect instance\n\nconsole.log rect.area() # should print 10000\n\nrectJSON = JSON.stringify(rect) # Serialize the object into JSON\n\n###\n{\n  \"width\": 100,\n  \"height\": 100\n}\n###\n```\n\n`rectJSON` is usually stored into file or transmitted via ajax call.\n\nWhen consuming the JSON\n\n```coffeescript\n\nmutate = require('mutator')\n\nrectCopy = JSON.parse(rectJSON)\n\nconsole.log rectCopy.area() # Got error: undefined isn't a function!\n\nrectClone = mutate(rectCopy, Rect)\n\nconsole.log rectClone == rectCopy # true, they are the same instance\nconsole.log rectCopy.area() # got 10000\n\n```\n\n## License\nMIT\n\n[![NPM download][npm-download]][npm-url]\n\n[homepage]: https://github.com/timnew/mutator\n[bower-image]: https://badge.fury.io/bo/widget.coffee.svg\n[bower-url]: http://bower.io/\n[npm-image]: http://img.shields.io/npm/v/mutator.svg\n[npm-download]: http://img.shields.io/npm/dm/mutator.svg?style=flat\n[npm-url]: https://www.npmjs.org/package/mutator\n[npm-homepage]: https://www.npmjs.org/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimnew%2Fmutator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimnew%2Fmutator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimnew%2Fmutator/lists"}