0.0.2 • Published 6 months ago
coolice v0.0.2
CoolIce
A lightweight TypeScript library for appending JSON objects to array-based JSON files.
Installation
npm install coolice
Usage
import { appendJSON } from "coolice"
// Basic usage
appendJSON("data.json", { name: "John" })
// With options
appendJSON(
"data.json",
{ name: "John" },
{
force: true, // Force create new file if JSON is invalid
space: 2, // Indentation spaces
replacer: null // Custom JSON replacer
}
)
// output: [{ "name": "John" }] --> data.json
API
appendJSON(path, data, options?)
Appends a JSON object to an array in a JSON file. If the file doesn't exist, creates a new file with the data.
Parameters
path (string) - The file path where the JSON data should be appended
data (object) - The object to append to the JSON array
options (optional) - Configuration options:
force (boolean) - Whether to force create new file if JSON is invalid
space (string|number) - Indentation spaces or characters to use
replacer (function|array) - Custom replacer function for JSON.stringify
License
MIT