Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
libkakashi committed Mar 30, 2024
0 parents commit d44ebed
Show file tree
Hide file tree
Showing 13 changed files with 3,312 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/"
}
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches:
- main

pull_request:
branches:
- main

jobs:
test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
fail-fast: false

steps:
- id: checkout
name: Checkout
uses: actions/checkout@v3
- id: setup-bun
name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- id: install-deps
name: Install dependencies
run: |
bun install
- id: test
name: Run test
run: |
bun test
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-node@v3
with:
node-version: 16.x

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
3 changes: 3 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json')
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Kakashi <https://github.com/libkakashi>

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.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
A streaming JSON parser for Node.js that works with [superqueue](https://github.com/libkakashi/superqueue). This parser is designed to work with streaming JSON data, such as live generating JSON by an LLM where you want to display it in real-time as it's being generated.

Note: This is not meant to work with files that are too large to fit in memory.

### Installation

```bash
// yarn
yarn add superqueue@https://github.com/libkakashi/json-stream

// npm
npm i https://github.com/libkakashi/json-stream
```

### Example Usage

```tsx
import Queue from 'superqueue'; // https://github.com/libkakashi/superqueue
import JsonParser, {resolveStreamResult} from 'json-stream';

const queue = new Queue<string>();
const parser = new JsonParser(queue);
const jsonStream = parser.parseValue();

const res = await axios.get('streaming-json-endpoint', {
responseType: 'stream',
});
const stream = res.data;

stream.on('data', chunk => {
queue.push(...chunk); // push character by character, very important

// obj gets name and description properties dynamically populated as more chunks are received. Make sure to keep every property optional since you never know when they'll be populated.
const obj = await resolveStreamResult<{name?: string; description?: string}>(
jsonStream
);
});
stream.on('end', () => queue.end());
```
8 changes: 8 additions & 0 deletions build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import dts from 'bun-plugin-dts'

await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
minify: true,
plugins: [dts()]
})
Loading

0 comments on commit d44ebed

Please sign in to comment.