{"id":28000483,"url":"https://github.com/hanmoehtet/funkify","last_synced_at":"2026-05-09T10:20:37.386Z","repository":{"id":57748399,"uuid":"523241182","full_name":"HanMoeHtet/funkify","owner":"HanMoeHtet","description":"Serialize and deserialize objects including functions, async functions, class instances, classes.","archived":false,"fork":false,"pushed_at":"2022-08-10T10:47:46.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T23:53:08.026Z","etag":null,"topics":["deserialize","function","funkify","javascript","json","serialize","stringify"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@han-moe-htet/funkify","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/HanMoeHtet.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":"2022-08-10T07:17:10.000Z","updated_at":"2023-03-17T13:10:23.000Z","dependencies_parsed_at":"2022-09-11T19:00:18.529Z","dependency_job_id":null,"html_url":"https://github.com/HanMoeHtet/funkify","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanMoeHtet%2Ffunkify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanMoeHtet%2Ffunkify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanMoeHtet%2Ffunkify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HanMoeHtet%2Ffunkify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HanMoeHtet","download_url":"https://codeload.github.com/HanMoeHtet/funkify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166490,"owners_count":21864471,"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":["deserialize","function","funkify","javascript","json","serialize","stringify"],"created_at":"2025-05-08T23:53:11.975Z","updated_at":"2026-05-09T10:20:37.339Z","avatar_url":"https://github.com/HanMoeHtet.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# [Funkify](https://github.com/HanMoeHtet/funkify) \u0026middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) [![npm version](https://img.shields.io/npm/v/@han-moe-htet/funkify.svg?style=flat)](https://www.npmjs.com/package/@han-moe-htet/funkify)\n\nSerialize and deserialize objects including functions, async functions, class instances, classes. Uses `JSON.stringify` and `JSON.parse` under the hood with the replacer function that prepend `myFunction.toString()` with a `\u003cFUNCTION\u003e` prefix.\nSupport for native functions is included. Variables used inside the function must be scoped correctly. See [caveats](#caveats) section below.\n\n## Installation\n\n```bash\nyarn add @han-moe-htet/funkify\n```\n\nOr\n\n```bash\nnpm install @han-moe-htet/funkify\n```\n\n## Usage\n\n### Serialize object with function\n\n```typescript\nimport assert from 'assert';\nimport { Funkify } from '@han-moe-htet/funkify';\n\nconst funkify = new Funkify();\n\nconst obj = {\n  name: 'world',\n  hello: (name: string) =\u003e `Hello ${name}`,\n};\n\nconst serialized = funkify.serialize(obj);\n\nconst deserialized = funkify.deserialize\u003ctypeof obj\u003e(serialized);\n\nassert.equal(obj.hello(obj.name), deserialized.hello(deserialized.name));\n```\n\n### Serialize function\n\n```typescript\nconst hello = (name: string) =\u003e `Hello ${name}`;\n\nconst serialized = funkify.serializeFunction(hello);\n\nconst deserialized = funkify.deserializeFunction\u003ctypeof hello\u003e(serialized);\n\nassert.equal(hello('world'), deserialized('world'));\n```\n\n### Serialize native function\n\nSince `toString` of native methods returns `function () { [native code] }`, you need to use a special function `serializeNativeFunction` add pass the native function path to serialize native functions. Native functions will be prefixed with `\u003cFUNCTION\u003e\u003cNATIVE\u003e`.\n\n```typescript\ntry {\n  serialized = funkify.serialize(now);\n} catch (e) {\n  if (e instanceof InvalidFunctionException) {\n    serialized = funkify.serializeNativeFunction('Date.now');\n  } else {\n    throw e;\n  }\n}\n\nassert.equal(now, funkify.deserializeNativeFunction\u003ctypeof now\u003e(serialized));\n```\n\nOr you can wrap the native function with a custom function and serialize the custom function.\n\n```typescript\nconst now = () =\u003e Date.now();\n\nconst serialized = funkify.serialize(now);\nconst deserialized = funkify.deserialize\u003ctypeof now\u003e(serialized);\n```\n\n### Serialize class instance\n\n```typescript\nclass Hello {\n  constructor(private name: string) {}\n\n  hello() {\n    return `Hello ${this.name}`;\n  }\n}\n\nconst obj = new Hello('world');\n\nconst serialized = funkify.serialize({\n  ...obj,\n  hello: obj.hello,\n});\n\nconst deserialized = funkify.deserialize\u003ctypeof obj\u003e(serialized);\n```\n\n### Serialize class\n\n```typescript\nconst serialized = funkify.serialize(Hello);\n\nconst NewHello = funkify.deserialize\u003ctypeof Hello\u003e(serialized);\n\nassert.equal(Hello.toString(), NewHello.toString());\nassert.equal(new Hello('world').hello(), new NewHello('world').hello());\n```\n\nSee more examples at [examples](https://github.com/HanMoeHtet/funkify/tree/main/app/src/examples).\n\n## Caveats\n\nThe following deserialized function will throw error because the scope of `name` variable is lost when serialized.\n\n```typescript\nconst name = 'world';\nconst hello = () =\u003e `Hello ${name}`;\n\nconst serialized = funkify.serialize(hello);\nconst deserialized = funkify.deserialize\u003ctypeof hello\u003e(serialized);\n```\n\n## Development\n\n1. Clone the repository\n2. Run the following command to install local package in the app directory.\n\n```bash\nyarn link \u0026\u0026 yarn --cwd app link @han-moe-htet/funkify\n```\n\n3. Run the following command to run the app.\n\n```bash\nyarn app\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanmoehtet%2Ffunkify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhanmoehtet%2Ffunkify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhanmoehtet%2Ffunkify/lists"}