{"id":13719333,"url":"https://github.com/maple3142/wasm-jseval","last_synced_at":"2025-05-07T11:31:38.225Z","repository":{"id":55874793,"uuid":"231609725","full_name":"maple3142/wasm-jseval","owner":"maple3142","description":"A safe eval library based on WebAssembly and Duktape/QuickJS.","archived":false,"fork":false,"pushed_at":"2020-01-04T03:36:22.000Z","size":4329,"stargazers_count":232,"open_issues_count":3,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-14T08:36:23.312Z","etag":null,"topics":["duktape","eval","webassembly"],"latest_commit_sha":null,"homepage":"","language":"C","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/maple3142.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":"2020-01-03T14:58:13.000Z","updated_at":"2024-10-16T10:55:30.000Z","dependencies_parsed_at":"2022-08-15T08:20:35.305Z","dependency_job_id":null,"html_url":"https://github.com/maple3142/wasm-jseval","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/maple3142%2Fwasm-jseval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fwasm-jseval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fwasm-jseval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maple3142%2Fwasm-jseval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maple3142","download_url":"https://codeload.github.com/maple3142/wasm-jseval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252868869,"owners_count":21816926,"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":["duktape","eval","webassembly"],"created_at":"2024-08-03T01:00:46.568Z","updated_at":"2025-05-07T11:31:33.206Z","avatar_url":"https://github.com/maple3142.png","language":"C","readme":"# wasm-jseval\n\nA safe **eval** library based on WebAssembly and [Duktape](https://duktape.org/)/[QuickJS](https://bellard.org/quickjs/).\n\n[Duktape Demo](https://gh.maple3142.net/maple3142/duktape-eval/ae198189baf244ff062901475e8877637d265df3/example/example.html) | [Source code of Duktape Demo](https://github.com/maple3142/duktape-eval/blob/master/example/example.html)\n\n## Usage\n\nIn node:\n\n```js\nconst { duktapeEval, quickjsEval } = require('wasm-jseval')\nduktapeEval.getInstance().then(mod =\u003e {\n\tconsole.log(mod.eval('1+1')) // 2\n\tconst add = mod.newFunction(['a', 'b'], 'return a+b')\n\tconsole.log(add(1, 2)) // 3\n})\nquickjsEval.getInstance().then(mod =\u003e {\n\tconsole.log(mod.eval('1+1')) // 2\n\tconst add = mod.newFunction(['a', 'b'], 'return a+b')\n\tconsole.log(add(1, 2)) // 3\n})\n```\n\nIn browser:\n\n```html\n\u003cscript src=\"https://unpkg.com/wasm-jseval/duktapeEval.js\"\u003e\u003c/script\u003e\n\u003c!-- \u003cscript src=\"https://unpkg.com/wasm-jseval/quickjsEval.js\"\u003e\u003c/script\u003e --\u003e\n\u003cscript\u003e\n\t// or quickjsEval\n\tduktapeEval.getInstance().then(mod =\u003e {\n\t\tconsole.log(mod.eval('1+1')) // 2\n\t\tconst add = mod.newFunction(['a', 'b'], 'return a+b')\n\t\tconsole.log(add(1, 2)) // 3\n\t})\n\u003c/script\u003e\n```\n\n## API\n\n### `duktapeEval.getInstance(): Promise\u003cInstance\u003e`\n\nReturns a Promise to resolve the duktapeEval instance.\n\n### `quickjsEval.getInstance(): Promise\u003cInstance\u003e`\n\nReturns a Promise to resolve the quickjsEval instance.\n\n### `Instance`\n\n#### `Instance#eval(code: string): any`\n\nEvaluate JavaScript string in Duktape engine, and return a value.\n\n#### `Instance#newFunction(argnames: string[], body: string): (...any) =\u003e any`\n\nCreate a function like `new Function` to be called afterward.\n\n## Q\u0026A\n\n### What can it runs?\n\n`duktapeEval` can run ES5 syntax and some ES6, ES7 capabilities. `quickjsEval` can run almost complete feature set of ES10.\n\n### Why two version?\n\n`duktapeEval` is smaller, but less feature. `quickjsEval` has a more complete JavaScript support, but it result in bigger size.\n\n### How can I pass data to it?\n\n`JSON.stringify` is your friend. `newFunction` is a good choice too.\n\n### How can I return data from it?\n\nJust like normal `eval`, for example `var a={};a.prop=1;a` will return `{ prop: 1 }`. But keep in mind, only JSON serializable data can be returned.\n\n### How big is this?\n\n`duktapeEval` is about 348kB, and gzipped version is 154kB.\n`quickjsEval` is about 484kB, and gzipped version is 225kB.\n","funding_links":[],"categories":["C"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaple3142%2Fwasm-jseval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaple3142%2Fwasm-jseval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaple3142%2Fwasm-jseval/lists"}