npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aminya/minijson

v1.1.0

Published

Minify JSON files blazing fast, removing comments/whitespace.

Downloads

313

Readme

minijson

Minify JSON files blazing fast, removing comments/whitespace.

Uses D, C, and AVX2 and SSE4_1 SIMD. 4180 times faster than jsonminify!

CI

Installation

  • Npm (Nodejs)
npm install @aminya/minijson
  • Dub (D)
git submodule update --init --recursive
dub build --config=library --build=release-nobounds --compiler=ldc2
# or
dub build --config=executable --build=release-nobounds --compiler=ldc2
  • Download Native Binaries from https://github.com/aminya/minijson/releases/latest

CLI Usage

# Minify the specified files
minijson ./dist/**/*.json ./build/a.json

# Minify the specified files (supports comments)
minijson --comment file1_with_comment.json file2_with_comment.json

# Minify the specified json string
minijson --str '{"some_json": "string_here"}'

# Minify the specified json string (supports comments)
minijson --comment --str '{"some_json": "string_here"} //comment'
> minijson --help

Usage: minijson [--files FILES ...] [--comment] [--str STR ...] [--file FILE ...] [-h]

minijson: minify json files with support for comments

Optional arguments:
  --files FILES ...
  --comment
  --str STR ...
  --file FILE ...
  -h, --help           Show this help message and exit

Node API

import { minifyFiles, minifyString } from "minijson"

// minify the files in-place and in parallel
await minifyFiles(["file1.json", "file2.json"])

// supports comments by passing true as the second argument
await minifyFiles(["file1_with_comment.json", "file2_with_comment.json"], true)

// minify the given string
const minifiedString = minifyString(`{"some_json": "here"}`)

// supports comments by passing true as the second argument
const minifiedString2 = minifyString(`{"some_json": "here"}//comment`, true)

Note: in the Nodejs API, prefer minifyFiles over other functions, as it minifies the files in parallel with the least amount of resources.

D API

import minijson: minifyString, minifyFiles;

// minify the given string
const minifiedString = minifyString(`{"some_json": "here"}`);

// supports comments by passing true as the second argument
const minifiedString2 = minifyString(`{"some_json": "here"}//comment`, true);

// minify the files in-place and in parallel
minifyFiles(["file1.json", "file2.json"]);

// supports comments by passing true as the second argument
minifyFiles(["file1.json", "file2.json"], true);

Benchmarks

On AMD Ryzen 7 4800H:

  • minifyString: minijson is 4178 times faster than jsonMinify
  • minifyFiles: minijson is 1894 times faster than jsonMinify.
❯ .\dist\minijson-benchmark.exe --benchmark-minifyString --benchmark-minifyFiles
Benchmark minifyString
14 ms
Benchmark minifyFiles
31 ms

❯ node .\benchmark\js-benchmark.mjs
Benchmark minifyString
58.502 seconds
Benchmark minifyFiles
58.703 seconds

Contributing

You would need to install the ldc compiler for the D programming language

curl -fsS https://dlang.org/install.sh | bash -s ldc

After installation, it will print a message about activating it. Something like source activate_ldc.sh.

After running the activation command, clone the repository:

git clone --recurse-submodules https://github.com/aminya/minijson
cd minijson

Then build with:

pnpm install
pnpm build.node

License

The project is licensed under MIT. It was inspired by fkei/JSON.minify.