{"id":17297997,"url":"https://github.com/inlife/squirrel-require","last_synced_at":"2026-01-06T21:17:11.150Z","repository":{"id":150879984,"uuid":"86447762","full_name":"inlife/squirrel-require","owner":"inlife","description":"📦  Create and manage your squirrel modules","archived":false,"fork":false,"pushed_at":"2019-02-01T16:25:44.000Z","size":16,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-01T03:18:16.691Z","etag":null,"topics":["commonjs","dofile","library","nut","require","squirrel","squirrel-lang","squirrel-modules","visibility"],"latest_commit_sha":null,"homepage":"","language":"Squirrel","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/inlife.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-03-28T10:38:37.000Z","updated_at":"2023-11-02T11:12:27.000Z","dependencies_parsed_at":"2023-07-23T14:15:55.180Z","dependency_job_id":null,"html_url":"https://github.com/inlife/squirrel-require","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-require","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-require/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-require/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inlife%2Fsquirrel-require/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inlife","download_url":"https://codeload.github.com/inlife/squirrel-require/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245736209,"owners_count":20663854,"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":["commonjs","dofile","library","nut","require","squirrel","squirrel-lang","squirrel-modules","visibility"],"created_at":"2024-10-15T11:17:45.729Z","updated_at":"2026-01-06T21:17:11.110Z","avatar_url":"https://github.com/inlife.png","language":"Squirrel","readme":"# squirrel-require\nRequire module for squirrel-lang\n\nHandling multiple files via squirrel might be problem.\nEven if you are using dofile/loadfile at some point you will probably find yourself experiencing some inconviniences related to global namespacing and visibility.\n\n## Purpose\n\nCreate simple, and working alternative to Node.js implementation of **CommonJS** for squirrel lang.\nThis library allows you to use all beauty of modular concepts that you \\*might probably\\* used to while writing on Node.js.\n\n## Features\n\n* It can load modules in **multiple ways**: filename w/o extension, filename w/ extension, directory name with index.nut file, and even via module name from squirrel_modules directory.\n* It is **isolated**! (you can easily define some global functions or variables inside module, but they wont be visible to any other module).\n* It comes with builtin `\"path\"` core library, which is kinda similar to one, used in Node.js.\n* It **caches** modules and resolves *cyclic requires*, so no worries about that.\n* It suppors **multiple exports** from same module, via `module.exports`\n\nAs you see most of the features, are similar to Node.js's require.\n\nSeparate modules, in lets say `squirrel_modules` dir with package.json or package.nut inside a folder named after module title.\nThis package.* file should contain almost same information as npm's package.json does.\nYou can look example for this in `examples/` folder.\n\n## Installation\n\n1. Download or clone repository. Or just copy file src/require.nut, its up to you.\n2. Load that file at the beginning of your main squirrel script:\n\n```js\nlocal require = dofile(\"./squirrel-require/src/require.nut\", {\n    debug = false,\n    aliases = {\n        engine = \"./src/engine\",\n        tests = \"./tests/\",\n    },\n})();\n```\n\n3. Use it!\n\n```js\n// mymodule.nut\n\nmodule.exports = {\n    hello = function(text) {\n        print(\"Hello \" + text + \"\\n\");\n    },\n};\n\n```\n\n```js\n// main.nut\nlocal mymodule = require(\"./mymodule\");\n\n// do stuff\nprint( mymodule.hello(\"world\") );\n```\n\nYou can look at more examples at examples/ dir.\n\n## Documentation\n\nAs soon as you attach squirrel-require to your project, your file global namespace becomes populated with several tables/methods:\n\n* `__dirname` - relative directory of the current file (calculated is based on option of the attaching: dofile(...)(\"THIS_ARGUMENT\"))\n* `__filename` - relative filepath of the current file, (calculated same way as above)\n* `require` - method for including modules\n* `globals` - table contaning all current global members (can be defined inside submodule, and be available at the top)\n* `console` - table\n* * `log` - method for logging various data of plain types\n* `module` - table (current module)\n* * `loaded` - boolean representing whether or not this module've been loaded\n* * `exports` - table of exporting values, any given to export data should be put there\n* * `parent` - reference to the parent module (the one who required this module first)\n* * `children` - array of child modules (required by this module)\n* * `dirname` - alias of `__dirname`\n* * `filename` - alias of `__filename`\n* `process` - table\n* * `stdin` - stdin stream (alias of the default global `stdin`)\n* * `stdout` - stdout stream (alias of the default global `stdout`)\n* * `stderr` - stderr stream (alias of the default global `stderr`)\n* * `version` - version string (alias of the default global `_version_`)\n\nAll these tables/methods will be automatically inserted(binded) into child modules on their require time.\n\n## License\n\nLook [LICENSE.md](LICENSE.md)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlife%2Fsquirrel-require","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finlife%2Fsquirrel-require","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finlife%2Fsquirrel-require/lists"}