{"_id":"apitree","_rev":"9-24d0d14e9705e779c1ce29d0b1a888d8","name":"apitree","description":"Creates a SocketStream-style API tree from a file system directory","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"author":{"name":"Andrey Tarantsov","email":"andreyvit@me.com"},"name":"apitree","description":"Creates a SocketStream-style API tree from a file system directory","version":"1.0.0","homepage":"https://github.com/andreyvit/apitree.js","repository":{"type":"git","url":"git://github.com/andreyvit/apitree.js.git"},"bugs":{"name":"http://github.com/andreyvit/apitree.js/issues"},"main":"lib/apitree.js","directories":{"lib":"lib","example":"example"},"scripts":{"test":"./node_modules/.bin/mocha"},"engines":{"node":">=0.4.0"},"dependencies":{},"devDependencies":{"mocha":">=0.3.1"},"_npmUser":{"name":"andreyvit","email":"andreyvit@me.com"},"_id":"apitree@1.0.0","_engineSupported":true,"_npmVersion":"1.0.99","_nodeVersion":"v0.5.5","_defaultsLoaded":true,"dist":{"shasum":"664e5480051ee48d36f8cee0997163559fd93bcd","tarball":"https://registry.npmjs.org/apitree/-/apitree-1.0.0.tgz","integrity":"sha512-IswOND1VmISzrvONqY4urRRocFjM5UY/+vpGEjtbB7JnLqTDHiZb+I1KoOhNZsDPO1DvutUReNAaasvuOon2Nw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGv3ZFy5A9wU4IQZRBZPKxLpa4P+B745LepBVcZO1ohWAiEA59keXQGKtUB8Qb1dcCWr+LMuqASaqKV158sLkWWkkbA="}]},"maintainers":[{"name":"andreyvit","email":"andreyvit@me.com"}]},"1.1.0":{"author":{"name":"Andrey Tarantsov","email":"andreyvit@me.com"},"name":"apitree","description":"Creates a SocketStream-style API tree from a file system directory","version":"1.1.0","homepage":"https://github.com/andreyvit/apitree.js","repository":{"type":"git","url":"git://github.com/andreyvit/apitree.js.git"},"bugs":{"name":"http://github.com/andreyvit/apitree.js/issues"},"main":"lib/apitree.js","directories":{"lib":"lib","example":"example"},"scripts":{"test":"./node_modules/.bin/mocha"},"engines":{"node":">=0.6.0"},"dependencies":{},"devDependencies":{"mocha":"~1.0","coffee-script":"~1.3"},"_npmUser":{"name":"andreyvit","email":"andreyvit@me.com"},"_id":"apitree@1.1.0","optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.16","_nodeVersion":"v0.6.15","_defaultsLoaded":true,"dist":{"shasum":"5815bb5beeb2a84dadf6e241ccc52e003f1c556f","tarball":"https://registry.npmjs.org/apitree/-/apitree-1.1.0.tgz","integrity":"sha512-LBwhSKKy1AZiuSVHEO3DdQo1H7eypwpWR9fYJhSNxr4aTTxGjW288uHQLX7oinaVPqLjO/M5ZY+8YPvhKyzbUw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmQ+E5ENHhaE2iEV0OxxszcViHoyX4ZgV0Ky+HTxAoTAIhAJ3AuowCN+F5duabWtJ+VYyvqOYzP4I++6h7R7AAz3hE"}]},"maintainers":[{"name":"andreyvit","email":"andreyvit@me.com"}]},"1.2.0":{"author":{"name":"Andrey Tarantsov","email":"andreyvit@me.com"},"name":"apitree","description":"Creates a SocketStream-style API tree from a file system directory","version":"1.2.0","homepage":"https://github.com/andreyvit/apitree.js","repository":{"type":"git","url":"git://github.com/andreyvit/apitree.js.git"},"bugs":{"url":"http://github.com/andreyvit/apitree.js/issues"},"main":"lib/apitree.js","directories":{"lib":"lib","example":"example"},"scripts":{"test":"mocha"},"engines":{"node":">=0.6.0"},"dependencies":{},"devDependencies":{"mocha":"~1.0","coffee-script":"~1.3"},"_id":"apitree@1.2.0","dist":{"shasum":"8dff1dd42bc61a9ab19b96f2d806aaff2e266a7d","tarball":"https://registry.npmjs.org/apitree/-/apitree-1.2.0.tgz","integrity":"sha512-1NyBxvIH7JEHJjs7IqlBvSy8sWTjVRKWFpxT2IAO7HlsgJTQ0Cuq4BbL/R/1TCkzTNwGAo/+XfdinKDWQFn+hA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDS1z+dUn/9tYKhD6Aw2bS0B5eQG5jLUBeasm0zGMxAXAiAxytOtKSUXUNG8eAMnWQRRfwSrANw09/X7F9UqhEGWZg=="}]},"_from":".","_npmVersion":"1.4.3","_npmUser":{"name":"andreyvit","email":"andrey@tarantsov.com"},"maintainers":[{"name":"andreyvit","email":"andreyvit@me.com"}]}},"maintainers":[{"name":"andreyvit","email":"andreyvit@me.com"}],"time":{"modified":"2022-06-13T03:14:14.355Z","created":"2011-12-13T21:31:53.281Z","1.0.0":"2011-12-13T21:31:55.926Z","1.1.0":"2012-07-17T18:38:25.525Z","1.2.0":"2014-09-09T23:27:57.544Z"},"author":{"name":"Andrey Tarantsov","email":"andreyvit@me.com"},"repository":{"type":"git","url":"git://github.com/andreyvit/apitree.js.git"},"readme":"apitree.js\n===========\n\nNode.js module to create a SocketStream-style API tree from a file system directory.\n\n\nInstallation\n------------\n\n    npm install apitree\n\n\nUsage\n-----\n\nCall `createApiTree` to load all files in the given directory (and its subdirectories) and return an object, such that `returnedObject.foo.bar.boz.fubar` equals to exported function `fubar` of file `boz` in subdirectory `foo/bar` of the given directory. (Some of the described details are customizable via optional callbacks.)\n\nExample:\n\n    var apitree = require('apitree');\n    var path    = require('path');\n\n    var api = apitree.createApiTree(path.join(__dirname, 'apiroot'))\n\n    api.somefile.func1(42);\n    api.sub.folder.anotherfile.func2(24);\n\ncreateApiTree function accepts 2 arguments:\n\n    apitree.createApiTree(directory, options)\n\nwhere options is an optional object with 3 possible keys:\n\n* `options.loadItem(path)` loads the contents of file at `path`; returns either `null` or an object that will be merged into the tree; the default value is `require`.\n* `options.filter(name, names)` determines whether given file should be processed or ignored; other names from the same directory are provided as the second argument; the default implementation returns true for .js files and files with a registered extension in require.extensions which don't have corresponding .js files. (Exludes .json files)\n* `options.nameToKey(name)` returns a key to use in the tree object for the given file or folder name; the default implementation strips the file extension and replaces any non-identifier characters with underscores.\n\nAdditionally, `options.readdirSync(directory)` and `options.isDirectory(path)` can be provided to override the standard behavior of reading from the file system.\n\n\nSomewhat more realistic example\n-------------------------------\n\nSee example/ directory. In CoffeeScript:\n\n    global.DB =\n      put: (collection, object) ->\n        @[collection].push object\n        console.log \"Added to #{collection}: #{JSON.stringify(object)}\"\n\n    path = require 'path'\n    global.S = require('apitree').createApiTree(path.join(__dirname, 'server'))\n\n    S.app.init()\n    userId = S.users.create(name: 'admin', password: 'admin123')\n    postId = S.blog.posts.publish(authorId: userId, title: \"Hello!\", body: \"Hey! This is my first post.\")\n    S.blog.comments.publish(postId: postId, author: \"Random Visitor\", body: \"Very excited about your new blog.\")\n    S.blog.comments.publish(postId: postId, author: \"spa.m@mer.go.ddam.it\", body: \"Send Your Name, Address...\")\n\nexample/server/app.coffee:\n\n    exports.init = ->\n      DB.users    = []\n      DB.posts    = []\n      DB.comments = []\n\nexample/server/users.coffee:\n\n    exports.create = ({ name, password }) ->\n      user = { name, password, id: DB.users.length }\n      DB.put 'users', user\n      user.id\n\nexample/server/blog/posts.coffee:\n\n    exports.publish = ({authorId, title, body}) ->\n      post = { authorId, title, body, id: DB.posts.length }\n      DB.put 'posts', post\n      post.id\n\nexample/server/blog/comments.coffee:\n\n    exports.publish = ({postId, author, body}) ->\n      comment = { postId, author, body, id: DB.comments.length }\n      DB.put 'comments', comment\n      comment.id\n\n\nSpec\n----\n\nUses mocha, run `npm test` to execute tests.\n\n    API tree\n        when given an empty folder\n          ✓ should return an empty tree\n        when given a folder with a single file\n          ✓ should put the file node under the tree root\n          ✓ should strip the extension when naming the tree node\n          ✓ should put the file's contents under its node\n        when given a file and a subfolder\n          ✓ should put the file and subfolder nodes together under the tree root\n        when given a file and a subfolder which have the same name after stripping extensions\n          ✓ should merge the file and the subfolder into a single node under the tree root\n        when given a folder hierarchy with nested subfolders\n          ✓ should reproduce the folder hierarachy inside the API tree\n        loadItem callback\n          ✓ should be used to obtain file contents\n        nameToKey callback\n          ✓ should accept file name as the only argument\n          ✓ should be used to translate file names into tree keys\n          ✓ should be used to translate subfolder names into tree keys\n          ✓ should not be used to modify keys returned by loadItem\n        default nameToKey callback\n          ✓ should strip file extension\n          ✓ should replace any non-identifier characters with underscores\n          ✓ should replace runs of multiple non-identifier characters with a single underscore\n        filter callback\n          ✓ should accept file name as the first argument\n          ✓ should accept the list of all file names in the same folder as the second argument\n          ✓ should be used to choose which files to process\n          ✓ should have no effect on which folders are processed\n        default filter callback\n          ✓ should include .js files\n          ✓ should include .coffee files that don't have corresponding .js files\n          ✓ should include registered extension files that don't have corresponding .js files\n          ✓ should only include .js file when both .js and .coffee files exist\n          ✓ should only include .js file when both registered extension file and .js files exist\n          ✓ should not include any other files\n\n    ✔ 25 tests complete (47ms)\n\n\nLicense\n-------\n\nMIT license. Copyright 2011–2012, [Andrey Tarantsov](andrey@tarantsov.com).\n","homepage":"https://github.com/andreyvit/apitree.js","bugs":{"url":"http://github.com/andreyvit/apitree.js/issues"},"readmeFilename":"README.md"}