{"id":13658430,"url":"https://github.com/meyfa/runstring","last_synced_at":"2025-04-12T23:22:27.519Z","repository":{"id":21385167,"uuid":"92623110","full_name":"meyfa/runstring","owner":"meyfa","description":"Convert JS functions to runnable strings. With parameter serialization!","archived":false,"fork":false,"pushed_at":"2024-04-10T15:08:36.000Z","size":690,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-10T17:40:28.139Z","etag":null,"topics":["electron","eval","executable","functions","javascript","nodejs","runnable","string","stringify"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/runstring","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/meyfa.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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},"funding":{"github":"meyfa"}},"created_at":"2017-05-27T20:43:34.000Z","updated_at":"2024-04-15T12:48:15.908Z","dependencies_parsed_at":"2024-03-09T22:38:37.645Z","dependency_job_id":"f69cb8f3-429f-44fb-b0c5-9922c076a376","html_url":"https://github.com/meyfa/runstring","commit_stats":{"total_commits":85,"total_committers":4,"mean_commits":21.25,"dds":0.5882352941176471,"last_synced_commit":"68f16b0271bb3ad73ba9dcb53ef9c58ec1a0e61b"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Frunstring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Frunstring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Frunstring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meyfa%2Frunstring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meyfa","download_url":"https://codeload.github.com/meyfa/runstring/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248644213,"owners_count":21138570,"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":["electron","eval","executable","functions","javascript","nodejs","runnable","string","stringify"],"created_at":"2024-08-02T05:00:59.494Z","updated_at":"2025-04-12T23:22:27.503Z","avatar_url":"https://github.com/meyfa.png","language":"TypeScript","readme":"# runstring\n\n[![CI](https://github.com/meyfa/runstring/actions/workflows/main.yml/badge.svg)](https://github.com/meyfa/runstring/actions/workflows/main.yml)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/39e38e2764a453e66a43/test_coverage)](https://codeclimate.com/github/meyfa/runstring/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/39e38e2764a453e66a43/maintainability)](https://codeclimate.com/github/meyfa/runstring/maintainability)\n\nConvert JS functions to runnable strings, with parameter serialization!\n(We also support TypeScript natively!)\n\nThis was made for Electron's `executeJavaScript()` method, so that the code does\nnot need to be constructed as a string but can be passed as a function.\nrunstring will convert that function and its parameters to an IIFE string.\n\nThe following parameter types are supported:\n\n- Literals `null`, `undefined`, `true`, `false`\n- Numbers\n- Strings\n- Functions (both standard notation and arrow notation)\n- Arrays\n- Objects\n\nStrings will be escaped. Nesting of values (in objects and arrays) is supported\nwithout limit.\n\n## Usage\n\n### Basic Usage\n\nSimply invoke the module with a function and its parameters to obtain the IIFE\nstring.\n\n```js\nconst runstring = require('runstring')\n\nconst code = runstring(myFunction, arg1, arg2 /* , ... */)\n// do something with `code`\n```\n\n### Example 1\n\n```js\nconst runstring = require('runstring')\n\nconst code = runstring(function (a, b) {\n  return a + b\n}, 5, 7)\n```\n\n`code` would now store a string similar to this:\n`';(function (a, b) { return a + b })(5, 7);'`. That string could be passed to\nElectron's `executeJavaScript()`, or the standard `eval()` (eval is evil, but if\nyou have your reasons to use it, might as well do it right).\n\n### Example 2\n\nAny parameter type is supported \u0026mdash; numbers, strings, objects, arrays, and\neven other functions can all be passed to the module for stringification:\n\n```js\nconst runstring = require('runstring')\n\nconst code = runstring(function (predicate, action) {\n  const elements = document.getElementsByClassName('item')\n  for (let i = 0; i \u003c elements.length; ++i) {\n    if (predicate(elements[i])) {\n      action(elements[i])\n    }\n  }\n}, (e) =\u003e e.tagName.toLowerCase() === 'div', removeElement)\n\nfunction removeElement (e) {\n  e.parentNode.removeChild(e)\n}\n```\n\n`code` would now store the following string:\n\n```\n';(function (predicate, action) {\n  const elements = document.getElementsByClassName('item')\n  for (let i = 0; i \u003c elements.length; ++i) {\n    if (predicate(elements[i])) {\n      action(elements[i])\n    }\n  }\n})((e) =\u003e e.tagName.toLowerCase() === 'div', function removeElement (e) {\n  e.parentNode.removeChild(e)\n});'\n```\n","funding_links":["https://github.com/sponsors/meyfa"],"categories":["JavaScript","TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeyfa%2Frunstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeyfa%2Frunstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeyfa%2Frunstring/lists"}