Skip to content

Commit 0dcc58a

Browse files
committed
Updating lint rules & fixing formatting, generated CHANGELOG.md
1 parent 64308a4 commit 0dcc58a

File tree

6 files changed

+218
-36
lines changed

6 files changed

+218
-36
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d
44

55
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
66

7+
#### [2.0.0](https://github.com/avoidwork/tiny-jsonl/compare/1.0.10...2.0.0)
8+
9+
- Bump husky from 9.1.0 to 9.1.1 [`#8`](https://github.com/avoidwork/tiny-jsonl/pull/8)
10+
- Bump husky from 9.0.11 to 9.1.0 [`#7`](https://github.com/avoidwork/tiny-jsonl/pull/7)
11+
- Bump eslint from 9.6.0 to 9.7.0 [`#6`](https://github.com/avoidwork/tiny-jsonl/pull/6)
12+
- Bump tiny-strings from 1.0.6 to 1.0.12 [`#5`](https://github.com/avoidwork/tiny-jsonl/pull/5)
13+
- Bump rollup from 4.18.0 to 4.18.1 [`#4`](https://github.com/avoidwork/tiny-jsonl/pull/4)
14+
- Bump tiny-strings from 1.0.5 to 1.0.6 [`#3`](https://github.com/avoidwork/tiny-jsonl/pull/3)
15+
- Creating 'parse()' & renaming 'jsonl()' to 'stringify()', updating README.md [`380c0bd`](https://github.com/avoidwork/tiny-jsonl/commit/380c0bddfa79f272b7adc3fff1e434f8d7502ff4)
16+
717
#### [1.0.10](https://github.com/avoidwork/tiny-jsonl/compare/1.0.9...1.0.10)
818

19+
> 6 July 2024
20+
921
- Version bump [`6de15b1`](https://github.com/avoidwork/tiny-jsonl/commit/6de15b1185ba69f06975ead7532839f8537a7c0f)
22+
- Generated CHANGELOG.md [`297555d`](https://github.com/avoidwork/tiny-jsonl/commit/297555d4cd5c5d3e25088b7f66c6d3f0c8d7b3c0)
1023

1124
#### [1.0.9](https://github.com/avoidwork/tiny-jsonl/compare/1.0.8...1.0.9)
1225

eslint.config.js

+172-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,175 @@ import globals from "globals";
22
import pluginJs from "@eslint/js";
33

44
export default [
5-
{languageOptions: {globals: {...globals.browser, ...globals.node, it: true, describe: true}}},
6-
pluginJs.configs.recommended,
7-
];
5+
{
6+
languageOptions: {
7+
globals: {
8+
...globals.node,
9+
...globals.browser,
10+
it: true,
11+
describe: true
12+
},
13+
parserOptions: {
14+
ecmaVersion: 2022
15+
}
16+
},
17+
rules: {
18+
"arrow-parens": [2, "as-needed"],
19+
"arrow-spacing": [2, {"before": true, "after": true}],
20+
"block-scoped-var": [0],
21+
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
22+
"camelcase": [0],
23+
"comma-dangle": [2, "never"],
24+
"comma-spacing": [2],
25+
"comma-style": [2, "last"],
26+
"complexity": [0, 11],
27+
"consistent-return": [2],
28+
"consistent-this": [0, "that"],
29+
"curly": [2, "multi-line"],
30+
"default-case": [2],
31+
"dot-notation": [2, {"allowKeywords": true}],
32+
"eol-last": [2],
33+
"eqeqeq": [2],
34+
"func-names": [0],
35+
"func-style": [0, "declaration"],
36+
"generator-star-spacing": [2, "after"],
37+
"guard-for-in": [0],
38+
"handle-callback-err": [0],
39+
"indent": ["error", "tab", {"VariableDeclarator": {"var": 1, "let": 1, "const": 1}, "SwitchCase": 1}],
40+
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
41+
"quotes": [2, "double", "avoid-escape"],
42+
"max-depth": [0, 4],
43+
"max-len": [0, 80, 4],
44+
"max-nested-callbacks": [0, 2],
45+
"max-params": [0, 3],
46+
"max-statements": [0, 10],
47+
"new-parens": [2],
48+
"new-cap": [2, {"capIsNewExceptions": ["ToInteger", "ToObject", "ToPrimitive", "ToUint32"]}],
49+
"newline-after-var": [0],
50+
"newline-before-return": [2],
51+
"no-alert": [2],
52+
"no-array-constructor": [2],
53+
"no-bitwise": [0],
54+
"no-caller": [2],
55+
"no-catch-shadow": [2],
56+
"no-cond-assign": [2],
57+
"no-console": [0],
58+
"no-constant-condition": [1],
59+
"no-continue": [2],
60+
"no-control-regex": [2],
61+
"no-debugger": [2],
62+
"no-delete-var": [2],
63+
"no-div-regex": [0],
64+
"no-dupe-args": [2],
65+
"no-dupe-keys": [2],
66+
"no-duplicate-case": [2],
67+
"no-else-return": [0],
68+
"no-empty": [2],
69+
"no-eq-null": [0],
70+
"no-eval": [2],
71+
"no-ex-assign": [2],
72+
"no-extend-native": [1],
73+
"no-extra-bind": [2],
74+
"no-extra-boolean-cast": [2],
75+
"no-extra-semi": [1],
76+
"no-empty-character-class": [2],
77+
"no-fallthrough": [2],
78+
"no-floating-decimal": [2],
79+
"no-func-assign": [2],
80+
"no-implied-eval": [2],
81+
"no-inline-comments": [0],
82+
"no-inner-declarations": [2, "functions"],
83+
"no-invalid-regexp": [2],
84+
"no-irregular-whitespace": [2],
85+
"no-iterator": [2],
86+
"no-label-var": [2],
87+
"no-labels": [2],
88+
"no-lone-blocks": [2],
89+
"no-lonely-if": [2],
90+
"no-loop-func": [2],
91+
"no-mixed-requires": [0, false],
92+
"no-mixed-spaces-and-tabs": [2, false],
93+
"no-multi-spaces": [2],
94+
"no-multi-str": [2],
95+
"no-multiple-empty-lines": [2, {"max": 2}],
96+
"no-native-reassign": [0],
97+
"no-negated-in-lhs": [2],
98+
"no-nested-ternary": [0],
99+
"no-new": [2],
100+
"no-new-func": [0],
101+
"no-new-object": [2],
102+
"no-new-require": [0],
103+
"no-new-wrappers": [2],
104+
"no-obj-calls": [2],
105+
"no-octal": [2],
106+
"no-octal-escape": [2],
107+
"no-param-reassign": [0],
108+
"no-path-concat": [0],
109+
"no-plusplus": [0],
110+
"no-process-env": [0],
111+
"no-process-exit": [0],
112+
"no-proto": [2],
113+
"no-redeclare": [2],
114+
"no-regex-spaces": [2],
115+
"no-reserved-keys": [0],
116+
"no-reno-new-funced-modules": [0],
117+
"no-return-assign": [2],
118+
"no-script-url": [2],
119+
"no-self-compare": [0],
120+
"no-sequences": [2],
121+
"no-shadow": [2],
122+
"no-shadow-restricted-names": [2],
123+
"no-spaced-func": [2],
124+
"no-sparse-arrays": [2],
125+
"no-sync": [0],
126+
"no-ternary": [0],
127+
"no-throw-literal": [2],
128+
"no-trailing-spaces": [2],
129+
"no-undef": [2],
130+
"no-undef-init": [2],
131+
"no-undefined": [0],
132+
"no-underscore-dangle": [0],
133+
"no-unreachable": [2],
134+
"no-unused-expressions": [2],
135+
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
136+
"no-use-before-define": [2],
137+
"no-void": [0],
138+
"no-warning-comments": [0, {"terms": ["todo", "fixme", "xxx"], "location": "start"}],
139+
"no-with": [2],
140+
"no-extra-parens": [2],
141+
"one-var": [0],
142+
"operator-assignment": [0, "always"],
143+
"operator-linebreak": [2, "after"],
144+
"padded-blocks": [0],
145+
"quote-props": [0],
146+
"radix": [0],
147+
"semi": [2],
148+
"semi-spacing": [2, {before: false, after: true}],
149+
"sort-vars": [0],
150+
"keyword-spacing": [2],
151+
"space-before-function-paren": [2, {anonymous: "always", named: "always"}],
152+
"space-before-blocks": [2, "always"],
153+
"space-in-brackets": [0, "never", {
154+
singleValue: true,
155+
arraysInArrays: false,
156+
arraysInObjects: false,
157+
objectsInArrays: true,
158+
objectsInObjects: true,
159+
propertyName: false
160+
}],
161+
"space-in-parens": [2, "never"],
162+
"space-infix-ops": [2],
163+
"space-unary-ops": [2, {words: true, nonwords: false}],
164+
"spaced-line-comment": [0, "always"],
165+
strict: [0],
166+
"use-isnan": [2],
167+
"valid-jsdoc": [0],
168+
"valid-typeof": [2],
169+
"vars-on-top": [0],
170+
"wrap-iife": [2],
171+
"wrap-regex": [2],
172+
yoda: [2, "never", {exceptRange: true}]
173+
}
174+
},
175+
pluginJs.configs.recommended
176+
];

src/parse.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {MSG_INVALID_INPUT, STRING_STRING} from "./constants";
66
* @returns {any}
77
*/
88
export function parse (arg) {
9-
if (typeof arg !== STRING_STRING) {
10-
throw new TypeError(MSG_INVALID_INPUT);
11-
}
9+
if (typeof arg !== STRING_STRING) {
10+
throw new TypeError(MSG_INVALID_INPUT);
11+
}
1212

13-
const result = JSON.parse(`[${arg.trim().split(/(?<=})\n/).join(",")}]`);
13+
const result = JSON.parse(`[${arg.trim().split(/(?<=})\n/).join(",")}]`);
1414

15-
return result.length > 1 ? result : result[0];
15+
return result.length > 1 ? result : result[0];
1616
}

src/rewrite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66
export function rewrite (arg) {
77
return `"${arg.replace(/"/g, "\\\"").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t")}"`;
8-
}
8+
}

src/stringify.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {
2-
MSG_INDEX,
3-
MSG_INVALID_INPUT,
4-
STRING_MARK,
5-
STRING_NEW_LINE,
6-
STRING_OBJECT,
7-
STRING_REPLACEMENT
2+
MSG_INDEX,
3+
MSG_INVALID_INPUT,
4+
STRING_MARK,
5+
STRING_NEW_LINE,
6+
STRING_OBJECT,
7+
STRING_REPLACEMENT
88
} from "./constants.js";
99
import {rewrite} from "./rewrite.js";
1010
import {strings} from "tiny-strings";
@@ -15,28 +15,28 @@ import {strings} from "tiny-strings";
1515
* @returns {string}
1616
*/
1717
export function stringify (arg) {
18-
if (typeof arg !== STRING_OBJECT) {
19-
throw new TypeError(MSG_INVALID_INPUT);
20-
}
18+
if (typeof arg !== STRING_OBJECT) {
19+
throw new TypeError(MSG_INVALID_INPUT);
20+
}
2121

22-
let result;
22+
let result;
2323

24-
if (Array.isArray(arg)) {
25-
result = arg.map(i => stringify(i)).join(STRING_NEW_LINE);
26-
} else {
27-
let tmp = JSON.stringify(arg, null, 0);
28-
const extracted = strings(arg, true).map(rewrite);
24+
if (Array.isArray(arg)) {
25+
result = arg.map(i => stringify(i)).join(STRING_NEW_LINE);
26+
} else {
27+
let tmp = JSON.stringify(arg, null, 0);
28+
const extracted = strings(arg, true).map(rewrite);
2929

30-
for (const [idx, val] of extracted.entries()) {
31-
tmp = tmp.replace(val, MSG_INDEX.replace(STRING_MARK, idx));
32-
}
30+
for (const [idx, val] of extracted.entries()) {
31+
tmp = tmp.replace(val, MSG_INDEX.replace(STRING_MARK, idx));
32+
}
3333

34-
result = tmp.replace(/(:|,)/g, STRING_REPLACEMENT);
34+
result = tmp.replace(/(:|,)/g, STRING_REPLACEMENT);
3535

36-
for (const [idx, val] of extracted.entries()) {
37-
result = result.replace(MSG_INDEX.replace(STRING_MARK, idx.toString()), val);
38-
}
39-
}
36+
for (const [idx, val] of extracted.entries()) {
37+
result = result.replace(MSG_INDEX.replace(STRING_MARK, idx.toString()), val);
38+
}
39+
}
4040

41-
return result;
42-
}
41+
return result;
42+
}

test/jsonl.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("Testing functionality", function () {
1616

1717
it("It should throw a TypeError if trying to parse a String", function () {
1818
throws(() => parse(true), TypeError);
19-
})
19+
});
2020

2121
it("It should stringify an Object", function () {
2222
const jsonlObject = stringify({"id": "test-123", "email": "[email protected]", "field1:field2": "d,e", "description": "this field has \"embed quotes\"", "object": {"abc": true, "def": false}, "array": ["ghi", 1234, "other string", {"nested": true, "multi-line": "string\ttabbed\n\rwith\n\rnew\n\rlines"}]});
@@ -32,5 +32,5 @@ describe("Testing functionality", function () {
3232

3333
it("It should throw a TypeError if trying to stringify a String", function () {
3434
throws(() => stringify("invalid"), TypeError);
35-
})
35+
});
3636
});

0 commit comments

Comments
 (0)