{"id":26094235,"url":"https://github.com/alii/scraggy","last_synced_at":"2026-05-14T01:39:58.370Z","repository":{"id":281377930,"uuid":"945096529","full_name":"alii/scraggy","owner":"alii","description":"Portable JS interpreter, built for avoiding eval() under strict CSP in the browser","archived":false,"fork":false,"pushed_at":"2025-03-09T17:41:31.000Z","size":331,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-05T20:46:48.303Z","etag":null,"topics":["interpreter","js","parser","vm"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/scraggy","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null}},"created_at":"2025-03-08T16:47:02.000Z","updated_at":"2025-03-31T20:40:45.000Z","dependencies_parsed_at":"2025-03-08T17:40:51.645Z","dependency_job_id":null,"html_url":"https://github.com/alii/scraggy","commit_stats":null,"previous_names":["alii/evaluate"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alii/scraggy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fscraggy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fscraggy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fscraggy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fscraggy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alii","download_url":"https://codeload.github.com/alii/scraggy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alii%2Fscraggy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33006752,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"ssl_error","status_checked_at":"2026-05-13T13:14:51.610Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["interpreter","js","parser","vm"],"created_at":"2025-03-09T12:50:46.649Z","updated_at":"2026-05-14T01:39:58.355Z","avatar_url":"https://github.com/alii.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003cimg width=\"150\" src=\"https://raw.githubusercontent.com/alii/scraggy/refs/heads/main/scraggy.png\" /\u003e\n\u003ch1\u003eScraggy\u003c/h1\u003e\n\u003c/div\u003e\n\nA relatively safe JavaScript code evaluator that doesn't use `eval()` or `Function()`. This library parses and executes JavaScript code using an AST-based approach.\n\n[![Tests](https://github.com/alii/scraggy/actions/workflows/bun-test.yml/badge.svg)](https://github.com/alii/scraggy/actions/workflows/bun-test.yml)\n\n## Features\n\n- Evaluates JavaScript code without using the built-in `eval()` or `Function()` constructor\n- Supports a subset of common JavaScript language features\n- Provides proper memory management and cleanup\n- Uses Acorn for parsing JavaScript into an AST\n\n## Installation\n\n```bash\nbun install scraggy\n```\n\n## Usage\n\n```typescript\nimport {evaluate} from 'scraggy';\n\n// Simple evaluation with an empty context\nconst result = await evaluate({}, '2 + 3'); // returns 5 (basic arithmetic works with no globals)\n\n// Evaluation with a context object\nconst context = {x: 10, y: 20};\nconst result = await evaluate(context, 'x + y'); // returns 30\n\n// More complex evaluations - no globals needed\nconst code = `\n  function factorial(n) {\n    if (n \u003c= 1) return 1;\n    return n * factorial(n - 1);\n  }\n  factorial(5)\n`;\nconst result = await evaluate({}, code); // returns 120\n```\n\n## Supported Features\n\n- Literals (numbers, strings, booleans, null, undefined)\n- Variables and scope handling (although there's no difference between var, const, let). There is also no hoisting\n- Object and array literals\n- Object property access (both dot notation and bracket notation)\n- Array element access\n- Function declarations and function expressions\n- Arrow functions\n- Rest parameters and spread operators\n- Binary expressions (+, -, \\*, /, %, etc.)\n- Logical expressions (\u0026\u0026, ||, ??)\n- Unary expressions (+, -, !, ~, typeof)\n- if/else statements\n- while loops\n- for loops (for, for...in, for...of)\n- try/catch/finally blocks\n- async/await with Promises\n- switch statements\n- Class declarations and class expressions with inheritance\n- Destructuring assignments (object and array)\n- Super references in class methods\n- Destructuring in function parameters\n- Template literals with expression interpolation\n- Optional chaining (?.)\n\n## Security Features\n\nThis evaluator is designed with security in mind:\n\n- **No Default Globals**: Unlike JavaScript's `eval()`, this evaluator does not provide ANY built-in global objects by default. This means features like `Promise`, `setTimeout`, `console` are not available unless you explicitly provide them.\n- **Explicit Context**: You must explicitly provide any global objects that your code needs through the context parameter, giving you fine-grained control over what's accessible.\n- **Sandboxed Execution**: The evaluator cannot access the host environment outside what you provide in the context.\n\n## Limitations and Unsupported Features\n\nTo avoid running into unexpected issues, be aware of the following unsupported features:\n\n### Unsupported Syntax\n\n- Module import/export statements\n- Private fields (#property)\n- Generator functions and yield\n- BigInt literals\n- Default values in destructuring assignments\n\n### Partially Supported\n\n- Regular expression literals (should be provided via global context)\n- Object method definitions use function expressions under the hood\n- Only basic error handling is implemented\n- Built-in objects like Promise, Error, Math, JSON, Date, etc. must be explicitly provided in the global context if needed\n- Nullish coalescing (??) is supported in binary expressions\n\n### Runtime Environment\n\n- No DOM or Web API support\n- Limited global object\n- No access to Node.js or Bun built-in modules\n\n## Development\n\nTo run tests:\n\n```bash\nbun test\n```\n\nTo typecheck:\n\n```bash\nbun tsc --noEmit\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falii%2Fscraggy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falii%2Fscraggy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falii%2Fscraggy/lists"}