{"id":22769710,"url":"https://github.com/bfontaine/tp.js","last_synced_at":"2025-08-26T22:04:56.563Z","repository":{"id":11310510,"uuid":"13728704","full_name":"bfontaine/tp.js","owner":"bfontaine","description":"Optimize your tail-recursive functions","archived":false,"fork":false,"pushed_at":"2013-10-20T23:27:31.000Z","size":176,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-23T08:49:34.009Z","etag":null,"topics":["js","library"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/bfontaine.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":"2013-10-20T23:14:48.000Z","updated_at":"2017-06-30T15:39:47.000Z","dependencies_parsed_at":"2022-09-13T06:50:45.098Z","dependency_job_id":null,"html_url":"https://github.com/bfontaine/tp.js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bfontaine/tp.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Ftp.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Ftp.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Ftp.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Ftp.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bfontaine","download_url":"https://codeload.github.com/bfontaine/tp.js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bfontaine%2Ftp.js/sbom","scorecard":{"id":235918,"data":{"date":"2025-08-11","repo":{"name":"github.com/bfontaine/tp.js","commit":"dad7cb0f5398b1afcbc481f87c0b59c7131a49ed"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/9 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":9,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/bfontaine/.github/SECURITY.md:1","Info: Found linked content: github.com/bfontaine/.github/SECURITY.md:1","Warn: One or no descriptive hints of disclosure, vulnerability, and/or timelines in security policy","Info: Found text in security policy: github.com/bfontaine/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}}]},"last_synced_at":"2025-08-17T05:45:27.627Z","repository_id":11310510,"created_at":"2025-08-17T05:45:27.628Z","updated_at":"2025-08-17T05:45:27.628Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272260571,"owners_count":24902391,"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","status":"online","status_checked_at":"2025-08-26T02:00:07.904Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["js","library"],"created_at":"2024-12-11T15:14:12.233Z","updated_at":"2025-08-26T22:04:56.526Z","avatar_url":"https://github.com/bfontaine.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tp.js\n\n[![Build Status](https://travis-ci.org/bfontaine/tp.js.png?branch=master)](https://travis-ci.org/bfontaine/tp.js)\n\n\u003ci\u003e\u003cb\u003etp\u003c/b\u003e\u003c/i\u003e is a lightweight, experimental, library which optimize your\ntail-recursive functions so they won’t blow up the stack.\n\n## Install\n\n### With Node\n\nInstall it with `npm`:\n\n    [sudo] npm install [-g] tp\n\nThen use:\n\n    var tp = require('tp');\n\n### In the browser\n\nInclude `tp.min.js` in your page, before using it. The file is 0.4kb, and only\n0.2kb gzip'd. You can download it from [GitHub][gh].\n\n[gh]: https://github.com/bfontaine/tp.js/\n\n## Usage\n\nHere is a tail-recursive `sum` function, which sums all positive numbers\nbelow its first argument:\n\n```js\nfunction sum( e, acc ) {\n    if (acc == undefined) {\n        acc = 0;\n    }\n    return e \u003c= 0 ? acc : sum( e-1, e+acc );\n}\n\nsum(2); // 3\nsum(200); // 20100\nsum(20000); // RangeError: Maximum call stack size exceeded\n```\n\nHere is the same function defined using tp:\n\n```js\nvar sum = tp(function(recur) {\n    return function sum( e, acc ) {\n        if (acc == undefined) {\n            acc = 0;\n        }\n        return e \u003c= 0 ? acc : recur( e-1, e+acc );\n    }\n});\n\nsum(2); // 3\nsum(200); // 20100\nsum(20000); // 200010000\nsum(2000000); // 2000001000000\n```\n\nThe function is the same, but we define it in an anonymous function which takes\na mysterious `recur` as an argument, and use it for recursive calls instead of\nthe original name of the function.\n\n### Limits\n\nBecause this library is experimental, it only works in a few cases. The function\n*must* be tail-recursive and *must* use recursion to return something. Below are\nsome examples of functions that won’t work:\n\n- `function fibo(x) { return x \u003c 2 ? 1 : (fibo(x-1) + fibo(x-2)); }`: not\n  tail-recursive\n- `function lX(s, n) { if (n == 0) { return; } console.log(s); lX(s, n-1); }`:\n  the recursive call is not used to return something\n- `function a() { return function() {}; }`: \u003ci\u003etp\u003c/i\u003e doesn’t support functions\n  that return functions (see below for more explanations).\n\nPlease not that \u003ci\u003etp\u003c/i\u003e doesn’t speed up your function, it only prevents it to blow\nup the stack. It means you can make an infinite recursive function, it’ll work.\n\n## How it works\n\nFrom [Wikipedia][wk]:\n\u003e a trampoline is a loop that iteratively invokes thunk-returning functions\n\u003e (continuation-passing style). A single trampoline is sufficient to express all\n\u003e control transfers of a program; a program so expressed is trampolined, or in\n\u003e trampolined style; converting a program to trampolined style is trampolining.\n\u003e Trampolined functions can be used to implement tail-recursive function calls in\n\u003e stack-oriented programming languages.\n\n[wk]: https://en.wikipedia.org/wiki/Trampoline_(computing)#High_level_programming\n\n\u003ci\u003etp\u003c/i\u003e uses a little bit of magic to bind `recur` in your function to\npre-binded version of itself. Your function now returns either a final result,\neither itself binded to some arguments. Then, \u003ci\u003etp\u003c/i\u003e repeatedly calls your function\nuntil it returns something that’s not a function. So it won’t work if your\nfunction returns a function, because \u003ci\u003etp\u003c/i\u003e doesn’t know if it has to call this\nfunction or return it. \u003ci\u003etp\u003c/i\u003e then works as a proxy to your original function,\nhanding the annoying stuff.\n\n## Licence\n\nMIT\n\n## Changelog\n\n### v0.1.0\n\n- first version\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfontaine%2Ftp.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbfontaine%2Ftp.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbfontaine%2Ftp.js/lists"}