{"id":26172021,"url":"https://github.com/oktopost/namespace","last_synced_at":"2025-12-25T11:13:01.675Z","repository":{"id":57314077,"uuid":"86985819","full_name":"Oktopost/namespace","owner":"Oktopost","description":null,"archived":false,"fork":false,"pushed_at":"2018-06-04T14:23:23.000Z","size":168,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-10T03:56:05.738Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Oktopost.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":"2017-04-02T12:49:32.000Z","updated_at":"2017-04-02T12:52:12.000Z","dependencies_parsed_at":"2022-08-31T00:00:48.569Z","dependency_job_id":null,"html_url":"https://github.com/Oktopost/namespace","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oktopost%2Fnamespace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oktopost%2Fnamespace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oktopost%2Fnamespace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Oktopost%2Fnamespace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Oktopost","download_url":"https://codeload.github.com/Oktopost/namespace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243104176,"owners_count":20236943,"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":[],"created_at":"2025-03-11T19:52:58.143Z","updated_at":"2025-12-25T11:13:01.647Z","avatar_url":"https://github.com/Oktopost.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# oktopost-namespace \n\n[![npm version](https://img.shields.io/npm/v/oktopost-namespace.svg)](https://www.npmjs.com/package/oktopost-namespace)\n[![Build Status](https://travis-ci.org/Oktopost/namespace.svg?branch=master)](https://travis-ci.org/Oktopost/namespace)\n\nThe **oktopost-namespace** library aims to implement the usage of Namespaces inside JavaScript projects. \n\n\n## Table Of Contents\n\n  * [Installation](#installation)\n  * [Basic Example](#basic-example)\n  * [Building With Gulp Example](#building-with-gulp-example)\n  * [More To Read](#more-to-read)\n\n\n## Installation\n\n```bash\nnpm install oktopost-namespace --save\n```\n\n## Basic Example\n\nThe following example will assume the next directory structure:\n\n```\nsrc\n  Example\n    Subdir\n      sub.js\n      sum.js\n    calc.js\nnamespace.json\nindex.js\n```\n\n\n**./src/Example/Subdir/sub.js**\n\n\u003e Define a new function named `sub` inside the namespace `Example.Subdir`\n \n```js\nnamespace('Example.Subdir', function () \n{\n\tthis.sub = function sub(a, b)\n\t{\n\t\treturn a - b;\n\t}\n});\n```\n\n**./src/Example/Subdir/sum.js**\n\n\u003e Define a new function named `sum` inside the namespace `Example.Subdir`\n\n```js\nnamespace('Example.Subdir', function () \n{\n\tthis.sum = function sum(a, b)\n\t{\n\t\treturn a + b;\n\t}\n});\n```\n\n**./src/Example/calc.js**\n\n\u003e Define a new function named `calc` inside the namespace `Example`\n\n```js\nnamespace('Example', function () \n{\n\tthis.sum = function sum(a, b)\n\t{\n\t\treturn a + b;\n\t}\n});\n```\n\n**./namespace.json**\n\n\u003e `namespace.json` is the configuration file for the Namespace library.\n\n```json\n{\n\t\"map\":\n\t{\n\t\t\"dir\":\n\t\t{\n\t\t\t\"Example\": \"./src/\"\n\t\t}\n\t}\n}\n```\n\n\n**./index.js**\n\n\u003e Load and setup the Namespace library. After calling the method `virtual`, the function `namespace` is registered into \n\u003e the global scope and can be called using `global.namesapce(...)` or just `namespace(...)`.\n\n```js\nvar root = require('oktopost-namespace').virtual(__dirname);\nmodule.exports = root.Example;\n```\n\nMost initialization methods, including `virtual`, will return the root object in which all the namespaces are stored.\n\n\nFew notes:\n* Directory names should match the namespace path.\n* In the current version, `this` should not introduce more then one new definition per file into the namespaces scope.\nOr in other words, don't use `this.something = something;` more then once in the same JavaScript file.\n\n\n## Building With Gulp Example\n\nInside your `gulp.js` file, you can use the following snippet:\n\n```js\nlet result = require('oktopost-namespace').getDependencies(\n\t__dirname, \n\t() =\u003e {}, \n\t(root) =\u003e\n\t{\n\t\tconst calc = root.Example.calc;\n\t});\n```\n\nThe `result` variable will be equal to an array of file names ordered by thier *dependency priority*. Starting from the\nfiles that have no depends at all, and all the way to the enrty-point file of the project - that depends on all\nother library files. \n\nIn this case `result` it will be equal to:\n```js\n[\n\t'src/Example/Subdir/sub.js',\n\t'src/Example/Subdir/sum.js',\n\t'src/Example/calc.js'\n]\n```\n\nIf your project depends on any other files from different libraries, they will also be included inside this array.\nFor example: \n\n```js\n[\n\t'node_modules/my_lib/src/other_file.js',\n\t'src/Example/calc.js'\n]\n```\n\n### The `getDependencies(path, setupCallback, initCallback)` method:\n\n* `path` must be the full directory path to `index.js` file.\n* `setupCallback` this function is called before resolving dependencies. You can leave it empty for most cases.\n* `initCallback` is a function that is used to load all dependencies. In most cases this can be done by loading the \nentry-point object of your library. In this case it's the `calc` function.\n\n\n## More To Read\n\nFor more generic example, see the content of **[docs/example_01](docs/example_01)**\n\n```ssh\ngit clone git@github.com:Oktopost/namespace.git\ncd namespace/docs/example_01\nnpm install\nnode run_me.js\nnode run_me_gulp.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foktopost%2Fnamespace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foktopost%2Fnamespace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foktopost%2Fnamespace/lists"}