├── .travis.yml ├── .npmignore ├── index.js ├── README.md ├── package.json ├── .gitignore ├── LICENSE └── test └── test.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Vagrant 2 | .vagrant 3 | 4 | # Windows 5 | Thumbs.db 6 | Desktop.ini 7 | 8 | # Vim 9 | .*.sw[a-z] 10 | *.un~i 11 | tags 12 | 13 | # OsX 14 | .DS_Store 15 | Icon? 16 | ._* 17 | .Spotlight-V100 18 | .Trashes 19 | 20 | # nodejs npm modules 21 | /node_modules 22 | build 23 | test/tempdb -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var from = require('from2') 2 | 3 | var factory = module.exports = function(opts, arr){ 4 | if(arguments.length<=1){ 5 | arr = opts 6 | opts = {} 7 | } 8 | var reduce = [].concat(arr) 9 | return from(opts, function(size, cb){ 10 | if(reduce.length<=0) return cb(null, null) 11 | cb(null, reduce.shift()) 12 | }) 13 | } 14 | 15 | factory.obj = function(arr){ 16 | return factory({ 17 | objectMode:true 18 | }, arr) 19 | } 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | from2-array 2 | =========== 3 | 4 | [![NPM](https://nodei.co/npm/from2-array.png?global=true)](https://nodei.co/npm/from2-array/) 5 | 6 | [![Travis](http://img.shields.io/travis/binocarlos/from2-array.svg?style=flat)](https://travis-ci.org/binocarlos/from2-array) 7 | 8 | Create a [from2](https://github.com/hughsk/from2) stream based on an array of source values 9 | 10 | Useful when you want to create a Readable stream with some values you already have in an array 11 | 12 | ## example 13 | 14 | ```js 15 | var from = require('from2-array') 16 | var through = require('through2') 17 | 18 | from.obj([{ 19 | name:'a' 20 | },{ 21 | name:'b' 22 | },{ 23 | name:'c' 24 | }]).pipe(through.obj(function(chunk, enc, cb){ 25 | console.log('found: ' + chunk.name) 26 | cb() 27 | })) 28 | 29 | ``` 30 | 31 | ## license 32 | 33 | MIT -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "from2-array", 3 | "version": "0.0.4", 4 | "description": "Create a from2 stream based on an array of source values", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "set -e; for t in test/*.js; do node $t; done" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/binocarlos/from2-array.git" 12 | }, 13 | "keywords": [ 14 | "stream", 15 | "streams2", 16 | "from", 17 | "source", 18 | "readable" 19 | ], 20 | "author": "Kai Davenport", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/binocarlos/from2-array/issues" 24 | }, 25 | "homepage": "https://github.com/binocarlos/from2-array", 26 | "dependencies": { 27 | "from2": "^2.0.3" 28 | }, 29 | "devDependencies": { 30 | "tape": "^4.0.0", 31 | "through2": "^2.0.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | *.sql 27 | *.sqlite 28 | 29 | # OS generated files # 30 | ###################### 31 | .DS_Store 32 | .DS_Store? 33 | ._* 34 | .Spotlight-V100 35 | .Trashes 36 | Icon? 37 | ehthumbs.db 38 | Thumbs.db 39 | 40 | # Vagrant # 41 | ########### 42 | .vagrant 43 | 44 | # nodejs # 45 | ########### 46 | lib-cov 47 | *.seed 48 | *.log 49 | *.csv 50 | *.dat 51 | *.out 52 | *.pid 53 | *.gz 54 | 55 | dist 56 | pids 57 | logs 58 | results 59 | 60 | npm-debug.log 61 | node_modules 62 | build 63 | 64 | test/tempdb 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Kai Davenport 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var test = require('tape') 2 | var path = require('path') 3 | 4 | var through = require('through2') 5 | var from = require('../') 6 | 7 | function fromStrings() { 8 | return from.obj(['a', 'b', 'c']) 9 | } 10 | 11 | function fromObjects() { 12 | return from.obj([{ 13 | name:'a'},{ 14 | name:'b'},{ 15 | name:'c'}]) 16 | } 17 | 18 | test('from2 string array', function(t) { 19 | var stream = fromStrings() 20 | 21 | var arr = [] 22 | stream 23 | .pipe(through.obj(function(chunk, enc, cb){ 24 | arr.push(chunk) 25 | cb() 26 | }, function(){ 27 | t.equal(arr.length, 3) 28 | t.equal(arr[0], 'a') 29 | t.equal(arr[1], 'b') 30 | t.equal(arr[2], 'c') 31 | t.end() 32 | })) 33 | }) 34 | 35 | test('from2 object array', function(t) { 36 | var stream = fromObjects() 37 | 38 | var arr = [] 39 | stream 40 | .pipe(through.obj(function(chunk, enc, cb){ 41 | arr.push(chunk) 42 | cb() 43 | }, function(){ 44 | t.equal(arr.length, 3) 45 | t.equal(arr[0].name, 'a') 46 | t.equal(arr[1].name, 'b') 47 | t.equal(arr[2].name, 'c') 48 | t.end() 49 | })) 50 | }) 51 | --------------------------------------------------------------------------------