Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 1a06695a7993d0ff414cc11dcdc16df24c0a662d @shinout committed Nov 16, 2011
Showing with 684 additions and 0 deletions.
  1. +120 −0 ArrayStream.js
  2. +22 −0 LICENCE
  3. +56 −0 README.ja.md
  4. +65 −0 README.md
  5. +18 −0 package.json
  6. +59 −0 scripts/README.tpl.md
  7. +16 −0 scripts/en.lang
  8. +16 −0 scripts/ja.lang
  9. +18 −0 scripts/package.tpl.json
  10. +21 −0 scripts/umecob-command.js
  11. +5 −0 scripts/updateinfo.sh
  12. +70 −0 test/load.test.js
  13. +59 −0 test/termcolor.js
  14. +139 −0 test/test.js
@@ -0,0 +1,120 @@
+/**
+ * ArrayStream -- ReadableStream of arrays or hash variables
+ * @author SHIN Suzuki
+ * @version 0.0.1
+ *
+ */
+
+var EventEmitter = require('events').EventEmitter,
+ nextTick = process.nextTick;
+
+/**
+ * @constructor
+ *
+ * @param {Array} or {Object} arr
+ * @param {Object} op
+ * {boolean} tolerant if true, continue iteration even if errors occurred
+ *
+ * @event {data} function(value, key)
+ * Emitted when received an element.
+ *
+ * @event {end} function()
+ * Emitted when reached end
+ *
+ * @event {error} function(e)
+ * Emitted when an error occurred
+ **/
+function ArrayStream(arr, op) {
+ op = op || {};
+ this.i = 0;
+
+ this.readable = true;
+ this.paused = !!op.pause;
+
+ this.arr = arr || [];
+ this.isArray = Array.isArray(arr);
+ this.keys = Object.keys(arr);
+ this.length = this.keys.length;
+ this._options = op;
+
+ if (!this.paused) nextTick(emit.bind(this));
+}
+
+
+ArrayStream.prototype = new EventEmitter();
+
+/**
+ * @see ReadableStream
+ **/
+ArrayStream.prototype.resume = function() {
+ this.paused = false;
+ emit.call(this);
+};
+
+/**
+ * @see ReadableStream
+ **/
+ArrayStream.prototype.pause = function() {
+ this.paused = true;
+};
+
+/**
+ * @see ReadableStream
+ **/
+ArrayStream.prototype.destroy = function() { // implementing ReadableStream
+ this.stream.destroy();
+ this.readable = false;
+}
+
+
+/**
+ * @see ReadableStream
+ **/
+ArrayStream.prototype.destroySoon = function() { // implementing ReadableStream
+ // Not knowing what to do, this remains unimplemented...
+ this.destroy();
+}
+
+/**
+ * @see ReadableStream
+ **/
+ArrayStream.prototype.pipe = function() {
+ return process.stdin.pipe.apply(this, arguments);
+}
+
+
+/**
+ * private function
+ **/
+function emit() {
+ var self = this;
+ (function execute() {
+ try {
+ var k = self.keys[self.i];
+ self.emit('data', self.arr[k], k);
+ self.i++;
+
+ if(self.i >= self.length) {
+ self.emit('end');
+ }
+ else {
+ if (!self.paused) nextTick(execute);
+ }
+ } catch (e) {
+ self.emit('error', e);
+ if (self._options.tolerant) {
+ self.i++;
+ if (!self.paused) nextTick(execute);
+ }
+ else {
+ self.emit('end');
+ self.readable = false;
+ }
+ }
+ })();
+}
+
+
+ArrayStream.version = '0.0.1';
+
+module.exports = ArrayStream;
22 LICENCE
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2011 SHIN Suzuki <shinout310@gmail.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.
@@ -0,0 +1,56 @@
+ArrayStream.js 0.0.1
+==========
+[Node.js] 配列,ハッシュをReadableStreamとして扱う
+
+変更履歴
+
+----------------
+* [0.0.1]: リリース
+
+概要
+----------------
+### インストール方法 ###
+ git clone git://github.com/shinout/ArrayStream.git
+
+ または
+
+ npm install arraystream
+
+### 使い方 ###
+#### 配列を扱う ####
+ var ArrayStream = require('arraystream');
+ var stream = new ArrayStream(['hoge', 'fuga', 'piyo']);
+
+ stream.on('data', function(value, key) {
+ console.log(value); // hoge, fuga, piyo
+ console.log(key); // 0, 1, 2
+ });
+
+ stream.on('end', function() { // イテレーションの終わりに実行されます。
+ console.log('end');
+ });
+
+ stream.on('error', function(e) { // エラー発生時に呼び出されます。
+ console.log(e);
+ });
+
+
+
+#### オブジェクトを扱う ####
+ var ArrayStream = require('arraystream');
+ var objstream = new ArrayStream({a:'hoge', b:'fuga', c:'piyo']);
+
+ objstream.on('data', function(value, key) {
+ console.log(key); // a, b, c
+ console.log(value); // hoge, fuga, piyo
+ });
+
+ objstream.on('end', function() { // Objectの終わりに実行されます。
+ console.log('end');
+ });
+
+ objstream.on('error', function(e) { // エラー発生時に呼び出されます。
+ console.log(e);
+ });
+
+
@@ -0,0 +1,65 @@
+Extra comma. at line 7.
+//------------------------------------//
+//-------------- start ---------------//
+ 1 ({ changeLogs :
+ 2 { "0.0.1" : "Release"
+ 3 }
+ 4
+ 5 , changelog : 'Change Log'
+ 6 , _OR : 'OR'
+*7 , description : 'ReadableStream from array (or hash variable)',
+ 8 , install : 'Installation'
+ 9 , overview : 'Overview'
+ 10 , usage : 'Usage'
+ 11 , witharr : 'with Array'
+ 12 , withobj : 'with Object'
+ 13 , iteration : 'iteration'
+ 14 , endemit : function(v) { return 'emitted at the end of '+ v}
+ 15 , erremit : 'emitted when an error occurred'
+ 16 }
+ 17 )
+//--------------- end ----------------//
+//------------------------------------//
+
+SyntaxError: Unexpected token ,
+ at jsonize (/home/shinout/node_modules/umecob/umecob.js:339:19)
+ at Object.sync (/home/shinout/node_modules/umecob/umecob.js:365:42)
+ at Function.sync (/home/shinout/node_modules/umecob/umecob.js:237:90)
+ at umecob (/home/shinout/node_modules/umecob/umecob.js:20:49)
+ at Object.<anonymous> (/home/shinout/node_modules/arraystream/scripts/umecob-command.js:18:14)
+ at Module._compile (module.js:432:26)
+ at Object..js (module.js:450:10)
+ at Module.load (module.js:351:31)
+ at Function._load (module.js:310:12)
+ at Array.0 (module.js:470:10)
+'description' is not defined. in /home/shinout/node_modules/arraystream/scripts/../scripts/README.tpl.md at line 3.
+//------------------------------------//
+//-------------- start ---------------//
+ 1 ArrayStream.js ${version}
+ 2 ==========
+*3 [Node.js] ${description}
+ 4
+ 5 ${changelog}
+ 6
+ 7 ----------------
+ 8 << for (var i in changeLogs) { >>
+ 9 * [${i}]: ${changeLogs[i]}
+ 10 << } >>
+ 11
+ 12 ${overview}
+ 13 ----------------
+//--------------- end ----------------//
+//------------------------------------//
+
+ReferenceError: description is not defined
+ at Function.<anonymous> (eval at <anonymous> (/home/shinout/node_modules/umecob/umecob.js:548:50))
+ at Function.eval (/home/shinout/node_modules/umecob/umecob.js:548:45)
+ at Object.run (/home/shinout/node_modules/umecob/umecob.js:590:21)
+ at common_end (/home/shinout/node_modules/umecob/umecob.js:222:57)
+ at Function.sync (/home/shinout/node_modules/umecob/umecob.js:238:16)
+ at umecob (/home/shinout/node_modules/umecob/umecob.js:20:49)
+ at Object.<anonymous> (/home/shinout/node_modules/arraystream/scripts/umecob-command.js:18:14)
+ at Module._compile (module.js:432:26)
+ at Object..js (module.js:450:10)
+ at Module.load (module.js:351:31)
+'description' is not defined. in /home/shinout/node_modules/arraystream/scripts/../scripts/README.tpl.md at line 3.
@@ -0,0 +1,18 @@
+{
+ "name": "arrayemitter"
+, "version": "0.0.1"
+, "description": "EventEmitter emittin array-iteration events."
+, "tags": ["EventEmitter", "array", "object", "iteration", "event"]
+, "author": "SHIN Suzuki <shinout310@gmail.com>"
+, "repository":
+ { "type": "git"
+ , "url": "https://github.com/shinout/ArrayEmitter.git"
+ }
+, "bugs": {"web": "https://github.com/shinout/ArrayEmitter/issues" }
+, "licences":
+ [ { "type": "MIT"
+ , "url": "https://github.com/shinout/ArrayEmitter/raw/master/LICENCE"
+ }
+ ]
+, "main": "./ArrayEmitter.js"
+}
@@ -0,0 +1,59 @@
+ArrayStream.js ${version}
+==========
+[Node.js] ${description}
+
+${changelog}
+
+----------------
+<< for (var i in changeLogs) { >>
+* [${i}]: ${changeLogs[i]}
+<< } >>
+
+${overview}
+----------------
+### ${install} ###
+ git clone git://github.com/shinout/ArrayStream.git
+
+ ${_OR}
+
+ npm install arraystream
+
+### ${usage} ###
+#### ${witharr} ####
+ var ArrayStream = require('arraystream');
+ var stream = new ArrayStream(['hoge', 'fuga', 'piyo']);
+
+ stream.on('data', function(value, key) {
+ console.log(value); // hoge, fuga, piyo
+ console.log(key); // 0, 1, 2
+ });
+
+ stream.on('end', function() { // ${endemit(iteration)}
+ console.log('end');
+ });
+
+ stream.on('error', function(e) { // ${erremit}
+ console.log(e);
+ });
+
+
+
+#### ${withobj} ####
+ var ArrayStream = require('arraystream');
+ var objstream = new ArrayStream({a:'hoge', b:'fuga', c:'piyo']);
+
+ objstream.on('data', function(value, key) {
+ console.log(key); // a, b, c
+ console.log(value); // hoge, fuga, piyo
+ });
+
+ objstream.on('end', function() { // ${endemit('Object')}
+ console.log('end');
+ });
+
+ objstream.on('error', function(e) { // ${erremit}
+ console.log(e);
+ });
+
+
+
@@ -0,0 +1,16 @@
+{ changeLogs :
+ { "0.0.1" : "Release"
+ }
+
+, changelog : 'Change Log'
+, _OR : 'OR'
+, description : 'ReadableStream from array (or hash variable)',
+, install : 'Installation'
+, overview : 'Overview'
+, usage : 'Usage'
+, witharr : 'with Array'
+, withobj : 'with Object'
+, iteration : 'iteration'
+, endemit : function(v) { return 'emitted at the end of '+ v}
+, erremit : 'emitted when an error occurred'
+}
@@ -0,0 +1,16 @@
+{ changeLogs :
+ { "0.0.1" : "リリース"
+ }
+
+, changelog : '変更履歴'
+, _OR : 'または'
+, description : '配列,ハッシュをReadableStreamとして扱う'
+, install : 'インストール方法'
+, overview : '概要'
+, usage : '使い方'
+, witharr : '配列を扱う'
+, withobj : 'オブジェクトを扱う'
+, iteration : 'イテレーション'
+, endemit : function(v) { return v + 'の終わりに実行されます。'}
+, erremit : 'エラー発生時に呼び出されます。'
+}
Oops, something went wrong.

0 comments on commit 1a06695

Please sign in to comment.