{"_id":"nsdeclare","_rev":"240530","name":"nsdeclare","description":"Safely declare a namespace using dot notation","dist-tags":{"latest":"0.1.0"},"maintainers":[{"name":"lazd","email":"lazdnet@gmail.com"}],"time":{"modified":"2021-06-03T15:56:03.000Z","created":"2014-03-07T21:45:32.298Z","0.1.0":"2014-07-28T05:35:20.921Z","0.0.0":"2014-03-07T21:45:32.298Z"},"users":{},"author":{"name":"Larry Davis","email":"lazdnet@gmail.com"},"repository":{"type":"git","url":"git://github.com/lazd/nsdeclare.git"},"versions":{"0.1.0":{"name":"nsdeclare","version":"0.1.0","description":"Safely declare a namespace using dot notation","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/lazd/nsdeclare.git"},"keywords":["namespace","declare","declaration"],"author":{"name":"Larry Davis","email":"lazdnet@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/lazd/nsdeclare/issues"},"homepage":"https://github.com/lazd/nsdeclare","devDependencies":{"mocha":"~1.21.3","should":"~4.0.4"},"_id":"nsdeclare@0.1.0","_shasum":"10daa153642382d3cf2c01a916f4eb20a128b19f","_from":".","_npmVersion":"1.4.7","_npmUser":{"name":"lazd","email":"lazdnet@gmail.com"},"maintainers":[{"name":"lazd","email":"lazdnet@gmail.com"}],"dist":{"shasum":"10daa153642382d3cf2c01a916f4eb20a128b19f","size":3608,"noattachment":false,"key":"/nsdeclare/-/nsdeclare-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/nsdeclare/download/nsdeclare-0.1.0.tgz"},"directories":{},"publish_time":1406525720921,"_cnpm_publish_time":1406525720921,"_hasShrinkwrap":false},"0.0.0":{"name":"nsdeclare","version":"0.0.0","description":"Safely declare a namespace using dot notation","main":"index.js","scripts":{"test":"mocha"},"repository":{"type":"git","url":"git://github.com/lazd/nsdeclare.git"},"keywords":["namespace","declare","declaration"],"author":{"name":"Larry Davis","email":"lazdnet@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/lazd/nsdeclare/issues"},"homepage":"https://github.com/lazd/nsdeclare","devDependencies":{"mocha":"~1.17.1","should":"~3.1.3"},"_id":"nsdeclare@0.0.0","dist":{"shasum":"c3b1aad07cfb5b206ad1875443a4e32917964c72","size":2665,"noattachment":false,"key":"/nsdeclare/-/nsdeclare-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/nsdeclare/download/nsdeclare-0.0.0.tgz"},"_from":".","_npmVersion":"1.3.24","_npmUser":{"name":"lazd","email":"lazdnet@gmail.com"},"maintainers":[{"name":"lazd","email":"lazdnet@gmail.com"}],"directories":{},"publish_time":1394228732298,"_cnpm_publish_time":1394228732298,"_hasShrinkwrap":false}},"readme":"# nsdeclare [![NPM version][npm-image]][npm-url] [![Build status][travis-image]][travis]\n> Safely declare a namespace using dot notation\n\n## Usage\n\n```js\nvar declare = require('nsdeclare');\n\nvar declaration = declare('MyApp.Templates');\n```\n\nResult:\n```js\nthis[\"MyApp\"] = this[\"MyApp\"] || {};\nthis[\"MyApp\"][\"Templates\"] = this[\"MyApp\"][\"Templates\"] || {};\n```\n\n## Options\n\nOptions can be passed as the second argument to `nsdeclare`.\n\n### value\nType: `String`\n\nBy passing `options.value`, you can use `nsdeclare` to both declare and safely assign properties of a namespace:\n\n```js\nvar declare = require('nsdeclare');\n\nvar declaration = declare('MyApp.Templates.Main', { value: 'function() { return \"Main\"; }' });\n```\n\nResult:\n```js\nthis[\"MyApp\"] = this[\"MyApp\"] || {};\nthis[\"MyApp\"][\"Templates\"] = this[\"MyApp\"][\"Templates\"] || {};\nthis[\"MyApp\"][\"Templates\"][\"Main\"] = function() { return \"Main\"; };\n```\n\n### declared\nType: `Object`\n\nTo avoid redeclaration, you can pass a list of already declared namespace parts as `options.declared`:\n\n```js\nvar declare = require('nsdeclare');\n\nvar options = {\n  declared: {\n    'MyApp': true\n  }\n};\n\nvar declaration = [\n  declare('MyApp.Views', options),\n  declare('MyApp.Templates', options),\n  declare('MyApp.Models', options),\n  declare('MyApp.Collections', options)\n].join('\\n');\n```\n\nResult:\n```js\nthis[\"MyApp\"][\"Views\"] = this[\"MyApp\"][\"Views\"] || {};\nthis[\"MyApp\"][\"Templates\"] = this[\"MyApp\"][\"Templates\"] || {};\nthis[\"MyApp\"][\"Models\"] = this[\"MyApp\"][\"Models\"] || {};\nthis[\"MyApp\"][\"Collections\"] = this[\"MyApp\"][\"Collections\"] || {};\n```\n\nNote that, if you don't pass `options.declared` and a namespace part is already declared, `nsdeclare` will not overwrite it.\n\n### separator\nType: `String`\n\nDefault: `'\\n'`\n\nIf you would like to separate declaration parts with something other than `\\n`, you can pass it as `options.separator`:\n\n```js\nvar declare = require('nsdeclare');\n\nvar declaration = declare('MyApp.Templates', { separator: '' });\n```\n\nResult:\n```js\nthis[\"MyApp\"] = this[\"MyApp\"] || {};this[\"MyApp\"][\"Templates\"] = this[\"MyApp\"][\"Templates\"] || {};\n```\n\n### root\nType: `String`\n\nDefault: `'this'`\n\nBy default, `nsdeclare` will declare namespaces within the `this` object (which defaults to `window` in browser environments). You can change this behavior with `options.root`:\n\n```js\nvar declare = require('nsdeclare');\n\nvar declaration = declare('MyApp.Templates', { root: 'global' });\n```\n\nResult:\n```js\nglobal[\"MyApp\"] = global[\"MyApp\"] || {};\nglobal[\"MyApp\"][\"Templates\"] = global[\"MyApp\"][\"Templates\"] || {};\n```\n\n### response\nType: `String`  \nDefault: `declaration`\n\nBy default, `nsdeclare` will return the declaration as a string. In some cases, you might want additional details such as a safe reference to the namespace itself. Passing `response: 'details'` will cause `nsdeclare` to return an object with the following properties:\n\n  * `namespace` - The namespace itself as a `String`\n  * `declaration` - The declaration of the namespace as a `String`\n\n```js\nvar declare = require('nsdeclare');\n\nvar declaration = declare('MyApp.Templates', { response: 'object' });\n```\n\nResult:\n```js\n{\n  namespace: 'this[\"MyApp\"][\"Templates\"]',\n  declaration: 'this[\"MyApp\"] = this[\"MyApp\"] || {};\\nthis[\"MyApp\"][\"Templates\"] = this[\"MyApp\"][\"Templates\"] || {};'\n}\n```\n\n[travis]: http://travis-ci.org/lazd/nsdeclare\n[travis-image]: https://secure.travis-ci.org/lazd/nsdeclare.png?branch=master\n\n[npm-url]: https://npmjs.org/package/nsdeclare\n[npm-image]: https://badge.fury.io/js/nsdeclare.png\n","_attachments":{},"homepage":"https://github.com/lazd/nsdeclare","bugs":{"url":"https://github.com/lazd/nsdeclare/issues"},"license":"MIT"}