{"id":17791260,"url":"https://github.com/schell/mod","last_synced_at":"2025-09-04T10:39:18.341Z","repository":{"id":66386465,"uuid":"2085189","full_name":"schell/mod","owner":"schell","description":"JS modules to aid in code separation and organization.","archived":false,"fork":false,"pushed_at":"2013-01-23T00:10:15.000Z","size":188,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-05T20:49:30.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/schell.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}},"created_at":"2011-07-21T19:07:28.000Z","updated_at":"2016-12-14T07:39:03.000Z","dependencies_parsed_at":"2023-02-20T03:15:38.810Z","dependency_job_id":null,"html_url":"https://github.com/schell/mod","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/schell/mod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fmod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fmod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fmod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fmod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/schell","download_url":"https://codeload.github.com/schell/mod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/schell%2Fmod/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273594989,"owners_count":25134256,"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-09-04T02:00:08.968Z","response_time":61,"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":[],"created_at":"2024-10-27T10:50:26.144Z","updated_at":"2025-09-04T10:39:18.320Z","avatar_url":"https://github.com/schell.png","language":"JavaScript","readme":"mod\n=======\n`mod` is a function for defining and loading JS modules from a browser. \nIt serves as a method to break your project into a tree of maintainable \npieces that depend on each other, much like an include or import statement. \nOnce your project is loaded you may use mod to compile your code into one \nmonolithic closure.\n\nUse\n---\n`mod` uses initialization objects (called packages, internally) to define \nmodules. An initialization object takes a name, an array of dependencies \nand an init function, which by my convention always returns a constructor. \n\nInclude mod.js in your `\u003chead\u003e`:\n\t\n```html\n\u003cscript src=\"mod.js\" type=\"text/javascript\" charset=\"utf-8\"\u003e\u003c/script\u003e\n```\n\nand then set up your a module:\n\n```html\n\u003cscript type=\"text/javascript\" charset=\"utf-8\"\u003e\n```\n```javascript\n\t// create a main module\n\t\tmod({\n\t\t\tname : 'SomeModule',\n\t\t\tdependencies : [\n\t\t\t\t'path/to/AnotherModule.js',\n\t\t\t\t'path/to/YetAnotherModule.js'\n\t\t\t],\n\t\t\tinit : function initMain(AnotherModule, YetAnotherModule) {\n\t\t\t\t// We can access AnotherModule and YetAnotherModule because mod.js\n\t\t\t\t// initializes dependencies in order and provides them to your init\n\t\t\t\t// in the order that you declare them in the dependencies array above...\n\t\t\t\tfunction SomeConstructor() {\n\t\t\t\t\tthis.foo = \"bar\";\n\t\t\t\t}\n\t\t\t\tSomeConstructor.prototype = {\n\t\t\t\t\tanotherInstance : new AnotherModule(),\n\t\t\t\t\tyetAnotherInstance : new YetAnotherInstance()\n\t\t\t\t};\n\t\t\t\treturn SomeConstructor;\n\t\t\t}\n\t\t});\n```\n```html\n\u003c/script\u003e\n```\n\nIn this first call `mod` packages your module and starts loading its dependencies (either through XMLHttpRequest or script tag injection). \nOnce the dependencies are loaded, which probably define more modules and load more scripts, the result of the `init` function is stored in `mod.modules`, in this case as `mod.modules.SomeModule`, so they don't clutter global space. \nThe initialized modules are provided to other `init` functions in the order they are asked for.\n\nAs an added benefit, you can share data between modules using `mod.modules`.\n\nCompiling\n---------\nIf you use `mod` to write lots of modules (when you're making a big project) `mod` can 'compile' your project for you, removing all instances of `mod`. \nIt essentially takes all your `init` functions and prints them to one monolithic file, which you can then compress with YUI or Google Closure. \nTo do this, load your project in your browser, open the js console and type `mod.printCompilation()`. Alternatively, to store in a string, type `var compilation = mod.compile();`.\n\nExamples\n--------\nFor more examples check out my other project `bang` at https://github.com/schell/bang\nNotes\n-----\nIn development situations the scripts `mod` loads can change often. In order to avoid the browser cacheing these files (and returning an old version of your scripts) set `mod.nocache = true`, which will enable the \"force re-download\" feature. Unfortunately with `mod.nocache` set to true, many javascript debuggers can't set breakpoints on the loaded scripts. Keep this in mind.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschell%2Fmod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fschell%2Fmod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fschell%2Fmod/lists"}