Skip to content

Commit c93518c

Browse files
Add linter and fix minor issues
1 parent f1237c5 commit c93518c

File tree

4 files changed

+90
-9
lines changed

4 files changed

+90
-9
lines changed

README.md

Lines changed: 68 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,78 @@
11
# littlejson
22

3-
LittleJSON is a lightweigh CLI to compress and decompress JSON files.
3+
**A lightweight CLI for compressing and decompressing JSON files.**
4+
5+
`littlejson` utilizes MessagePack for efficient binary serialization of JSON data, offering potentially significant size reductions for your JSON files.
6+
7+
## Features
8+
9+
- **Compress JSON to LJSON:** Reduces file size using MessagePack binary encoding.
10+
- **Decompress LJSON to JSON:** Restores compressed LJSON files back to readable JSON format.
11+
- **Simple CLI:** Easy-to-use command-line interface with clear instructions.
12+
- **File size analysis:** Provides details about the original size, compressed/decompressed size, and the percentage of change.
13+
14+
## Installation
15+
16+
**Global Installation:**
17+
If you perform a global installation, you can use the `littlejson` command directly instead of running it through `npx`.
18+
19+
```bash
20+
npm install -g littlejson
21+
```
422

523
## Usage
624

25+
### Compressing JSON Files
26+
27+
To compress a JSON file into a `.ljson` file:
28+
29+
```bash
30+
npx littlejson compress <input-file.json> [output-file.ljson]
31+
```
32+
33+
- `<input-file.json>`: The path to your JSON input file.
34+
- `[output-file.ljson]`: (Optional) The desired path for the compressed output file. If not provided, the output file will be named with the same base name as the input but with the `.ljson` extension, saved in the current working directory.
35+
36+
**Example:**
37+
738
```bash
8-
npx littlejson compress <input-file> <output-file>
9-
npx littlejson decompress <input-file> <output-file>
39+
npx littlejson compress data.json compressed.ljson
40+
# or
41+
npx littlejson compress data.json
1042
```
1143

44+
### Decompressing LJSON Files
45+
46+
To decompress a `.ljson` file back into a `.json` file:
47+
48+
```bash
49+
npx littlejson decompress <input-file.ljson> [output-file.json]
50+
```
51+
52+
- `<input-file.ljson>`: The path to your LJSON input file.
53+
- `[output-file.json]`: (Optional) The desired path for the decompressed output file. If not provided, the output file will be named with the same base name as the input but with the `.json` extension, saved in the current working directory.
54+
55+
**Example:**
56+
57+
```bash
58+
npx littlejson decompress compressed.ljson decompressed.json
59+
# or
60+
npx littlejson decompress compressed.ljson
61+
```
62+
63+
## Output
64+
65+
The CLI provides useful details upon completion:
66+
67+
- Success/error messages
68+
- Original file size
69+
- Compressed/Decompressed file size
70+
- Compression/Size change percentage
71+
1272
## License
1373

14-
MIT
74+
[MIT](LICENSE)
75+
76+
## Contributing
77+
78+
Contributions are welcome! Feel free to submit a pull request or open an issue.

eslint.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pluginJs from "@eslint/js";
2+
import globals from "globals";
3+
import tseslint from "typescript-eslint";
4+
5+
/** @type {import('eslint').Linter.Config[]} */
6+
export default [
7+
{ files: ["**/*.{js,mjs,cjs,ts}"] },
8+
{ languageOptions: { globals: globals.browser } },
9+
pluginJs.configs.recommended,
10+
...tseslint.configs.recommended,
11+
];

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "littlejson",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"module": "dist/index.js",
55
"type": "module",
66
"bin": {
77
"littlejson": "dist/index.js"
88
},
99
"scripts": {
10-
"build": "bun build src/index.ts --outdir dist --minify --packages external"
10+
"build": "bun build src/index.ts --outdir dist --minify --packages external",
11+
"lint": "eslint src"
1112
},
1213
"repository": {
1314
"type": "git",
@@ -35,7 +36,11 @@
3536
"LICENSE"
3637
],
3738
"devDependencies": {
38-
"@types/bun": "^1.2.1"
39+
"@eslint/js": "^9.19.0",
40+
"@types/bun": "^1.2.1",
41+
"eslint": "^9.19.0",
42+
"globals": "^15.14.0",
43+
"typescript-eslint": "^8.22.0"
3944
},
4045
"peerDependencies": {
4146
"typescript": "^5.7.3"

src/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
23

34
import { decode, encode } from "@msgpack/msgpack";
45
import { program } from "commander";
@@ -29,7 +30,7 @@ async function getFileSize(filePath: string): Promise<number> {
2930
async function compressFile(inputFile: string, outputFile: string | undefined) {
3031
try {
3132
const inputSize = await getFileSize(inputFile);
32-
consola.debug(`Compressing ${inputFile}...`);
33+
consola.debug(`Compressing ${inputFile}...`);
3334

3435
const data = await readFile(inputFile, "utf-8");
3536
const json = JSON.parse(data);
@@ -64,7 +65,7 @@ async function decompressFile(
6465
) {
6566
try {
6667
const inputSize = await getFileSize(inputFile);
67-
consola.debug(`Decompressing ${inputFile}...`);
68+
consola.debug(`Decompressing ${inputFile}...`);
6869

6970
const data = await readFile(inputFile);
7071
const decompressed = decode(data);

0 commit comments

Comments
 (0)