{"id":21187179,"url":"https://github.com/milosdjakonovic/micromodules","last_synced_at":"2025-03-14T20:20:18.970Z","repository":{"id":30957061,"uuid":"126492742","full_name":"milosdjakonovic/micromodules","owner":"milosdjakonovic","description":"Minimalistic JavaScript module system for browsers.","archived":false,"fork":false,"pushed_at":"2022-12-10T12:46:15.000Z","size":93,"stargazers_count":1,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T13:07:46.520Z","etag":null,"topics":["amd","javascript-modules","modularization","module","module-system","modules"],"latest_commit_sha":null,"homepage":"https://milosdjakonovic.github.io/micromodules/","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/milosdjakonovic.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":"2018-03-23T13:58:59.000Z","updated_at":"2020-01-13T07:18:26.000Z","dependencies_parsed_at":"2023-01-14T18:02:14.888Z","dependency_job_id":null,"html_url":"https://github.com/milosdjakonovic/micromodules","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosdjakonovic%2Fmicromodules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosdjakonovic%2Fmicromodules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosdjakonovic%2Fmicromodules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milosdjakonovic%2Fmicromodules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milosdjakonovic","download_url":"https://codeload.github.com/milosdjakonovic/micromodules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243639724,"owners_count":20323546,"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":["amd","javascript-modules","modularization","module","module-system","modules"],"created_at":"2024-11-20T18:32:23.880Z","updated_at":"2025-03-14T20:20:18.948Z","avatar_url":"https://github.com/milosdjakonovic.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build status][travis-img]][travis] [![GitHub issues](https://img.shields.io/github/issues/milosdjakonovic/micromodules.svg)](https://github.com/milosdjakonovic/micromodules/issues) [![GitHub license](https://img.shields.io/github/license/milosdjakonovic/micromodules.svg)](https://github.com/milosdjakonovic/micromodules/blob/master/license) [![GitHub version](https://badge.fury.io/gh/milosdjakonovic%2Fmicromodules.svg)](https://badge.fury.io/gh/milosdjakonovic%2Fmicromodules) [![Maintainability](https://api.codeclimate.com/v1/badges/2b75b55af4b2da6c1cb1/maintainability)](https://codeclimate.com/github/milosdjakonovic/micromodules/maintainability) [![Twitter](https://img.shields.io/twitter/url/https/github.com/milosdjakonovic/micromodules.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:\u0026url=https%3A%2F%2Fgithub.com%2Fmilosdjakonovic%2Fmicromodules)\n\n\n\n# micromodules\n\nMinimalistic JavaScript module system for browsers.\n\n**micromodules** is a good way to organize browser code when using mastodon-like libraries and/or tooling is less desirable option. It does not load JS files for you but rather helps you to keep your code into meaningfull and reusable modules. \n**micromodules** weights only ~900B compressed and is suitable for placing into document's head or anywhere else.\n\n### Usage\n\nPlace the code anywhere before first usage. Even that is not strictly required, which will be explained soon.\n\n\n#### 1. Declaring a module\nA module is declared with `declare` function call.\n```javascript\ndeclare('name', 'John Doe');\n```\nAny data type is allowed\n```javascript\ndeclare('num', 111);\ndeclare('bool', false);\ndeclare('Sysprops', {key:'value'});\n```\nAny number of modules may be declared in single file.\nModules that need *setup functions* may be declared like following: *(AMD style)*\n```javascript\n  declare('MoreComplexModule', function(include){\n    //doing some computation\n    //and\n    return 'some value';\n  });\n```\nIt is good time to say more about declaring module with *setup function*. Setup function in the example above is not called until first time `include`d and never again. That means:\n\n**1.** If you need reusable function from declared module defining inside setup function and returning it is the way to go:\n```javascript\n  declare('ComplexMethod', function(include){\n    //doing some computation\n    //and\n    return function(){\n        \n    };\n  });\n```\n\n**2.** If you pass function as an argument to `declare` it will be executed and return value will be used as module value. So, for example, things like `jQuery`, which are actually functions, would have to be declared like this:\n\n```javascript\n  declare('jQuery', function(include){\n    return jQuery\n  });\n```\n(this is by no means niether only nor the best way yo store jQuery and friends as modules).\n\n##### 1.1 Declaring 'inline' (or 'lazy') module\nIf your prefer to declare modules immidiately (for example) in document's head and to include **micromodule** library code after that, you have an option of using 'inline' modules declaration, like following:\n\n```html\n  \u003cscript type=\"text/n\" data-md=\"inline1\"\u003e\n    // regular JS code\n    // and return statement as if we are inside function's body\n    return \"A value of some 'inline module'\";\n  \u003c/script\u003e\n```\n\nRequirements are that `script`'s attribute `type` is set to ignorable value (antyhing other than `\"module\"` (ES6) or `\"text/javascript\"`) and `data-md` attribute is set to module's id. This way, module will be registered whenever **micromodule** library code occurs.\n\n\n##### 1.2 Deleting module\nModule may be deleted with `declare.remove` function call:\n```javascript\n  declare.remove('modname');\n```\n\n\n\n---\n\n\n\n#### 2. Using modules\nModule is used with `include` function call:\n\n```javascript\nvar name = include('name');\n```\n\nA module has to be declared previously, of course:\n\n```javascript\nvar nonExistingMod = include('nonExistingMod'); // undefined\n```\n\n`include` is available as first argument in `declare` setup function:\n\n```javascript\ndeclare('mod_name', function(include){\n    var name = include('name');\n    // note: this === window in setup functions\n})\n```\n\n##### 2.1 Deep include\nThere is a useful option of storing a global variable into **micromodules** module system and subsequent including:\n\n```javascript\nvar Raf = include('requestAnimationFrame+');\nvar jQuery = include('jQuery+');\n```\nThis option is triggered with the last character of identifier set to `+`, which means, if there is no requested module name, before giving up, try to search global variables and import them if founded.\n\nThis way we will have globals as local vars pulled from module system.\n\n\n\n[travis]: https://travis-ci.org/milosdjakonovic/micromodules\n[travis-img]: https://travis-ci.org/milosdjakonovic/micromodules.svg?branch=master","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilosdjakonovic%2Fmicromodules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilosdjakonovic%2Fmicromodules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilosdjakonovic%2Fmicromodules/lists"}