Skip to content

Commit 053af9c

Browse files
authored
Initial version (#1)
* Initial commit of code * Adding github files * Adding precommit hook * Adding 'files' to package.json * Adding constants, minor reformatting * Fixing '.github/ci.yml' * Reverting change to '.gitignore' * Updating '.gitignore' * Updating 'types/jsonl.d.ts'
1 parent 96d4da7 commit 053af9c

22 files changed

+4236
-2
lines changed

.github/FUNDING.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [avoidwork]

.github/dependabot.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
open-pull-requests-limit: 10
8+
- package-ecosystem: npm
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
open-pull-requests-limit: 10

.github/workflows/ci.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: ci
3+
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [18.x, 20.x]
16+
17+
steps:
18+
- name: Checkout Repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 1
22+
23+
- name: Setup Node ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
always-auth: false
27+
node-version: ${{ matrix.node-version }}
28+
29+
- name: Install dependencies
30+
run: npm install
31+
32+
- name: Build
33+
run: npm run rollup
34+
35+
- name: Run Tests
36+
run: npm run test
37+
38+
automerge:
39+
needs: build
40+
runs-on: ubuntu-latest
41+
permissions:
42+
pull-requests: write
43+
contents: write
44+
steps:
45+
- uses: fastify/github-action-merge-dependabot@v3
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
.idea

.husky/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm test

README.md

+127-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,127 @@
1-
# tiny-jsonl
2-
Transforms Objects and Arrays into JSONL Strings
1+
# Tiny JSONL
2+
3+
Transforms Objects and Arrays into JSONL Strings.
4+
5+
## Example
6+
7+
### Input
8+
9+
```javascript
10+
import {jsonl} from "tiny-jsonl";
11+
jsonl([
12+
{
13+
"_id": "66897c0b5bb3f3bda598a7be",
14+
"index": 0,
15+
"guid": "57cc37b7-ea7b-4cf5-b07e-238a15cc1cdd",
16+
"isActive": true,
17+
"balance": "$1,290.80",
18+
"picture": "http://placehold.it/32x32",
19+
"age": 21,
20+
"eyeColor": "blue",
21+
"name": "Valeria Jenkins",
22+
"gender": "female",
23+
"company": "GEOLOGIX",
24+
"email": "[email protected]",
25+
"phone": "+1 (976) 597-3338",
26+
"address": "681 Jackson Place, Collins, Nevada, 8477",
27+
"about": "Officia sunt fugiat aute eiusmod cillum excepteur enim consectetur in pariatur consequat cupidatat. Id minim anim sint cupidatat nostrud labore esse proident eiusmod eu. Dolor sit aute adipisicing est proident eiusmod voluptate reprehenderit sunt aliquip non quis. Lorem voluptate laboris aliquip cupidatat.\r\n",
28+
"registered": "2016-04-05T01:14:10 +04:00",
29+
"latitude": 8.514373,
30+
"longitude": -22.578972,
31+
"tags": [
32+
"voluptate",
33+
"esse",
34+
"amet",
35+
"mollit",
36+
"in",
37+
"consectetur",
38+
"sunt"
39+
],
40+
"friends": [
41+
{
42+
"id": 0,
43+
"name": "Moore Howell"
44+
},
45+
{
46+
"id": 1,
47+
"name": "Summer Cline"
48+
},
49+
{
50+
"id": 2,
51+
"name": "Francis Simon"
52+
}
53+
],
54+
"greeting": "Hello, Valeria Jenkins! You have 1 unread messages.",
55+
"favoriteFruit": "banana"
56+
},
57+
{
58+
"_id": "66897c0b0eea9250887803d6",
59+
"index": 1,
60+
"guid": "6eac3134-b442-4289-a498-ef9b5624f196",
61+
"isActive": false,
62+
"balance": "$1,302.96",
63+
"picture": "http://placehold.it/32x32",
64+
"age": 28,
65+
"eyeColor": "brown",
66+
"name": "Amanda Rodgers",
67+
"gender": "female",
68+
"company": "GRAINSPOT",
69+
"email": "[email protected]",
70+
"phone": "+1 (987) 457-3247",
71+
"address": "650 Osborn Street, Edenburg, New Jersey, 1377",
72+
"about": "Eu minim enim aliquip nulla aliquip elit sit nostrud dolore reprehenderit aliquip sit qui Lorem. Enim et excepteur dolor velit minim nulla ullamco nisi. Qui adipisicing id occaecat nisi duis quis sint minim laborum minim id. Do id aliqua deserunt incididunt nulla officia nostrud reprehenderit laborum aliquip qui. Veniam pariatur eu quis reprehenderit velit nostrud deserunt deserunt. Commodo duis esse deserunt laborum tempor dolore anim laborum deserunt ipsum sit tempor consectetur.\r\n",
73+
"registered": "2023-05-27T09:39:08 +04:00",
74+
"latitude": 45.890773,
75+
"longitude": -29.059383,
76+
"tags": [
77+
"Lorem",
78+
"sunt",
79+
"cillum",
80+
"ea",
81+
"in",
82+
"aute",
83+
"culpa"
84+
],
85+
"friends": [
86+
{
87+
"id": 0,
88+
"name": "Jo Nunez"
89+
},
90+
{
91+
"id": 1,
92+
"name": "Mcdonald Burns"
93+
},
94+
{
95+
"id": 2,
96+
"name": "Pacheco Vang"
97+
}
98+
],
99+
"greeting": "Hello, Amanda Rodgers! You have 7 unread messages.",
100+
"favoriteFruit": "strawberry"
101+
}
102+
]);
103+
```
104+
105+
### Output
106+
107+
```javascript
108+
{"_id": "66897c0b5bb3f3bda598a7be", "index": 0, "guid": "57cc37b7-ea7b-4cf5-b07e-238a15cc1cdd", "isActive": true, "balance": "$1, 290.80", "picture": "http: //placehold.it/32x32", "age": 21, "eyeColor": "blue", "name": "Valeria Jenkins", "gender": "female", "company": "GEOLOGIX", "email": "[email protected]", "phone": "+1 (976) 597-3338", "address": "681 Jackson Place, Collins, Nevada, 8477", "about": "Officia sunt fugiat aute eiusmod cillum excepteur enim consectetur in pariatur consequat cupidatat. Id minim anim sint cupidatat nostrud labore esse proident eiusmod eu. Dolor sit aute adipisicing est proident eiusmod voluptate reprehenderit sunt aliquip non quis. Lorem voluptate laboris aliquip cupidatat.rn", "registered": "2016-04-05T01: 14: 10 +04: 00", "latitude": 8.514373, "longitude": -22.578972, "tags": ["voluptate", "esse", "amet", "mollit", "in", "consectetur", "sunt"], "friends": [{"id": 0, "name": "Moore Howell"}, {"id": 1, "name": "Summer Cline"}, {"id": 2, "name": "Francis Simon"}], "greeting": "Hello, Valeria Jenkins! You have 1 unread messages.", "favoriteFruit": "banana"}
109+
{"_id": "66897c0b0eea9250887803d6", "index": 1, "guid": "6eac3134-b442-4289-a498-ef9b5624f196", "isActive": false, "balance": "$1, 302.96", "picture": "http: //placehold.it/32x32", "age": 28, "eyeColor": "brown", "name": "Amanda Rodgers", "gender": "female", "company": "GRAINSPOT", "email": "[email protected]", "phone": "+1 (987) 457-3247", "address": "650 Osborn Street, Edenburg, New Jersey, 1377", "about": "Eu minim enim aliquip nulla aliquip elit sit nostrud dolore reprehenderit aliquip sit qui Lorem. Enim et excepteur dolor velit minim nulla ullamco nisi. Qui adipisicing id occaecat nisi duis quis sint minim laborum minim id. Do id aliqua deserunt incididunt nulla officia nostrud reprehenderit laborum aliquip qui. Veniam pariatur eu quis reprehenderit velit nostrud deserunt deserunt. Commodo duis esse deserunt laborum tempor dolore anim laborum deserunt ipsum sit tempor consectetur.rn", "registered": "2023-05-27T09: 39: 08 +04: 00", "latitude": 45.890773, "longitude": -29.059383, "tags": ["Lorem", "sunt", "cillum", "ea", "in", "aute", "culpa"], "friends": [{"id": 0, "name": "Jo Nunez"}, {"id": 1, "name": "Mcdonald Burns"}, {"id": 2, "name": "Pacheco Vang"}], "greeting": "Hello, Amanda Rodgers! You have 7 unread messages.", "favoriteFruit": "strawberry"}
110+
```
111+
112+
## Testing
113+
114+
Tiny-JSONL has 100% code coverage with its tests.
115+
116+
```console
117+
----------------|---------|----------|---------|---------|-------------------
118+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
119+
----------------|---------|----------|---------|---------|-------------------
120+
All files | 100 | 100 | 100 | 100 |
121+
tiny-jsonl.cjs | 100 | 100 | 100 | 100 |
122+
----------------|---------|----------|---------|---------|-------------------
123+
```
124+
125+
## License
126+
Copyright (c) 2024 Jason Mulligan
127+
Licensed under the BSD-3 license.

dist/tiny-jsonl.cjs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* tiny-jsonl
3+
*
4+
* @copyright 2024 Jason Mulligan <[email protected]>
5+
* @license BSD-3-Clause
6+
* @version 1.0.0
7+
*/
8+
'use strict';
9+
10+
const STRING_EMPTY = "";
11+
const STRING_LEFT_BRACE = "{";
12+
const STRING_RIGHT_BRACE = "}";
13+
const STRING_NEW_LINE = "\n";
14+
const STRING_REPLACEMENT = "$1 ";
15+
16+
function jsonl (arg) {
17+
let result;
18+
19+
if (Array.isArray(arg)) {
20+
result = arg.map(i => jsonl(i)).join(STRING_NEW_LINE);
21+
} else {
22+
result = JSON.stringify(arg, null, 0)
23+
.replace(/^"|\n|\\|"$/g, STRING_EMPTY)
24+
.replace(/^{\s/, STRING_LEFT_BRACE)
25+
.replace(/\s}$/, STRING_RIGHT_BRACE)
26+
.replace(/(:|,)/g, STRING_REPLACEMENT);
27+
}
28+
29+
return result;
30+
}
31+
32+
exports.jsonl = jsonl;

dist/tiny-jsonl.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* tiny-jsonl
3+
*
4+
* @copyright 2024 Jason Mulligan <[email protected]>
5+
* @license BSD-3-Clause
6+
* @version 1.0.0
7+
*/
8+
const STRING_EMPTY = "";
9+
const STRING_LEFT_BRACE = "{";
10+
const STRING_RIGHT_BRACE = "}";
11+
const STRING_NEW_LINE = "\n";
12+
const STRING_REPLACEMENT = "$1 ";function jsonl (arg) {
13+
let result;
14+
15+
if (Array.isArray(arg)) {
16+
result = arg.map(i => jsonl(i)).join(STRING_NEW_LINE);
17+
} else {
18+
result = JSON.stringify(arg, null, 0)
19+
.replace(/^"|\n|\\|"$/g, STRING_EMPTY)
20+
.replace(/^{\s/, STRING_LEFT_BRACE)
21+
.replace(/\s}$/, STRING_RIGHT_BRACE)
22+
.replace(/(:|,)/g, STRING_REPLACEMENT);
23+
}
24+
25+
return result;
26+
}export{jsonl};

dist/tiny-jsonl.min.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*!
2+
2024 Jason Mulligan <[email protected]>
3+
@version 1.0.0
4+
*/
5+
function r(e){let n;return n=Array.isArray(e)?e.map((e=>r(e))).join("\n"):JSON.stringify(e,null,0).replace(/^"|\n|\\|"$/g,"").replace(/^{\s/,"{").replace(/\s}$/,"}").replace(/(:|,)/g,"$1 "),n}export{r as jsonl};//# sourceMappingURL=tiny-jsonl.min.js.map

dist/tiny-jsonl.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/tiny-jsonl.umd.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* tiny-jsonl
3+
*
4+
* @copyright 2024 Jason Mulligan <[email protected]>
5+
* @license BSD-3-Clause
6+
* @version 1.0.0
7+
*/
8+
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.lru={}));})(this,(function(exports){'use strict';const STRING_EMPTY = "";
9+
const STRING_LEFT_BRACE = "{";
10+
const STRING_RIGHT_BRACE = "}";
11+
const STRING_NEW_LINE = "\n";
12+
const STRING_REPLACEMENT = "$1 ";function jsonl (arg) {
13+
let result;
14+
15+
if (Array.isArray(arg)) {
16+
result = arg.map(i => jsonl(i)).join(STRING_NEW_LINE);
17+
} else {
18+
result = JSON.stringify(arg, null, 0)
19+
.replace(/^"|\n|\\|"$/g, STRING_EMPTY)
20+
.replace(/^{\s/, STRING_LEFT_BRACE)
21+
.replace(/\s}$/, STRING_RIGHT_BRACE)
22+
.replace(/(:|,)/g, STRING_REPLACEMENT);
23+
}
24+
25+
return result;
26+
}exports.jsonl=jsonl;}));

dist/tiny-jsonl.umd.min.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/*!
2+
2024 Jason Mulligan <[email protected]>
3+
@version 1.0.0
4+
*/
5+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).lru={})}(this,(function(e){"use strict";e.jsonl=function e(n){let t;return t=Array.isArray(n)?n.map((n=>e(n))).join("\n"):JSON.stringify(n,null,0).replace(/^"|\n|\\|"$/g,"").replace(/^{\s/,"{").replace(/\s}$/,"}").replace(/(:|,)/g,"$1 "),t}}));//# sourceMappingURL=tiny-jsonl.umd.min.js.map

dist/tiny-jsonl.umd.min.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eslint.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
4+
export default [
5+
{languageOptions: {globals: {...globals.browser, ...globals.node, it: true, describe: true}}},
6+
pluginJs.configs.recommended,
7+
];

0 commit comments

Comments
 (0)