{"id":19149233,"url":"https://github.com/restuwahyu13/streambox-collection","last_synced_at":"2025-05-07T04:42:17.914Z","repository":{"id":38358594,"uuid":"332815036","full_name":"restuwahyu13/streambox-collection","owner":"restuwahyu13","description":"streambox-collection is a lightweight utility as a wrapper for displaying objects, arrays, strings, and number formats to clients using data streams.","archived":false,"fork":false,"pushed_at":"2023-03-06T12:59:07.000Z","size":1102,"stargazers_count":9,"open_issues_count":14,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T04:42:08.322Z","etag":null,"topics":["async-functions","grpc","node-module","nodejs-modules","pipeline","promise-wrapper","readable-stream","stream","utility","utility-library","wrapper-library","writable-streams"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/restuwahyu13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-01-25T16:45:41.000Z","updated_at":"2023-08-19T13:20:21.000Z","dependencies_parsed_at":"2025-04-19T15:50:40.170Z","dependency_job_id":"6fe3aa74-3dec-432f-947e-a3c4a96be07c","html_url":"https://github.com/restuwahyu13/streambox-collection","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restuwahyu13%2Fstreambox-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restuwahyu13%2Fstreambox-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restuwahyu13%2Fstreambox-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restuwahyu13%2Fstreambox-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/restuwahyu13","download_url":"https://codeload.github.com/restuwahyu13/streambox-collection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252816517,"owners_count":21808702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async-functions","grpc","node-module","nodejs-modules","pipeline","promise-wrapper","readable-stream","stream","utility","utility-library","wrapper-library","writable-streams"],"created_at":"2024-11-09T08:07:18.462Z","updated_at":"2025-05-07T04:42:17.893Z","avatar_url":"https://github.com/restuwahyu13.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StreamBox Collection\n\n[![Build Status](https://travis-ci.org/restuwahyu13/streambox-collection.svg?branch=main)](https://travis-ci.org/restuwahyu13/streambox-collection)\n[![Coverage Status](https://coveralls.io/repos/github/restuwahyu13/streambox-collection/badge.svg?branch=main)](https://coveralls.io/github/restuwahyu13/streambox-collection?branch=main)\n[![npm version](https://badge.fury.io/js/streambox-collection.svg)](https://badge.fury.io/js/streambox-collection)\n![node-current](https://img.shields.io/node/v/streambox-collection?style=flat-square)\n![npm](https://img.shields.io/npm/dm/streambox-collection)\n![npm bundle size](https://img.shields.io/bundlephobia/min/streambox-collection)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/streambox-collection)\n![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/restuwahyu13/streambox-collection)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/restuwahyu13/streambox-collection/blob/main/CONTRIBUTING.md)\n\n`streambox-collection` is a lightweight utility as a wrapper for displaying objects, arrays, strings, and number formats to\nclients using data streams, so data flow responses will be returned in buffer form, `streambox-collection` can also support large\nor small data streams, see this article for more information on [streams](https://bit.ly/39rkTzb).\n\n- [Installation Package](#installation-package)\n- [API Reference](#api-reference)\n  - [StreamBox Array](#streambox-array-data-recordstring-any--string--number-delay-number--promise)\n  - [StreamBox Object](#streambox-objectdata-recordstring-any-delay-number-promise)\n  - [StreamBox String](#streambox-stringdata-string-delay-number-promise)\n  - [StreamBox Number](#streambox-numberdata-number-delay-number-promise)\n  - [StreamBox Parser](#streambox-parserdata-buffer-any)\n- [Example Usage](#example-usage)\n- [Testing](#testing)\n- [Bugs](#bugs)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation Package\n\n#### With NPM\n  ```sh\nnpm install streambox-collection -S or yarn add streambox-collection -S\n  ```\n#### With CDN\n  follow this **[link](https://www.jsdelivr.com/package/npm/streambox-collection)**\n\n## API Reference\n\n#### StreamBox Array( data: Record\u003cstring, any\u003e[] | string[] | number[], delay?: number ): Promise\u003cBuffer\u003e\n\n- **streamBox.Array - Method** - create a data stream for the array and display it to the client\n- **streamBox.Array.data - Params** - set stream data for consumption to the client\n- **streamBox.Array.delay - Params** - set delay before returning data to the client\n\n#### StreamBox Object( data: Record\u003cstring, any\u003e, delay?: number ): Promise\u003cBuffer\u003e\n\n- **streamBox.object - Method** - create a data stream for the object and display it to the client\n- **streamBox.object.data - Params** - set stream data for consumption to the client\n- **streamBox.object.delay - Params** - set delay before returning data to the client\n\n#### StreamBox String( data: string, delay?: number ): Promise\u003cBuffer\u003e\n\n- **streamBox.string - Method** - create a data stream for the string and display it to the client\n- **streamBox.string.data - Params** - set stream data for consumption to the client\n- **streamBox.string.delay - Params** - set delay before returning data to the client\n\n#### StreamBox Number( data: number, delay?: number ): Promise\u003cBuffer\u003e\n\n- **streamBox.number - Method** - create a data stream for the number and display it to the client\n- **streamBox.number.data - Params** - set stream data for consumption to the client\n- **streamBox.number.delay - Params** - set delay before returning data to the client\n\n#### StreamBox Parser( data: Buffer ): any\n\n- **streamBox.toArray - Method** - parse the buffer data to an array and pass its value to the client\n- **streamBox.toObject - Method** - parse the buffer data to an object and pass its value to the client\n- **streamBox.toString - Method** - parse the buffer data to an string and pass its value to the client\n- **streamBox.toNumber - Method** - parse the buffer data to an number and pass its value to the client\n\n#### StreamBox Callback( parameter: Promise, callback: any ): void\n\n- **streamBox.toCallback - Method** - convert promise function to callback function\n\n### Example Usage\n\n- #### Example Usage Using CommonJS With Grpc\n\n  ```javascript\n  const streamBox = require('streambox-collection')\n  const { Empty } = require('../typedefs/users_pb')\n  const { client } = require('./client')\n\n  client.getUsers(Empty, (error, response) =\u003e {\n  \tif (error) console.error(error)\n  \tstreamBox\n  \t\t.array(response.toObject())\n  \t\t.then((res) =\u003e console.log(streamBox.toArray(res)))\n  \t\t.catch(console.log)\n  })\n  ```\n\n- #### Example Usage Using ES6 With Grpc\n\n  ```typescript\n  import * as streamBox from 'streambox-collection'\n  import { Empty } from '../typedefs/users_pb'\n  import { client } from './client'\n\n  client.getUsers(Empty, (error, response) =\u003e {\n  \tif (error) console.error(error)\n  \tstreamBox\n  \t\t.array(response.toObject())\n  \t\t.then((res) =\u003e console.log(streamBox.toArray(res)))\n  \t\t.catch(console.log)\n  })\n  ```\n\n- #### Example Usage Using ES6 With Grpc And Typescript\n\n  ```typescript\n  import * as streamBox from 'streambox-collection'\n  import { ServiceError } from 'grpc'\n  import { UserList, Empty } from '../typedefs/users_pb'\n  import { client } from './client'\n\n  client.getUsers(Empty, (error: ServiceError, response: UserList) =\u003e {\n  \tif (error) console.error(error)\n  \tstreamBox\n  \t\t.array(response.toObject())\n  \t\t.then((res: Buffer) =\u003e console.log(streamBox.toArray(res)))\n  \t\t.catch(console.log)\n  })\n  ```\n\n- #### Example Usage Using CommonJS With Express.js\n\n  ```javascript\n  const express = require('express')\n  const axios = require('axios')\n  const streamBox = require('streambox-collection')\n\n  const app = express()\n\n  app.get('/fetch', async (req, res) =\u003e {\n  \tconst { data } = await axios.get('https://jsonplaceholder.typicode.com/users')\n  \tstreamBox.array(data).then((response) =\u003e res.json(streamBox.toArray(response)))\n  })\n  ```\n\n- #### Example Usage Using ES6 With Express.js\n\n  ```typescript\n  import express from 'express'\n  import axios from 'axios'\n  import * as streamBox from 'streambox-collection'\n\n  const app = express()\n\n  app.get('/fetch', async (req, res) =\u003e {\n  \tconst { data } = await axios.get('https://jsonplaceholder.typicode.com/users')\n  \tstreamBox.array(data).then((response) =\u003e res.json(streamBox.toArray(response)))\n  })\n  ```\n\n- #### Example Usage Using ES6 With Express.js And Typescript\n\n  ```typescript\n  import express, { Express, Request, Response } from 'express'\n  import axios from 'axios'\n  import * as streamBox from 'streambox-collection'\n\n  const app = express() as Express\n\n  app.get('/fetch', async (req: Request, res: Response) =\u003e {\n  \tconst { data } = await axios.get('https://jsonplaceholder.typicode.com/users')\n  \tstreamBox.array(data).then((response: Buffer) =\u003e res.json(streamBox.toArray(response)))\n  })\n  ```\n\n- #### Example Usage Custom Stream Using CommonJS With Express.js\n\n  ```javascript\n  // util.stream.js\n  const streamBox = require('streambox-collection')\n\n  exports.streamBox = (handler, statusCode, data) =\u003e {\n  \tstreamBox.object({ ...data }).then((res) =\u003e {\n  \t\treturn handler.status(statusCode).json(streamBox.toObject(res))\n  \t})\n  }\n\n  // app.js\n  const express = require('express')\n  const axios = require('axios')\n  const { streamBox } = require('../utils/util.stream')\n\n  const app = express()\n\n  app.get('/fetch', async (req, res) =\u003e {\n  \tconst { data } = await axios.get('https://jsonplaceholder.typicode.com/users')\n  \t\tstreamBox(res, 200, {\n        method: req.method,\n        statusCode: res.statusCode,\n        users: data\n\t   })\n  })\n  ```\n\n- #### Example Usage Custom Stream Using ES6 With Express.js\n\n  ```javascript\n  // util.stream.js\n  import * as streamBoxCollection from 'streambox-collection'\n\n  export const streamBox = (handler, statusCode, data) =\u003e {\n  \tstreamBoxCollection.object({ ...data }).then((res) =\u003e {\n  \t\treturn handler.status(statusCode).json(streamBoxCollection.toObject(res))\n  \t})\n  }\n\n  // app.js\n  import express from 'express'\n  import axios from 'axios'\n  import { streamBox } from '../utils/util.stream'\n\n  const app = express()\n\n  app.get('/fetch', async (req, res) =\u003e {\n  \tconst { data } = await axios.get('https://jsonplaceholder.typicode.com/users')\n  \t\tstreamBox(res, 200, {\n        method: req.method,\n        statusCode: res.statusCode,\n        users: data\n\t  })\n  })\n  ```\n\n- #### Example Usage Custom Stream Using ES6 With Express.js And Typescript\n\n  ```typescript\n  // util.stream.ts\n  import { Response } from 'express'\n  import * as streamBoxCollection from 'streambox-collection'\n\n  export const streamBox = (handler: Response, statusCode: number, data: Record\u003cstring, any\u003e): void =\u003e {\n  \tstreamBoxCollection.object({ ...data }).then((res: Buffer) =\u003e {\n  \t\treturn handler.status(statusCode).json(streamBoxCollection.toObject(res))\n  \t})\n  }\n\n  // app.ts\n  import express, { Request, Response } from 'express'\n  import axios from 'axios'\n  import { streamBox } from '../utils/util.stream'\n\n  const app = express() as Express\n\n  app.get('/fetch', async (req: Request, res: Response) =\u003e {\n  \tconst { data } = await axios.get('https://jsonplaceholder.typicode.com/users')\n  \t\tstreamBox(res, 200, {\n        method: req.method,\n        statusCode: res.statusCode,\n        users: data\n\t  })\n  })\n  ```\n\n- #### Example Usage With React.js\n\n  ```javascript\n  import React, { useState, useEffect } from 'react'\n  import * as streamBox from 'streambox-collection'\n  import axios from 'axios'\n\n  function App() {\n    const [values, setValues] = useState({\n      loading: true,\n      users: []\n    })\n\n    useEffect(() =\u003e {\n      if (values.loading) {\n        fetchData()\n      }\n    }, [])\n\n    function fetchData() {\n      streamBox.toCallback(axios.get('https://jsonplaceholder.typicode.com/users'), (err, res) =\u003e {\n        if (err) console.log(err)\n        streamBox\n          .array(res.data)\n          .then((data) =\u003e setValues({ ...values, loading: false, users: streamBox.toArray(data) }))\n          .catch(console.error)\n      })\n    }\n\n    return (\n      \u003c\u003e\n        {values.loading \u0026\u0026 \u003ch1\u003eLoading...\u003c/h1\u003e}\n        \u003cul\u003e{!values.loading \u0026\u0026 values.users.map((user) =\u003e \u003cli key={user.id}\u003e{user.name}\u003c/li\u003e)}\u003c/ul\u003e\n      \u003c/\u003e\n    )\n  }\n\n  export default App\n  ```\n\n- #### Example Usage Convert Promise To Callback Using CommonJS\n\n  ```javascript\n  const streambox = require('streambox-collection')\n  const axios = require('axios')\n  const fetch = require('node-fetch')\n\n  // using axios\n  streambox.toCallback(axios.get('https://jsonplaceholder.typicode.com/users'), (err, res) =\u003e console.log(res.data))\n  \n  // using fetch\n  streambox.toCallback(fetch('https://jsonplaceholder.typicode.com/users'), async (err, res) =\u003e {\n\t   const data = await res.json()\n\t   console.log(data)\n   })\n   \n  // using promise constructor\n   function resultData() {\n\t     return new Promise((resolve, reject) =\u003e {\n\t\t    resolve('hello wordl')\n\t   })\n   }\n\n  streambox.toCallback(resultData(), (err, res) =\u003e console.log(res))\n  ```\n\n- #### Example Usage Convert Promise To Callback Using ES6\n\n  ```typescript\n  import * as streambox from 'streambox-collection'\n  import axios from 'axios'\n  import fetch from 'node-fetch'\n\n  // using axios\n  streambox.toCallback(axios.get('https://jsonplaceholder.typicode.com/users'), (err, res) =\u003e console.log(res.data))\n\n  // using fetch\n  streambox.toCallback(fetch('https://jsonplaceholder.typicode.com/users'), async (err, res) =\u003e {\n     const data = await res.json()\n     console.log(data)\n   })\n\n  // using promise constructor\n   function resultData() {\n       return new Promise((resolve, reject) =\u003e {\n        resolve('hello wordl')\n     })\n   }\n\n  streambox.toCallback(resultData(), (err, res) =\u003e console.log(res))\n  ```\n\n### Testing\n\n- Testing Via Local\n\n  ```sh\n  npm run test or make test\n  ```\n\n- Testing Via Local And Build\n\n  ```sh\n  make build\n  ```\n\n- Testing Via Docker\n\n  ```sh\n  docker build -t streambox-collection or make dkb tag=streambox-collection\n  ```\n\n### Bugs\n\nFor information on bugs related to package libraries, please visit\n[here](https://github.com/restuwahyu13/streambox-collection/issues)\n\n### Contributing\n\nWant to make **Streambox-Collection** more perfect ? Let's contribute and follow the\n[contribution guide.](https://github.com/restuwahyu13/streambox-collection/blob/main/CONTRIBUTING.md)\n\n### License\n\n- [MIT License](https://github.com/restuwahyu13/streambox-collection/blob/main/LICENSE.md)\n\n\u003cp align=\"right\" style=\"padding: 5px; border-radius: 100%; background-color: red; font-size: 2rem;\"\u003e\n  \u003cb\u003e\u003ca href=\"#streambox-collection\"\u003eBACK TO TOP\u003c/a\u003e\u003c/b\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestuwahyu13%2Fstreambox-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frestuwahyu13%2Fstreambox-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestuwahyu13%2Fstreambox-collection/lists"}