Skip to content

softwarexplus/coolice

Repository files navigation

CoolIce

Discord GitHub Action NPM Version NPM Downloads NPM Unpacked Size NPM License

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published