├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.d.ts ├── index.js ├── package.json └── test └── basic.js /.npmignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | test/ 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Feross Aboukhadijeh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | 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, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # string-to-stream [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] 2 | 3 | [travis-image]: https://img.shields.io/travis/feross/string-to-stream/master.svg 4 | [travis-url]: https://travis-ci.org/feross/string-to-stream 5 | [npm-image]: https://img.shields.io/npm/v/string-to-stream.svg 6 | [npm-url]: https://npmjs.org/package/string-to-stream 7 | [downloads-image]: https://img.shields.io/npm/dm/string-to-stream.svg 8 | [downloads-url]: https://npmjs.org/package/string-to-stream 9 | [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg 10 | [standard-url]: https://standardjs.com 11 | 12 | #### Convert a string into a stream (streams2) 13 | 14 | ### install 15 | 16 | ``` 17 | npm install string-to-stream 18 | ``` 19 | 20 | ### usage 21 | 22 | Use `string-to-stream` like this: 23 | 24 | ```js 25 | var str = require('string-to-stream') 26 | 27 | str('hi there').pipe(process.stdout) // => 'hi there' 28 | ``` 29 | 30 | ### license 31 | 32 | MIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org). 33 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'string-to-stream' { 2 | const stringToStream: (data: string, encoding?: string) => NodeJS.ReadableStream; 3 | export = stringToStream; 4 | } 5 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = stringToStream 2 | 3 | const stream = require('readable-stream') 4 | 5 | class StringStream extends stream.Readable { 6 | constructor (str, encoding) { 7 | super() 8 | this._str = str 9 | this._encoding = encoding || 'utf8' 10 | } 11 | 12 | _read () { 13 | if (!this.ended) { 14 | process.nextTick(() => { 15 | this.push(Buffer.from(this._str, this._encoding)) 16 | this.push(null) 17 | }) 18 | this.ended = true 19 | } 20 | } 21 | } 22 | 23 | function stringToStream (str, encoding) { 24 | return new StringStream(str, encoding) 25 | } 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "string-to-stream", 3 | "description": "Convert a string into a stream (streams2)", 4 | "version": "3.0.1", 5 | "author": "Feross Aboukhadijeh (http://feross.org/)", 6 | "bugs": { 7 | "url": "https://github.com/feross/string-to-stream/issues" 8 | }, 9 | "dependencies": { 10 | "readable-stream": "^3.4.0" 11 | }, 12 | "devDependencies": { 13 | "concat-stream": "^2.0.0", 14 | "standard": "*", 15 | "tape": "^4.0.0" 16 | }, 17 | "homepage": "https://github.com/feross/string-to-stream", 18 | "keywords": [ 19 | "convert", 20 | "convert string to stream", 21 | "str", 22 | "str stream", 23 | "stream", 24 | "string", 25 | "string stream", 26 | "string to stream" 27 | ], 28 | "license": "MIT", 29 | "main": "index.js", 30 | "repository": { 31 | "type": "git", 32 | "url": "git://github.com/feross/string-to-stream.git" 33 | }, 34 | "scripts": { 35 | "test": "standard && tape test/*.js" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /test/basic.js: -------------------------------------------------------------------------------- 1 | const concat = require('concat-stream') 2 | const str = require('../') 3 | const test = require('tape') 4 | 5 | test('basic tests', t => { 6 | t.plan(2) 7 | str('hi there').pipe(concat(data => { 8 | t.equal(data.toString(), 'hi there') 9 | })) 10 | str('').pipe(concat(data => { 11 | t.equal(data.toString(), '') 12 | })) 13 | }) 14 | --------------------------------------------------------------------------------