Comparing version 0.0.3 to 0.0.4
@@ -0,32 +1,48 @@ | ||
// (The MIT License) | ||
// | ||
// Copyright (c) 2012 Richard S Allinson <rsa@mountainmansoftware.com> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// 'Software'), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
/* | ||
* Load modules | ||
*/ | ||
/*jslint stupid: true, nomen: true*/ | ||
var express = require('express'), | ||
stache = require('stache'), | ||
knot = require('../../'), | ||
app = express.createServer(); | ||
'use strict'; | ||
/* | ||
* Tell express to use the knot middleware. | ||
* Load required modules | ||
*/ | ||
app.use(knot.node(process.cwd())); | ||
var connect = require('connect'), | ||
knot = require('../../'), | ||
app = connect.createServer(); | ||
/* | ||
* Register mustache for .html | ||
* Tell connect to use the knot middleware. | ||
*/ | ||
app.register('.html', stache); | ||
app.set('view options', { | ||
layout: false | ||
}); | ||
app.use(knot.node(process.cwd())); | ||
/* | ||
* Add a simple route to our flat file | ||
* Add a simple function to serve the index.html file | ||
*/ | ||
app.get('/', function(req, res){ | ||
res.render('index.html'); | ||
app.use(function (req, res) { | ||
res.end(require('fs').readFileSync('./views/index.html')); | ||
}); | ||
@@ -33,0 +49,0 @@ |
{ | ||
"name": "knot_example_basic", | ||
"description": "A basic example of knot node using express.", | ||
"description": "A basic example of knot node using connect.", | ||
"version": "0.0.1", | ||
@@ -14,5 +14,4 @@ "author": { | ||
"dependencies": { | ||
"express": "2.5.x", | ||
"stache": "0.1.0" | ||
"connect": ">= 1.8.x" | ||
} | ||
} |
@@ -0,5 +1,29 @@ | ||
// (The MIT License) | ||
// | ||
// Copyright (c) 2012 Richard S Allinson <rsa@mountainmansoftware.com> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// 'Software'), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
'use strict'; | ||
var add = require('./math').add; | ||
exports.increment = function(val) { | ||
exports.increment = function (val) { | ||
@@ -6,0 +30,0 @@ return add(val, 1); |
@@ -0,4 +1,28 @@ | ||
// (The MIT License) | ||
// | ||
// Copyright (c) 2012 Richard S Allinson <rsa@mountainmansoftware.com> | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// 'Software'), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
exports.add = function() { | ||
'use strict'; | ||
exports.add = function () { | ||
var sum = 0, | ||
@@ -8,8 +32,9 @@ i = 0, | ||
l = args.length; | ||
while (i < l) { | ||
sum += args[i++]; | ||
i = i + 1; | ||
sum += args[i]; | ||
} | ||
return sum; | ||
}; |
@@ -14,7 +14,11 @@ { | ||
"modules": [ | ||
"knot", | ||
"process", | ||
"console", | ||
"util", | ||
"events", | ||
"stream", | ||
"path", | ||
"util" | ||
"assert" | ||
] | ||
} | ||
} |
@@ -24,2 +24,6 @@ // (The MIT License) | ||
/*jslint stupid: true, nomen: true*/ | ||
'use strict'; | ||
/* | ||
@@ -50,3 +54,3 @@ * Load modules | ||
function decode(path){ | ||
function decode(path) { | ||
try { | ||
@@ -72,7 +76,7 @@ return decodeURIComponent(path); | ||
var head, | ||
get, | ||
getOnly, | ||
url, | ||
path, | ||
file; | ||
get, | ||
getOnly, | ||
url, | ||
path, | ||
file; | ||
@@ -86,4 +90,4 @@ options = options || {}; | ||
// setup | ||
head = 'HEAD' == req.method; | ||
get = 'GET' == req.method; | ||
head = 'HEAD' === req.method; | ||
get = 'GET' === req.method; | ||
getOnly = options.getOnly; | ||
@@ -98,3 +102,3 @@ | ||
// parse url | ||
url = parse(options.path) | ||
url = parse(options.path); | ||
path = decode(url.pathname); | ||
@@ -111,4 +115,4 @@ file = options.modules[path]; | ||
if (file.name !== 'knot') { | ||
res.write("process('" + file.name + "', function(exports, require, module, __filename, __dirname) {"); | ||
if (file.name !== 'process') { | ||
res.write("process('" + file.name + "', function(exports, require, module, __filename, __dirname) {\n"); | ||
} | ||
@@ -118,4 +122,4 @@ | ||
if (file.name !== 'knot') { | ||
res.write("}, {uri: '" + file.uri + "'});"); | ||
if (file.name !== 'process') { | ||
res.write("\n}, {uri: '" + file.uri + "'});"); | ||
} | ||
@@ -128,3 +132,4 @@ | ||
* This function looks for a <dir>/package.json file. If one is found it then | ||
* sees if there is a knot entry and each file it finds to the "modules" object. | ||
* sees if there is a knot entry and each file it finds it adds to the | ||
* "modules" object. NOTE: Only the files found here will be served by knot. | ||
* | ||
@@ -177,5 +182,5 @@ * "<dir>/package.json" | ||
// Add the file to the modules map. | ||
uri = (name ? name + '/' : '' ) + files[file] + '.js'; | ||
uri = (name ? name + '/' : '') + files[file] + '.js'; | ||
modules[KNOT_PREFIX + uri] = { | ||
name: (name ? name + '/' : '' ) + files[file], | ||
name: (name ? name + '/' : '') + files[file], | ||
path: path.join(dir, files[file] + '.js'), | ||
@@ -189,7 +194,7 @@ uri: uri | ||
if (pack.knot.main) { | ||
uri = (name ? name + '/' : '' ) + files[file] + '.js'; | ||
uri = name + '.js'; | ||
modules[KNOT_PREFIX + uri] = { | ||
name: name, | ||
path: path.join(dir, files[file] + '.js'), | ||
uri: uri | ||
path: path.join(dir, pack.knot.main + '.js'), | ||
uri: (name ? name + '/' : '') + files[file] + '.js' | ||
}; | ||
@@ -212,4 +217,4 @@ } | ||
var files, | ||
name, | ||
absPath; | ||
name, | ||
absPath; | ||
@@ -244,4 +249,4 @@ if (!modules) { | ||
exports = module.exports = function(root, options){ | ||
module.exports = function (root, options) { | ||
var modules = {}; | ||
@@ -262,3 +267,3 @@ | ||
return function(req, res, next) { | ||
return function (req, res, next) { | ||
options.path = req.url; | ||
@@ -265,0 +270,0 @@ options.getOnly = true; |
{ | ||
"name": "knot", | ||
"description": "A client side Node experiment.", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"author": { | ||
@@ -15,3 +15,8 @@ "name": "Richard S Allinson", | ||
"connect": "1.x" | ||
} | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/capecodehq/knot.git" | ||
}, | ||
"license": "MIT" | ||
} |
135
readme.md
# Knot Node | ||
A programmatic folly exploring the underbelly of implementing a client-side version of Node. | ||
A programmatic folly exploring the underbelly of implementing a client-side version of Node. | ||
## Exmaple Usage | ||
<script type="text/javascript" src="/knot/process.js"></script> | ||
<script type="text/javascript"> | ||
process(function(exports, require, module) { | ||
var util = require('util'); | ||
console.log(util.inspect(this, true, 6)); | ||
}); | ||
</script> | ||
## Supported Modules & Functions | ||
### Globals | ||
* process | ||
* console | ||
* require() | ||
* __filename | ||
* __dirname | ||
* module | ||
* exports | ||
* setTimeout(cb, ms) | ||
* clearTimeout(t) | ||
* setInterval(cb, ms) | ||
* clearInterval(t) | ||
### Process | ||
* process.stdout | ||
* process.stderr | ||
* process.execPath | ||
* process.cwd() | ||
* process.version | ||
* process.versions | ||
* process.installPrefix | ||
* process.arch | ||
* process.platform | ||
* process.uptime() | ||
### Console | ||
* console.log() | ||
* console.info() | ||
* console.warn() | ||
* console.error() | ||
* console.dir(obj) | ||
* console.time(label) | ||
* console.timeEnd(label) | ||
### Utils | ||
* util.format() | ||
* util.debug(string) | ||
* util.log(string) | ||
* util.inspect(object, [showHidden], [depth], [colors]) | ||
* util.isArray(object) | ||
* util.isRegExp(object) | ||
* util.isDate(object) | ||
* util.isError(object) | ||
* (not tested) util.pump(readableStream, writableStream, [callback]) | ||
* (not tested) util.inherits(constructor, superConstructor) | ||
### Events | ||
Note: Not tested yet. | ||
* emitter.addListener(event, listener) | ||
* emitter.on(event, listener) | ||
* emitter.once(event, listener) | ||
* emitter.removeListener(event, listener) | ||
* emitter.removeAllListeners([event]) | ||
* emitter.setMaxListeners(n) | ||
* emitter.listeners(event) | ||
* emitter.emit(event, [arg1], [arg2], [...]) | ||
### Buffer | ||
Notes: process.binding('buffer').SlowBuffer. | ||
* (check support) SlowBuffer | ||
### Path | ||
* path.normalize(p) | ||
* path.join([path1], [path2], [...]) | ||
* path.resolve([from ...], to) | ||
* path.relative(from, to) | ||
* path.dirname(p) | ||
* path.basename(p, [ext]) | ||
* path.extname(p) | ||
### URL | ||
Note: Requires "Query Strings". | ||
### Query Strings | ||
Notes: process.binding('http_parser').urlDecode. Requires "Buffer". | ||
### Assertion Testing | ||
* assert.fail(actual, expected, message, operator) | ||
* assert(value, message), assert.ok(value, [message]) | ||
* assert.equal(actual, expected, [message]) | ||
* assert.notEqual(actual, expected, [message]) | ||
* (not tested) assert.deepEqual(actual, expected, [message]) | ||
* (not tested) assert.notDeepEqual(actual, expected, [message]) | ||
* assert.strictEqual(actual, expected, [message]) | ||
* assert.notStrictEqual(actual, expected, [message]) | ||
* assert.throws(block, [error], [message]) | ||
* assert.doesNotThrow(block, [error], [message]) | ||
* assert.ifError(value) | ||
## Modules Not Supported | ||
* Crypto | ||
* File System | ||
* Net | ||
* UDP/Datagram | ||
* DNS | ||
* Stream | ||
* HTTP | ||
* HTTPS | ||
* Readline | ||
* REPL | ||
* VM | ||
* Child Processes | ||
* TTY | ||
* ZLIB | ||
* OS | ||
* Debugger | ||
* Cluster |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
96850
40
2390
137
1
7